提供一个宽字节与多字节之间进行转换的库,主要用于宽字节编码的MFC应用程序。
修正:
20160803 发现宽字节与多字节转换时分配内存异常,会导致后期无法对指针进行删除以及指针指向的内存进行释放;
==============================================================
目前提供的转换函数为:
- //Unicode(UTF16)ToUTF-8
- char* UnicodeToUTF8(wchar_t* pUnicode);
复制代码- //UTF-8ToUnicode(UTF-16)
- wchar_t* UTF8ToUnicode(char* pUtf8);
复制代码- //Unicode(UTF-16)ToMBCS
- char* UnicodeToMBCS(wchar_t* pUnicode);
复制代码- //MBCSToUnicode(UTF-16)
- wchar_t* MBCSToUnicode(char* pChar);
复制代码 ================================================================
调用方法:
1.将库放到工程根目录并进行根目录指定;
2.在调用的位置或者stdafx.h里面添加调用;
- //调用编码转换库
- #include "EnDeCodeAPI.h"
- #ifdef _DEBUG
- #pragma comment(lib,"EnDeCode_D.lib")
- #else
- #pragma comment(lib,"EnDeCode_R.lib")
- #endif
复制代码 相关案例
- //Unicode与UTF-8互转
- CString strTemp=_T("It's 中国人");
- char* chVal;
- chVal=UnicodeToUTF8(strTemp.GetBuffer());
- wchar_t *wchStr=NULL;
- wchStr=UTF8ToUnicode(chVal);
-
- CString str;
- str=(CString)wchStr;
- AfxMessageBox(str);
复制代码
- //宽字节与多字节相互转换
- CString strTemp=_T("It's 中国人");
- char* chVal;
- chVal=UnicodeToMBCS(strTemp.GetBuffer());
- wchar_t *wchStr=NULL;
- wchStr=MBCSToUnicode(chVal);
- CString str;
- str=(CString)wchStr;
-
- AfxMessageBox(str);</p>
复制代码
下载地址:
如果缺少msvcr100d.dll文件,请在vs2010目录下查找!
|