Unicode to ASCII in C# - 04-23-2010 , 06:53 AM
Hi i am calling a function in Native c++ .dll from .NetCF 3.5 app
the function takes char * as one of the args.
int SendResponse(int Bus, char *response_msg, int msg_size)
public static extern int SendResponse(int Bus,
// call to the native code
ResponseSb = new StringBuilder(ResponseString);
// Send the response message through the library interface.
status = cNiDeviceWrapper.SendResponse(cDevice.ActiveBus,
i am getting a pointer to Unicode chars as an argument in the c++ code
rather than a pointer to bytes.
how do i solve this so that i get a pointer to bytes as in C++ code.
RE: Unicode to ASCII in C# - 04-23-2010 , 12:51 PM
What I have typically done for this is to use something like this:
string s = "this is a test";
byte b = UnicodeEncoding.Unicode.GetBytes(s);
and declare the parameter as a byte array, not a string.
You can also use something like this for marshalling:
public static extern int MyTestC([MarshalAs(UnmanagedType.LPStr)]
Note that in neither case is StringBuilder normally used.
|Thread Tools||Search this Thread|