本人在从文本文件中读取信息时由于是UNICODE环境,把文字读入CString中结果,所有双字节字
均以单字节的形式存在。显示出来就是乱码。
查找多方未见好的方法,于是自己写了一个函数做这个转换工作,经测试OK!
CString GetUNCODEStringFromANSIString(CString strAnsi)
{
char szValue[1024];
int nIndex;
for(nIndex =0;nIndex<strAnsi.GetLength();nIndex++)
szValue[nIndex] = strAnsi.GetAt(nIndex);
szValue[nIndex] = 0;
CString strValue;
int nLength = strAnsi.GetLength();
int nWide = MultiByteToWideChar( CP_ACP, 0, szValue, nLength, NULL, 0 );
LPWSTR pszOutput = strValue.GetBuffer( nWide + 1 );
MultiByteToWideChar( CP_ACP, 0, szValue, nLength, pszOutput, nWide );
pszOutput[ nWide ] = 0;
strValue.ReleaseBuffer();
return strValue;
}