![](/img/trans.png)
[英]Converting Japanese characters from wide characacter to multibyte using API WideChartoMultibyte gives '????'
[英]Converting a string of multibyte characters to widechar's gives unexpected results
我正在尝试使用WinInet库读取UTF-8编码的网页。
这是我的一些代码:
HINTERNET hUrl = ::InternetOpenUrl(hInet, wurl.c_str(),NULL,NULL,NULL,NULL);
CHAR buffer[65536];
std::wstring full_content;
std::wstring read_content;
DWORD number_of_bytes_read=1;
while(number_of_bytes_read)
{
::InternetReadFile(hUrl, buffer, 65536, &number_of_bytes_read);
// ::InternetReadFileExW(hUrl, &buffersw, IRF_SYNC,NULL);
//((hUrl,buffer,65536,&number_of_bytes_read);
read_content.resize(number_of_bytes_read);
::MultiByteToWideChar(CP_ACP,MB_COMPOSITE,
&buffer[0],number_of_bytes_read,
&read_content[0],number_of_bytes_read);
full_content.append(read_content);
//readed_content.append(buffer,number_of_bytes_read);
}
我正确看到了英文符号,但看到的是垃圾符号,而不是俄语符号。 会是什么
提前致谢。
您的网页是UTF-8,但您仍使用ANSI代码页(CP_ACP)对其进行了解码。 改用CP_UTF8
将CP_ACP更改为CP_UTF8,将MB_COMPOSITE更改为0
来自文档
对于UTF-8或代码页54936(GB18030,从Windows Vista开始),必须将dwFlags设置为0或MB_ERR_INVALID_CHARS。 否则,该函数将失败并显示ERROR_INVALID_FLAGS。
完全不要转换。 将其保存在内存中为UTF-8。 仅在与Windows API函数交互时才转换为UTF-16。
有关此方法的更多信息,请参见http://utf8everywhere.org 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.