多字节与宽字节相互转换的方法
来源:互联网 发布:恺英网络阿拉德之怒 编辑:程序博客网 时间:2024/05/23 11:58
也就是WideCharToMultiByte和MultiByteToWideChar函数的使用方法。
多字节向宽字节转换:
wstring converToWideChar( const string& str )
{
int len = 0;
len = str.length();
int unicodeLen = ::MultiByteToWideChar(CP_UTF8,0,str.c_str(),-1,NULL,0);
wchar_t * pUnicode;
pUnicode = new wchar_t[unicodeLen+1];
memset(pUnicode,0,(unicodeLen+1)*sizeof(wchar_t));
::MultiByteToWideChar(CP_UTF8,0,str.c_str(),-1,(LPWSTR)pUnicode,unicodeLen);
wstring rt;
rt = ( wchar_t* )pUnicode;
delete pUnicode;
return rt;
}
宽字节向多字节转换:
string converToMultiChar( const wstring& str )
{
char* pElementText;
int iTextLen;
// wide char to multi char
iTextLen = WideCharToMultiByte( CP_ACP,
0,
str.c_str(),
-1,
NULL,
0,
NULL,
NULL );
pElementText = new char[iTextLen + 1];
memset( ( void* )pElementText, 0, sizeof( char ) * ( iTextLen + 1 ) );
::WideCharToMultiByte( CP_ACP,
0,
str.c_str(),
-1,
pElementText,
iTextLen,
NULL,
NULL );
string strText;
strText = pElementText;
delete[] pElementText;
return strText;
}
- 多字节与宽字节相互转换的方法
- 多字节与宽字节相互转换的方法
- 多字节与宽字节字符串的相互转换
- 多字节与宽字节字符串 的相互转换
- mfc宽字节widechar与多字节multiChar相互转换
- mfc宽字节widechar与多字节multiChar相互转换
- C++多字节字符与宽字节字符相互转换
- VC 宽字节和多字节的相互转换
- VC 宽字节和多字节的相互转换
- VC下多字节与宽字节之间的相互转换
- 多字节字符串与宽字节字符串的相互转化
- 多字节与宽字符相互转换
- 多字节和宽字节互相转换的方便方法
- Visual Studio中宽字节和多字节相互转换
- Windows 的多字节与宽字节的转换
- C++多字节与宽字节 转换
- 宽字节与多字节转换函数
- 字符串:多字节与宽字节转换
- (转)谈基于.net平台windows开发中的模式窗体
- 使用拖放的简单方法
- 有关属性对话框(property sheet )的几个提示
- Char[] 引起的 unsigned shot* 转 char* 的错误
- Microsoft .NET Pet Shop 4:将 ASP.NET 1.1 应用程序迁移到 2.0
- 多字节与宽字节相互转换的方法
- C++中类成员函数指针的继承
- CString 与 CComVariant 转换
- Bridges of Friendship
- 给GridView添加行单击事件
- 管理对象生存期
- Dreamweaver的正则表达式查找替换功能(转)
- CnPack 开发组以及产品介绍
- 在Eclipse的Web项目中java里面使用ant进行数字签名步骤详解