CString UTF8ToGB2312(char *str)
{
CString result;
WCHAR *strSrc = NULL;
TCHAR *szRes = NULL;
int i; // UTF8转换成Unicode
i = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0);
strSrc = new WCHAR[i+1];
MultiByteToWideChar(CP_UTF8, 0, str, -1, strSrc, i); // Unicode转换成GB2312
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);
result = szRes;
if (strSrc != NULL)
{
delete []strSrc; strSrc = NULL;
}
if (szRes != NULL)
{
delete []szRes;
szRes = NULL;
}
return result;
}
mfc UTF8 To GB2312
最新推荐文章于 2021-07-13 10:18:13 发布