|
There's no way to do that. The message to shutdown goes out to all applications at once, but there is no way to tell, let alone guarantee, appB will wait for your appA to shutdown before it does.
|
|
|
|
|
You might find a solution in SystemEvents.SessionEnding. I haven't played with it, but it seems like that might work, at least for knowing that log off/shutdown is happening.
It was my understanding that Windows shuts apps down in no guaranteed order, though I'm sure someone will chime in if there is a guaranteed order. It might be as the other reply stated, but I wouldn't necessarily rely upon that.
I'd be interested in what you find out.
Good Luck!
It isn't enough to do well in life.
One must do good when and where one can.
Otherwise, what's the point?
|
|
|
|
|
I need to make this DLL work Hopefully someone can help me.
The errors i'm getting are:
"Cannot find Entry Point.. "(unless I explicitly define the entry point as being #1)
If I explicitly define the entry point, I get the error:
"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
Could it be because the function I'm calling calls other functions? If so, how do I fix that?
C++ DLL header..
<code>
extern "C" _declspec(dllexport) BOOL FindUser2(char *cpUserFile,
char *cpPassword,
char *cpUserName,
char *cpUserPriveledge,
char *cpUserID,
char *cpComments,
BOOL *bUserActive,
char *cpErrorReason);
</code>
C++ DLL implementation..
(BOOL is an int)
<code>
extern "C" BOOL FindUser2(char *cpUserFile,
char *cpPassword,
char *cpUserName,
char *cpUserPriveledge,
char *cpUserID,
char *cpComments,
BOOL *bUserActive,
char *cpErrorReason)
{
...
return TRUE;
}
</code>
C# definition
<code>
...
using System.Runtime.InteropServices;
namespace Material_OIT
{
public static class Authorize
{
[DllImport("WN_USER_SECURITY.dll", EntryPoint="#1")]
static public unsafe extern int FindUser2(ref char[] UserFile,
ref char[] Password,
out char[] UserName,
out char[] UserPrivilege,
out char[] userID,
out char[] Comments,
out int UserActive,
out char[] ErrorReason);
}
}
</code>
C# function call..
<code>
char[] UserFile = new char[256];
char[] Password = new char[256];
char[] UserName = new char[256];
char[] UserPriv = new char[256];
char[] UserID = new char[256];
char[] Comments = new char[256];
int UserActive = 0;
char[] ErrorReason = new char[256];
String userFile = @"C:\BSAH_WN\MATERIAL\CELL\FILES\CONFIG\USER_LIST.INF";
userFile.CopyTo(0, UserFile, 0, 51);
string password = "410572537";
password.CopyTo(0, Password, 0, 9);
Authorize.FindUser2(ref UserFile, ref Password, out UserName, out UserPriv, out UserID, out Comments, out UserActive,out ErrorReason);
</code>
-- modified at 13:46 Friday 21st September, 2007
|
|
|
|
|
What does the .dll's definition file, usually a .def file, say about the function?
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
; WN_USER_SECURITY.def : Declares the module parameters for the DLL.
LIBRARY "WN_USER_SECURITY"
DESCRIPTION 'WN_USER_SECURITY Windows Dynamic Link Library'
EXPORTS
FindUser2 @1
|
|
|
|
|
Dio22 wrote: "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
I've run into this before and had to really play around with marshalling it. If I can find the code, I'll let you know how it was done.
"Try asking what you want to know, rather than asking a question whose answer you know." - Christian Graus
|
|
|
|
|
|
...if calling Dispose() results in an implicit call to Close(), why do people say that you shouldn't rely on Dispose to Close your connections? Take this code for example:
try
{
if (table != null)
{
using (OleDbConnection connection = new OleDbConnection())
{
connection.Open();
using (OleDbCommand command = connection.CreateCommand())
{
command.CommandText = "SELECT obj From " + table.Alias;
using (OleDbDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
container.Add(new Feature((xx)reader.Getxx(0)));
}
}
}
}
}
}
catch (Exception)
{
MessageBox.Show("There was a GPS Error");
}
What would have priority over a thrown exception such that it HAD to process before a catch was allowed to handle the Exception? Anything? Dispose?
-- modified at 10:54 Friday 21st September, 2007
|
|
|
|
|
It unwinds the stack. The stack is a standard mechanism in computing since the very early days.
So, in other words, it MUST tidy up everything created after the try before it can process the catch.
So the using statements will call Dispose before it gets to the catch block.
|
|
|
|
|
That's exactly what I thought. I was just trying to leave it as open a question as possible to promote other people to share their thoughts.
|
|
|
|
|
ForkOffandDie wrote: if calling Dispose() results in an implicit call to Close()
This can not be a blanket statement as it isn't always true. In this particular case, the Dispose method on OleDbConnection does actually call Close . There are other instances where this does not occur so you need to read the documentation carefuly or use a tool like Reflector to verify what the code actually does.
Keep in mind that your code is actually changed by the compiler so the using statements are replaced by try/finally blocks. It ends up looking similar to this:
try
{
if (table != null)
{
OleDbConnection connection;
try
{
connection = new OleDbConnection();
connection.Open();
OleDbCommand command;
try
{
command = connection.CreateCommand();
command.CommandText = "SELECT obj From " + table.Alias;
OleDbDataReader reader;
try
{
reader = command.ExecuteReader();
while (reader.Read())
{
container.Add(new Feature((xx)reader.Getxx(0)));
}
}
finally
{
if (reader != null)
{
((IDisposable)reader).Dispose();
}
}
}
finally
{
if (command != null)
{
((IDisposable)command).Dispose();
}
}
}
finally
{
if (connection != null)
{
((IDisposable)connection).Dispose();
}
}
}
}
catch (Exception)
{
MessageBox.Show("There was a GPS Error");
} When an exception occurs, the runtime begins a two-step process:
- The runtime searches the array for the first protected block that:
- Protects a region that includes the currently executing instruction, and
- Contains an exception handler or contains a filter that handles the exception.
- If a match occurs, the runtime creates an Exception object that describes the exception. The runtime then executes all finally or fault statements between the statement where the exception occurred and the statement handling the exception. Note that the order of exception handlers is important: the innermost exception handler is evaluated first. Also note that exception handlers can access the local variables and local memory of the routine that catches the exception, but any intermediate values at the time the exception is thrown are lost.
If no match occurs in the current method, the runtime searches each caller of the current method, and it continues this path all the way up the stack. If no caller has a match, the runtime allows the debugger to access the exception. If the debugger does not attach to the exception, the runtime raises the UnhandledException event. If there are no listeners for the UnhandledException event, the runtime dumps a stack trace and ends the program. (Exceptions Overview (MSDN)[^]
So, effectively what this says is that when an exception occurs, the runtime walks the stack backwards looking for a catch block that can handle that exception until it finds one or reaches to top of the stack and raises an UnhandledException. If it does find one, it then runs any finally blocks it found leading up to the catch block and then runs the catch block.
Sorry for the long-winded answer, but if I understand you correctly, it would seem that your line of reasoning is correct. The finally blocks would run, which would close the objects and then run the catch handler and display the message box.
ForkOffandDie wrote: What would have priority over a thrown exception such that it HAD to process before a catch was allowed to handle the Exception?
I'm not sure this really makes sense. Processing the catch block is handling the exception. The finally blocks really don't have anything to do with what exception was thrown as they will execute no matter what, even if no exceptions were thrown. The Framework does have a concept of Filtered exception handlers, but that isn't supported by C# (only VB and IL, as far as I know).
|
|
|
|
|
Pete O`Hanlon wrote: ms.Position = 0;
@ Pete : With your solution, it has an exception :
File format is not valid.

|
|
|
|
|
Hi guys,
please help!!! I am trying to delete the printtoprinter job that has already been sent to the printer and then reseting the printer. Is this possible? Is it possible to cancel printtoprinter and to capture a confirmation on whether the report was printed?
Please please please help!!!
Sameer
|
|
|
|
|
Perhaps you could use this[^] article as a starting point for your solution?
/ravi
|
|
|
|
|
Thank you Ravi, I really would hate to change my logic from a simple printtoprinter to a dll based process.
Sameer
|
|
|
|
|
hi
i have created this method to display graph on a form and is display but the problem that i have is that i want to save this method as an xml file but i can't get it right.under this method there is code that i am trying to use to save this method as an xml file.
private void DisplayTools()
{
Graph g = Graph("graph");
g.AddNode("Circle");
g.AddNode("Box");
g.AddNode("Ellipse");
g.AddNode("Diamond");
Edge e1 = (Edge)g.AddEdge("Circle", "Box");
Edge e2 = (Edge)g.AddEdge("Box", "Ellipse");
Edge e3 = (Edge)g.AddEdge("Ellipse", "Diamond");
Edge e4 = (Edge)g.AddEdge("Diamond", "Circle");
Node n1 = (Node)g.FindNode("Circle");
n1.Attr.Color = Microsoft.Glee.Drawing.Color.Black;
n1.Attr.Shape = Shape.Circle;
Node n2 = (Node)g.FindNode("Box");
n2.Attr.Color = Microsoft.Glee.Drawing.Color.Black;
n2.Attr.Shape = Shape.Box;
Node n3 = (Node)g.FindNode("Diamond");
n3.Attr.Color = Microsoft.Glee.Drawing.Color.Black;
n3.Attr.Shape = Shape.Diamond;
gViewer1.Graph = g;
here is code that i am trying to use to save as an xml file
FileStream fs = new FileStream("methods.xml", FileMode.Create);
XmlTextWriter w = new XmlTextWriter(fs,Encoding.UTF8);
w.WriteStartDocument();
w.WriteStartElement("methods");
DisplayTools();
w.WriteEndElement();
w.WriteEndDocument();
w.Flush();
fs.Close();
Mamphekgo
|
|
|
|
|
You need to decorate Graph and its contained classes with XML serialization attributes. See this[^] tutorial.
/ravi
|
|
|
|
|
I want to store a Word file into a database (into a field has Image type), and get the Word file from the database to show in RichTextbox. But, when i get a byte array (named content) from database and use :
MemoryStream ms = new MemoryStream(content);<br />
<br />
<br />
richTextBox1.LoadFile(ms, RichTextBoxStreamType.RichText);<br />
to show it in RichTextbox, it throws an exception :
"Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection."<br />
Can you help me ?
|
|
|
|
|
Hi,
AFAIK an RTB is capable of showing an RTF file, which you can generate with either an RTB or
with Wordpad. An MS Word document (.doc) can not be loaded into an RTB.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Luc Pattyn wrote: Hi,
AFAIK an RTB is capable of showing an RTF file, which you can generate with either an RTB or
with Wordpad. An MS Word document (.doc) can not be loaded into an RTB.
Uhm, what i can use to show MS Word document in my application ?
|
|
|
|
|
Hi,
if MS Word is present and .doc extension is associated with it, then a WebBrowser control
should be able to show it.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
ms.Position = 0;
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Hello...
I have a problem in treeview. If the treeview is focused, then I can see that the selection has a backcolor blue. But if focus changed to other control, I cannot see the selection anymore, backcolor is now white, just like another nodes.
How to keep this color blue if treeview is not focused ?
Thanks...
|
|
|
|
|
Set the treeview's HideSelection property to false. This will give it a grey background when not focused.
|
|
|
|
|
Hi,
I'm trying to add all JPG-Files from a directory to a list box with the help of following code:
const String pathFileSystem = @"\\server\c$\directory\JPG-TEST";
public void loadImagesFromFs()
{
try
{
DirectoryInfo di = new DirectoryInfo(pathFileSystem);
FileInfo[] rgFiles = di.GetFiles("*.jpg");
foreach (FileInfo fi in rgFiles)
{
this.fileList.Items.Add(fi.Name);
}
}
catch (Exception)
{
MessageBox.Show("Couldn't find directory.", "Error");
}
}
The " DirectoryInfo di = new DirectoryInfo(pathFileSystem);" allways throws me an SecurityException. It has something to do with the path. When I use System.IO.Directory.GetCurrentDirectory(); instead of the "pathFileSystem it works. But the path in the const is correct, it works on windows. And with "@" it should be correclty escaped, or not?
When I debug with "GetCurrentDirectory" the path is always with out "\\" (no escaping) but when I use the "correct version, it always has a string like "\\\\server\\directory...", which could be correct, because it escapes the "\" but I'm not sure if it isn't the problem, as it is the difference I notice in this two versions.
Any ideas?
Thx, Shi
|
|
|
|
|