2012-08-07 69 views
0

我想知道如何将C#字符串编组为一个本地C++ char *。我正在尝试它,但似乎没有任何工作。提前致谢。Marshall c#string to C++

+0

可能重复的[char *指针从C#中的字符串](http://stackoverflow.com/questions/1658269/char-pointer-from-string-in-c-sharp) – 2012-08-07 11:40:01

回答

0

请记住,C++的char实际上是一个字节,所以你需要它也Pass C# string to C++ and pass C++ result (string, char*.. whatever) to C#作为传递使用的东西一个byte []像

string str; // Contains string to pass to C++ DLL 
byte[] bytes = Encoding.UTF8.GetBytes(str); 
MyFun(bytes); // Call the C++ function with the string 

见了不同的观点。

+1

你通常不需要做 - 你通常应该能够声明该函数为一个System.String参数。 – 2012-09-20 09:56:17