LPSTR WideChar2MBCS( const CString& strCS )
{
const UINT wLen= strCS.GetLength()+ 1;
UINT aLen= WideCharToMultiByte(CP_ACP,0,strCS,wLen,NULL,0,NULL,NULL);
LPSTR lpa= newchar[aLen];
WideCharToMultiByte(CP_ACP,0,strCS,wLen,lpa,aLen,NULL,NULL);
return lpa;
}

std::string WideChar2StdStr(const
CString& strcs)


{
LPSTR l= WideChar2MBCS(strcs);
std::string stdStr(l);
delete [] l;
return stdStr;
}

LPOLESTR MBCS2WideChar( LPCSTR lpa )


{
size_t aLen= strlen(lpa)+
1;
int wLen
= MultiByteToWideChar(CP_ACP,0,lpa,aLen,NULL,0);
LPOLESTR lpw=
new WCHAR[wLen];
MultiByteToWideChar(CP_ACP,0,lpa,aLen,lpw,wLen);
return lpw;
}

CString MBCS2CString( LPCSTR lpa )


{
LPOLESTR lpw= MBCS2WideChar(lpa);
CString cstring(lpw);
delete [] lpw;
return cstring;
}

CString StdStr2CSting(const std::string&
stdStr )


{
return MBCS2CString(stdStr.c_str());
}
{
const UINT wLen= strCS.GetLength()+ 1;
UINT aLen= WideCharToMultiByte(CP_ACP,0,strCS,wLen,NULL,0,NULL,NULL);
LPSTR lpa= newchar[aLen];
WideCharToMultiByte(CP_ACP,0,strCS,wLen,lpa,aLen,NULL,NULL);
return lpa;
}

std::string WideChar2StdStr(const
CString& strcs)

{
LPSTR l= WideChar2MBCS(strcs);
std::string stdStr(l);
delete [] l;
return stdStr;
}
LPOLESTR MBCS2WideChar( LPCSTR lpa )

{
size_t aLen= strlen(lpa)+
1;
int wLen
= MultiByteToWideChar(CP_ACP,0,lpa,aLen,NULL,0);
LPOLESTR lpw=
new WCHAR[wLen];
MultiByteToWideChar(CP_ACP,0,lpa,aLen,lpw,wLen);
return lpw;
}
CString MBCS2CString( LPCSTR lpa )

{
LPOLESTR lpw= MBCS2WideChar(lpa);
CString cstring(lpw);
delete [] lpw;
return cstring;
}
CString StdStr2CSting(const std::string&
stdStr )

{
return MBCS2CString(stdStr.c_str());
}
本文提供了一系列用于字符编码转换的函数,包括从宽字符到多字节字符(MBCS)的转换,反之亦然,并展示了如何使用这些函数将 CString 对象转换为标准字符串或其他编码格式。
875

被折叠的 条评论
为什么被折叠?



