如果有中文的话,在 C# 端使用 CharSet = CharSet.Unicode
C#端:
[DllImport("capturePicture.dll",CharSet = CharSet.Unicode, EntryPoint = "ReceiveStrArr")]
public extern static int SendStrArr(string[] sendS, int arraySize);
C++端:
extern "C" _declspec(dllexport) int _stdcall ReceiveStrArr(wchar_t** receiveS, int arraySize)
{
vector<wstring> receiveStrs;
for (int i = 0; i < arraySize; i++)
{
wstring wstr = *(receiveS + i);
receiveStrs.push_back(wstr);
}
return 0;
}
如果传递的字符串中没有中文的话,可以使用 CharSet = CharSet.Ansi,在C++端使用 char** 接收
参考:https://zhidao.baidu.com/question/493957475787947812.html