WideCharToMultiByte:这是把UTF8转成Unicode了(宽字节转成多字节)。当然错了。
解决方案 »
- 如何使我新建的窗口设置成向导创建的具有换肤能力的框架窗口的颜色模式
- VC 读写txt的问题。
- 如何实现如下图形的镜像
- 对话框上有一个Static TEXT控件,如何在对话框在选中状态下使其反色高亮显示,而不选中时恢复普通显示?
- VC6编译成的.exe文件怎样进行反编译?
- 非技术问题的分不能用吗?现在散1000技术分。
- 请教高手-DLL里可否使用消息,事件??
- 怎样用csocket建立一个最基本的UDP程序?
- 关于几个图形函数的疑问,大家共同商讨
- 大家帮忙推荐一本VC的书 —— 一个VC初学者
- VS2010做的图片处理的小软件,导入韩文名字的图片就自动退出
- windows 程序设计 坐标映射的疑问
std::wstring utf8_to_unicode(const std::string& strdata)
{
std::wstring wstrdata;
if (strdata.size() == 0)
return L""; wstrdata.resize(strdata.size() * 2); int nretcode = MultiByteToWideChar(CP_UTF8, 0, strdata.c_str(), strdata.length(), &wstrdata[0], wstrdata.size()); if (nretcode > 0)
wstrdata.resize(nretcode); return wstrdata;
}
这才是UTF8转成Unicode
std::string UnicodeToANSI( std::wstring str ,UINT CodePage)
{
char* pElementText;
int iTextLen;
// wide char to multi char
iTextLen = WideCharToMultiByte( CodePage,
0,
str.c_str(),
-1,
NULL,
0,
NULL,
NULL ); pElementText = new char[iTextLen + 1];
memset( ( void* )pElementText, 0, sizeof( char ) * ( iTextLen + 1 ) );
::WideCharToMultiByte(CodePage,
0,
str.c_str(),
-1,
pElementText,
iTextLen,
NULL,
NULL );
std::string strText;
strText = pElementText;
delete[] pElementText;
return strText;
}
std::wstring ANSIToUnicode(std::string str ,UINT CodePage)
{
wchar_t* pElementText;
int iTextLen;
// wide char to multi char
iTextLen = ::MultiByteToWideChar( CodePage,
0,
str.c_str(),
-1,
NULL,
NULL); pElementText = new wchar_t[iTextLen + 1];
memset( ( void* )pElementText, 0, sizeof( wchar_t ) * ( iTextLen + 1 ) );
::MultiByteToWideChar( CodePage ,
0,
str.c_str(),
-1,
pElementText,
iTextLen);
std::wstring strText;
strText = pElementText;
delete[] pElementText;
return strText;
}
我的项目中使用了
不会出现乱码