我正在尝试将字符串从 c++ 传递给 c#。
C++:
extern "C" __declspec(dllexport) void GetSurfaceName(wchar_t* o_name);
void GetSurfaceName(wchar_t* o_name)
{
swprintf(o_name, 20, L"Surface name");
}
C#:
[DllImport("SurfaceReader.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern void GetSurfaceName(StringBuilder o_name);
StringBuilder name = new StringBuilder(20);
GetSurfaceName(name);
但只传递了第一个符号:name[0] == 'S'。其他符号为空。你能告诉我这里有什么问题吗?
谢谢,振亚