会员
周边
捐助
新闻
博问
闪存
赞助商
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
懒码农。。。。。。
博客园
::
首页
::
博问
::
闪存
::
新随笔
::
联系
::
订阅
::
管理
::
公告
WCHAR* CHAR* 转换
//包含头文件
#include <AFXCONV.H>
CString strUnicode(_T( "unicode string "));
USES_CONVERSION;
char* pszChar = W2A(strUnicode));
MultiByteToWideChar
WideCharToMultiByte
void
ConvertUtf8ToGBK(CString
&
strUtf8)
{
int
len
=
MultiByteToWideChar(CP_UTF8,
0
, (LPCTSTR)strUtf8,
-
1
, NULL,
0
);
unsigned
short
*
wszGBK
=
new
unsigned
short
[len
+
1
];
memset(wszGBK,
0
, len
*
2
+
2
);
MultiByteToWideChar(CP_UTF8,
0
, (LPCTSTR)strUtf8,
-
1
, wszGBK, len);
len
=
WideCharToMultiByte(CP_ACP,
0
, wszGBK,
-
1
, NULL,
0
, NULL, NULL);
char
*
szGBK
=
new
char
[len
+
1
];
memset(szGBK,
0
, len
+
1
);
WideCharToMultiByte (CP_ACP,
0
, wszGBK,
-
1
, szGBK, len, NULL,NULL);
strUtf8
=
szGBK;
delete[] szGBK;
delete[] wszGBK;
}
void
ConvertGBKToUtf8(CString
&
strGBK)
{
int
len
=
MultiByteToWideChar(CP_ACP,
0
, (LPCTSTR)strGBK,
-
1
, NULL,
0
);
unsigned
short
*
wszUtf8
=
new
unsigned
short
[len
+
1
];
memset(wszUtf8,
0
, len
*
2
+
2
);
MultiByteToWideChar(CP_ACP,
0
, (LPCTSTR)strGBK,
-
1
, wszUtf8, len);
len
=
WideCharToMultiByte(CP_UTF8,
0
, wszUtf8,
-
1
, NULL,
0
, NULL, NULL);
char
*
szUtf8
=
new
char
[len
+
1
];
memset(szUtf8,
0
, len
+
1
);
WideCharToMultiByte (CP_UTF8,
0
, wszUtf8,
-
1
, szUtf8, len, NULL,NULL);
strGBK
=
szUtf8;
delete[] szUtf8;
delete[] wszUtf8;
}
posted on
2011-09-30 22:13
阿彬
阅读(
918
) 评论(
0
)
编辑
收藏
举报
刷新页面
返回顶部