码迷,mamicode.com
首页 > 其他好文 > 详细

CStringUtf8ToUnicode

时间:2014-08-26 00:11:45      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:ar   art   new   size   c   har   return   string   r   

CString CStringUtf8ToUnicode( CString Utf8 )
{
	int wLen = 0;
	CString strUnicode;
	LPSTR pBufChar = NULL;
	LPWSTR pBufWchar  = NULL;
	
	//CString to char
	wLen = WideCharToMultiByte(CP_ACP, 0, Utf8, -1, NULL, 0, NULL, NULL);
	pBufChar = new char[wLen + 1];
	memset( pBufChar , 0, wLen + 1 );
	WideCharToMultiByte(CP_ACP, 0, Utf8, -1, pBufChar, wLen, NULL, NULL);
	
	//char to Unicode
	wLen = MultiByteToWideChar(CP_UTF8, 0, pBufChar, -1, NULL, NULL);
	pBufWchar = new wchar_t[wLen];
	memset(pBufWchar, 0, wLen * sizeof(wchar_t));
	MultiByteToWideChar(CP_UTF8, 0, pBufChar, -1, pBufWchar, wLen);

	strUnicode = CString(pBufWchar);
	if( pBufChar ) delete pBufChar;
	if( pBufWchar ) delete pBufWchar;

	return strUnicode;
}

CStringUtf8ToUnicode

标签:ar   art   new   size   c   har   return   string   r   

原文地址:http://www.cnblogs.com/nlsoft/p/3936031.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!