MFC中char与wchar的相互转换方法
2015-06-19 21:36
357 查看
//将 单字节char* 转换为 宽字节 wchar*
inline wchar_t* AnsiToUnicode( const char* szStr )
{
int nLen = MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, szStr, -1, NULL, 0 );
if (nLen == 0)
{
return NULL;
}
wchar_t* pResult = new wchar_t[nLen];
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, szStr, -1, pResult, nLen );
return pResult;
}
//----------------------------------------------------------------------------------
// 将 宽字节wchar_t* 转换 单字节char*
inline char* UnicodeToAnsi( const wchar_t* szStr )
{
int nLen = WideCharToMultiByte( CP_ACP, 0, szStr, -1, NULL, 0, NULL, NULL );
if (nLen == 0)
{
return NULL;
}
char* pResult = new char[nLen];
WideCharToMultiByte( CP_ACP, 0, szStr, -1, pResult, nLen, NULL, NULL );
return pResult;
}
inline wchar_t* AnsiToUnicode( const char* szStr )
{
int nLen = MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, szStr, -1, NULL, 0 );
if (nLen == 0)
{
return NULL;
}
wchar_t* pResult = new wchar_t[nLen];
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, szStr, -1, pResult, nLen );
return pResult;
}
//----------------------------------------------------------------------------------
// 将 宽字节wchar_t* 转换 单字节char*
inline char* UnicodeToAnsi( const wchar_t* szStr )
{
int nLen = WideCharToMultiByte( CP_ACP, 0, szStr, -1, NULL, 0, NULL, NULL );
if (nLen == 0)
{
return NULL;
}
char* pResult = new char[nLen];
WideCharToMultiByte( CP_ACP, 0, szStr, -1, pResult, nLen, NULL, NULL );
return pResult;
}
相关文章推荐
- MFC中char与wchar的相互转换方法
- 深入JVM系列(一)之内存模型与内存分配
- c++抽象类
- 3.1柱状图
- sgu 211
- 设置socket接收和发送超时的一种方式
- sgu 211 分类: sgu 2015-06-19 21:36 33人阅读 评论(0) 收藏
- 接触Matlab10年后的一个总结,随时使用Matlab要掌握的一些要点
- C++标准库学习笔记-5-(Container)
- 随笔
- poj2392解题报告
- HDU 3998 Sequence (最长递增子序列+最大流SAP,拆点法)经典
- chrome主页被篡改为360该溶液的导航
- [nowCoder] 局部最小值位置
- Android中View绘制优化之一---- 优化布局层次
- Uva1025 - A Spy in the Metro
- 测试与调试
- HDU 1237
- HDU2094
- hdu floyd 逆向理解