前言:
客户端(C++)通过gsoap(封装的一个Dll)调用Https方式的Webservice,客户端使用的是多字节,Dll使用的是Unicode,从而引发的传入参数乱码问题,导致调用接口失败
解决方案:
由于客户端调用地方太多,所以此处选择在Dll处进行转换,收到传入参数时先进行转换,再进行gsoap调用,代码如下:
LPWSTR MByteToWChar( LPCTSTR lpcszStr )
{
// Get the required size of the buffer that receives the Unicode
// string.
int nWideLen = MultiByteToWideChar( CP_UTF8, 0, ( LPCCH )lpcszStr, -1, NULL, 0 );
WCHAR *pWideBuf = new WCHAR[nWideLen + 1];
pWideBuf[nWideLen] = 0;
MultiByteToWideChar( CP_UTF8, 0, ( LPCCH )lpcszStr, -1, pWideBuf, nWideLen );
/*int nMultLen = WideCharToMultiByte(CP_ACP, 0, pWideBuf, nWideLen, NULL, 0, NULL, NULL);
pBuffer = new char[nMultLen + 1];
memset(pBuffer, 0, nMultLen + 1);
WideCharToMultiByte(CP_ACP, 0, pWideBuf, nWideLen, pBuffer, nMultLen, NULL, NULL);
delete[]pWideBuf;*/
return pWideBuf;
}