int UTF8ToGB(const char* str,char *out)
{
WCHAR *strSrc;
TCHAR *szRes;
int len;
//獲得臨時變量的大小
int i = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0);
strSrc = new WCHAR[i+1];
MultiByteToWideChar(CP_UTF8, 0, str, -1, strSrc, i);
//獲得臨時變量的大小
i = WideCharToMultiByte(CP_ACP, 0, strSrc, -1, NULL, 0, NULL, NULL);
szRes = new TCHAR[i+1];
WideCharToMultiByte(CP_ACP, 0, strSrc, -1, szRes, i, NULL, NULL);
len = (i+1)*sizeof(CHAR);
memcpy(out,szRes,len);
out[len+1] ='\0';
delete []strSrc;
delete []szRes;
return len;
}
摘自 sniper_bing的專欄