std::string UTF8ToGBK( const char *utf8Str )
{
unsigned short *wszGBK;
char *szGBK;
int len = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)utf8Str, -1, NULL, 0);
wszGBK = new unsigned short[len+1];
memset(wszGBK, 0, len * 2 + 2);
MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)utf8Str, -1, (LPWSTR)wszGBK, len);
len = WideCharToMultiByte(CP_ACP, 0, (LPWSTR)wszGBK, -1, NULL, 0, NULL, NULL);
szGBK = new char[len+1];
memset(szGBK, 0, len + 1);
WideCharToMultiByte(CP_ACP, 0, (LPWSTR)wszGBK, -1, szGBK, len, NULL, NULL);
std::string str(szGBK);
delete []szGBK;
delete []wszGBK;
return str;
}
std::string GBKToUTF8(const char* gbkStr)
{
int len=MultiByteToWideChar(CP_ACP, 0, (LPCSTR)gbkStr, -1, NULL,0);
unsigned short * wszUtf8 = new unsigned short[len+1];
memset(wszUtf8, 0, len * 2 + 2);
MultiByteToWideChar(CP_ACP, 0, (LPCSTR)gbkStr, -1, (LPWSTR)wszUtf8, len);
len = WideCharToMultiByte(CP_UTF8, 0, (LPWSTR)wszUtf8, -1, NULL, 0, NULL, NULL);
char *szUtf8=new char[len + 1];
memset(szUtf8, 0, len + 1);
WideCharToMultiByte (CP_UTF8, 0, (LPWSTR)wszUtf8, -1, szUtf8, len, NULL,NULL);
std::string str(szUtf8);
delete[] szUtf8;
delete[] wszUtf8;
return str;
}