From: srks on 23 Apr 2010 06:53 Hi i am calling a function in Native c++ .dll from .NetCF 3.5 app the function takes char * as one of the args. code snippets: in C++ int SendResponse(int Bus, char *response_msg, int msg_size) in C# [DllImport("NIDeviceWrapper.dll")] public static extern int SendResponse(int Bus, StringBuilder response_msg, int msg_size); // call to the native code ResponseSb = new StringBuilder(ResponseString); // Send the response message through the library interface. status = cNiDeviceWrapper.SendResponse(cDevice.ActiveBus, ResponseSb, ResponseSb.Length); 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.
From: Paul G. Tobey [eMVP] paultobey _at_ earthlink _dot_ on 23 Apr 2010 12:51 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: [DllImport("mydll.dll")] public static extern int MyTestC([MarshalAs(UnmanagedType.LPStr)] string cstring); Note that in neither case is StringBuilder normally used. Paul T. "srks" wrote: > Hi i am calling a function in Native c++ .dll from .NetCF 3.5 app > > the function takes char * as one of the args. > > code snippets: > in C++ > int SendResponse(int Bus, char *response_msg, int msg_size) > > in C# > [DllImport("NIDeviceWrapper.dll")] > public static extern int SendResponse(int Bus, > StringBuilder response_msg, > int msg_size); > > // call to the native code > ResponseSb = new StringBuilder(ResponseString); > > // Send the response message through the library interface. > status = cNiDeviceWrapper.SendResponse(cDevice.ActiveBus, > ResponseSb, ResponseSb.Length); > > 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.
|
Pages: 1 Prev: NullReferenceException in bitmap constructor Next: Debug with a local Web Service |