C++函数定义是这样的
__declspec(dllexport) LPWSTR __stdcall GetErrorString(int errCode);
我在 C# 中这样称呼它
[DllImport("DLLTest.dll")]
public static extern string GetErrorString(int errCode);
static void Main(string[] args)
{
string result = GetErrorString(5);
}
我收到 System.Runtime.InteropServices.SEHException 类型的未处理异常
我什至不确定 C++ DLL 是否可以尝试将 LPWSTR 返回到 C#...
Thanks.
您可能想尝试这样的事情:
[DllImport("DLLTest.dll", CharSet = CharSet.Unicode)]
[return: MarshalAs(UnmanagedType.LPWStr)]
public static extern string GetErrorString(int errCode);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)