G
Guest
i'm calling a C++ DLL from C#.
here's C++ interface:
char* __cdecl SendCmd(void* handle, char* cmd, char* data, char* buffer);
here's my call in C#:
[DllImport("somedll.dll", CharSet = CharSet.Auto, EntryPoint = "SendCmd")]
unsafe public static extern byte* SendCmd
(void* hReader,
[MarshalAs(UnmanagedType.LPArray)] byte[] cmd,
[MarshalAs(UnmanagedType.LPArray)] byte[] data,
[MarshalAs(UnmanagedType.LPArray)] byte[] buffer);
and the call is:
ReaderDLL.SendCommandGetData
(rdrHandle,
Encoding.ASCII.GetBytes("antenna off"),
Encoding.ASCII.GetBytes(""),
respBuffer);
the question is: when i pass the byte array to the DLL, (DLL expects
null-terminated char array) does it see a null-terminated char array?
in other words, GetBytes changes the string to byte array. how do i make
sure the byte array is null-terminated as expected by the dll?
thanks
here's C++ interface:
char* __cdecl SendCmd(void* handle, char* cmd, char* data, char* buffer);
here's my call in C#:
[DllImport("somedll.dll", CharSet = CharSet.Auto, EntryPoint = "SendCmd")]
unsafe public static extern byte* SendCmd
(void* hReader,
[MarshalAs(UnmanagedType.LPArray)] byte[] cmd,
[MarshalAs(UnmanagedType.LPArray)] byte[] data,
[MarshalAs(UnmanagedType.LPArray)] byte[] buffer);
and the call is:
ReaderDLL.SendCommandGetData
(rdrHandle,
Encoding.ASCII.GetBytes("antenna off"),
Encoding.ASCII.GetBytes(""),
respBuffer);
the question is: when i pass the byte array to the DLL, (DLL expects
null-terminated char array) does it see a null-terminated char array?
in other words, GetBytes changes the string to byte array. how do i make
sure the byte array is null-terminated as expected by the dll?
thanks