获取网页源代码的问题
利用CInternetSession 获取到了网页的源代码,
不过网页的格式是UTF-8
我用的VC是2008版本的,
这样获取到的源码是乱码,然后利用
wchar_t* charTowChar_t(char *buffer)
{
size_t clen=strlen(buffer);
size_t wlen=MultiByteToWideChar(CP_ACP,0,buffer,clen+1,NULL,0);
wchar_t *lpRetval=new wchar_t[wlen+1];
MultiByteToWideChar(CP_ACP,0,buffer,clen+1,lpRetval,wlen);
lpRetval[wlen]=L'\0';
return lpRetval;
}
这样函数将其转换为Unicode,
但是转换的只是非中文 ,中文仍然为乱码,有什么解决办法没?
谢谢~
[解决办法]
以前工程的代码
- C/C++ code
//编码转换 UTF-8 -> Unicode o WCHAR* tmp = NULL; tmp = new WCHAR[strHTML.GetLength()+1]; int n = MultiByteToWideChar(CP_UTF8,0,(LPCTSTR)strHTML,strHTML.GetLength(),tmp,strHTML.GetLength()+1); strHTML = tmp; delete tmp;