D
David Rose
I am trying to use a string as an in/out parameter from C#.
I have a win32 dll that exports a simple function:
extern "C" __declspec(dllimport) int ShowTheMessage(LPSTR str)
{
MessageBox(NULL, str, "Testing...", MB_OK);
strcpy(str, "XXXXXXXXXXXXXX");
return 42;
}
As a non ref parameter I can pass the string to the dll and the MessageBox()
pops up correctly. If I change it to ref, the MessageBox() comes up with
garbage and I get the following error message:
"An unhandled exception of type 'System.NullReferenceException' occurred in
CSDriver.exe
Additional information: Object reference not set to an instance of an
object."
How do I call this from C#? I have tried Marshaling several different ways,
but no luck.
Thanks for any help.
David Rose
I have a win32 dll that exports a simple function:
extern "C" __declspec(dllimport) int ShowTheMessage(LPSTR str)
{
MessageBox(NULL, str, "Testing...", MB_OK);
strcpy(str, "XXXXXXXXXXXXXX");
return 42;
}
As a non ref parameter I can pass the string to the dll and the MessageBox()
pops up correctly. If I change it to ref, the MessageBox() comes up with
garbage and I get the following error message:
"An unhandled exception of type 'System.NullReferenceException' occurred in
CSDriver.exe
Additional information: Object reference not set to an instance of an
object."
How do I call this from C#? I have tried Marshaling several different ways,
but no luck.
Thanks for any help.
David Rose