打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
MFC UTF

环境

适用范围:MFC。

字符集:多字节字符集。

声明

CString             UTF8AndUnicode_Convert(CString &strSource, UINT nSourceCodePage, UINT nTargetCodePage);

定义

CString UTF8AndUnicode_Convert(CString &strSource, UINT nSourceCodePage, UINT nTargetCodePage){    CString        strTarget; 	    wchar_t        *pWideBuf;    int            nWideBufLen;	    char           *pMultiBuf;    int            nMiltiBufLen;    int            nSourceLen;    nSourceLen = strSource.GetLength();     nWideBufLen = MultiByteToWideChar(nSourceCodePage, 0, strSource, -1, NULL, 0); 	    pWideBuf = new wchar_t[nWideBufLen+1];     memset(pWideBuf, 0, (nWideBufLen + 1) * sizeof(wchar_t)); 	    MultiByteToWideChar(nSourceCodePage, 0, strSource, -1, (LPWSTR)pWideBuf, nWideBufLen);    pMultiBuf = NULL;    nMiltiBufLen = WideCharToMultiByte(nTargetCodePage, 0, (LPWSTR)pWideBuf, -1, (char *)pMultiBuf, 0, NULL, NULL); 	    pMultiBuf = new char[nMiltiBufLen+1];     memset(pMultiBuf, 0, nMiltiBufLen + 1);     WideCharToMultiByte(nTargetCodePage, 0, (LPWSTR)pWideBuf, -1, (char *)pMultiBuf, nMiltiBufLen, NULL, NULL); 	    strTarget.Format(_T("%s"), pMultiBuf); 	    delete pWideBuf;     delete pMultiBuf; 	    return strTarget; }

 

调用方法

UTF-8转Unicode

m_strUnicode = UTF8AndUnicode_Convert(m_strUTF8, CP_UTF8, CP_ACP);

Unicode转UTF-8

m_strUTF8 = UTF8AndUnicode_Convert(m_strUnicode, CP_ACP, CP_UTF8);
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
C++ MFC string转Cstring为什么会乱码
第一次在VS2010下MFC采用ADO方式连接ACCESS数据库(详细过程)
WinCE程序设计的几个关键技术
MFC集成数据库访问
用MFC进行COM编程
MFC嵌入google map
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服