CString ConverToUTF8(CString szText)
{
WCHAR *chBuf;
char * p;
int iLen;
iLen = MultiByteToWideChar(CP_ACP, 0, szText,-1 , NULL, 0);
chBuf = new WCHAR[iLen+1];
ZeroMemory(chBuf, iLen * sizeof(WCHAR));
iLen =MultiByteToWideChar(CP_ACP, 0, szText, -1, chBuf, iLen+1);
iLen = WideCharToMultiByte(CP_UTF8, 0, chBuf,-1 , NULL, 0,NULL,NULL);
p = new CHAR[iLen+1];
ZeroMemory(p, iLen * sizeof(CHAR));
iLen =WideCharToMultiByte(CP_UTF8, 0, chBuf, -1, p, iLen+1,NULL,NULL);
delete []chBuf;
CString re(p);
return re;
}
CString UTF8ToUnicode(CString szText)
{
int len = 0;
len = szText.GetLength();
int unicodeLen = ::MultiByteToWideChar( CP_UTF8,0,szText.GetBuffer(len),-1,NULL,0 );
wchar_t * pUnicode;
pUnicode = new wchar_t[unicodeLen+1];
memset(pUnicode,0,(unicodeLen+1)*sizeof(wchar_t));
::MultiByteToWideChar( CP_UTF8,0,szText.GetBuffer(len),-1,(LPWSTR)pUnicode,unicodeLen );
CString rt = pUnicode;
delete pUnicode;
return rt;
}
posted on 2011-02-21 14:48
CrackRen 阅读(234)
评论(0) 编辑 收藏 所属分类:
VC 、
实用算法