原理:宽字节字符串与多字节字符串之间转换无法转换的字符默认会转换成'?'。
多字节每个字符的字节数不是固定的,而宽字节的每个字符固定的,所以要转换回宽字节字符串判断那个字符是无法转换的字符。
CString FindUnknownChar(LPCTSTR lpString)
{CString str(lpString);
CStringA strA;
int iSize = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
WideCharToMultiByte(CP_ACP, 0, str, -1, strA.GetBuffer(iSize), iSize+1, NULL, NULL);
strA.ReleaseBuffer();
CString strW;
iSize = MultiByteToWideChar(CP_ACP, 0, strA, -1, NULL, 0);
MultiByteToWideChar(CP_ACP, 0, strA, -1, strW.GetBuffer(iSize), iSize);
strW.ReleaseBuffer();
CString strFind;
int i=0;
while(i!=-1)
{
i = strW.Find(_T('?'), i);
if (i != -1)
{
strFind += str.GetAt(i);
i ++;
}
}
return strFind;
}