【发布时间】:2010-10-15 13:02:54
【问题描述】:
我想将 C# 中的字符串发送到本机 C++ DLL 中的函数。
这是我的代码: C# 方面:
[DllImport(@"Native3DHandler.dll", EntryPoint = "#22",
CharSet = CharSet.Unicode)]
private static extern void func1(byte[] path);
public void func2(string path)
{
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] arr = encoding.GetBytes(path);
func1(this.something, arr);
}
C++ 方面:
void func1(char *path)
{
//...
}
无论我发送什么,每次我在 C++ 端得到的是一个空字符串。 帮忙?
谢谢。
【问题讨论】:
-
Aldo,为了更准确的传递参数定义,可以使用 [MarshalAs(UnmanagedType.LPStr)] 等。更多信息见 MSDN
-
您如何确定字符串在 C++ 端为空?