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#...
谢谢。
最佳答案
您可能想尝试这样的事情:
[DllImport("DLLTest.dll", CharSet = CharSet.Unicode)]
[return: MarshalAs(UnmanagedType.LPWStr)]
public static extern string GetErrorString(int errCode);
关于c# - 是否可以将 LPWSTR 从 C++ DLL 返回到 C# 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9516263/