VS2008开发环境,多字符集和UNICODE字符集都可用。

WCHAR * mbcsToUnicode(const char *zStr)
{
int nByte;
WCHAR *zMbcsStr;
int codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP;
nByte = MultiByteToWideChar(codepage, , zStr, -, NULL,)*sizeof(WCHAR);
zMbcsStr = (WCHAR*)malloc( nByte*sizeof(zMbcsStr[]) );
if( zMbcsStr== )
{
return ;
}
nByte = MultiByteToWideChar(codepage, , zStr, -, zMbcsStr, nByte);
if( nByte== )
{
free(zMbcsStr);
zMbcsStr = ;
}
return zMbcsStr;
} BOOL CompareStr(CStringA S1, CStringA S2)
{
WCHAR* wa;
WCHAR* wb;
wa = mbcsToUnicode(S1.GetBuffer());
wb = mbcsToUnicode(S2.GetBuffer());
return CompareStringW(LOCALE_USER_DEFAULT, NORM_IGNORECASE, (LPCWSTR)wa, wcslen(wa), (LPCWSTR)wb, wcslen(wb)) - CSTR_EQUAL == ;
}

参考:http://blog.csdn.net/dbyoung/article/details/7716086

05-08 15:36