G
Guest
have an unmanaged C++ DLL with following method:
the DLL interface for unmanaged C++ is:
SendCommand(void *h, char *c, char *d, char *b);
the declaration in C# is:
[DllImport("test.dll", CharSet = CharSet.Ansi, EntryPoint = "SendCommand")]
unsafe public static extern char* SendCommand(void* h,
[MarshalAs(UnmanagedType.LPStr)] string cmd, [MarshalAs(UnmanagedType.LPStr)]
string data, [MarshalAs(UnmanagedType.LPArray)] ref byte[] buffer);
when i call the function
byte buf = new byte[25];
SendCommand(r, "test string", "", buf);
The problem is that buf should have a value in it when the call is
completed. However buf is empty. I have another function which only accepts a
byte array as the input and it is a char * on the c++ side and that returns
valid values in the byte array. So I am guessing the problem could be with
the passing of the strings as the SendCommand method will return correct
values when it understands the strings correctly. The SendCommand method
works correctly if I make the call using C++ code but does not work correctly
from C#. Could be LPSTR not be working correctly as it is supposed to?
THANKS
the DLL interface for unmanaged C++ is:
SendCommand(void *h, char *c, char *d, char *b);
the declaration in C# is:
[DllImport("test.dll", CharSet = CharSet.Ansi, EntryPoint = "SendCommand")]
unsafe public static extern char* SendCommand(void* h,
[MarshalAs(UnmanagedType.LPStr)] string cmd, [MarshalAs(UnmanagedType.LPStr)]
string data, [MarshalAs(UnmanagedType.LPArray)] ref byte[] buffer);
when i call the function
byte buf = new byte[25];
SendCommand(r, "test string", "", buf);
The problem is that buf should have a value in it when the call is
completed. However buf is empty. I have another function which only accepts a
byte array as the input and it is a char * on the c++ side and that returns
valid values in the byte array. So I am guessing the problem could be with
the passing of the strings as the SendCommand method will return correct
values when it understands the strings correctly. The SendCommand method
works correctly if I make the call using C++ code but does not work correctly
from C#. Could be LPSTR not be working correctly as it is supposed to?
THANKS