// Unicode 将std::string字符串转换为CString字符串
string CMyApp::TranslateCStringTostringByUnicode(IN CString& strSource)
{
// 字符串strSource太长W2A会崩溃!
/*
USES_CONVERSION;
std::string strResult(W2A(strSource));
*/
int nSourceLen = strSource.GetLength();
int nSourceBytes = WideCharToMultiByte(CP_ACP, 0, strSource, nSourceLen, NULL, 0, NULL, NULL);
char* chrTemp = new char[nSourceBytes + 1];
memset(chrTemp, 0, nSourceBytes + 1);
WideCharToMultiByte(CP_OEMCP, 0, strSource, nSourceLen, chrTemp, nSourceBytes, NULL, NULL);
chrTemp[nSourceBytes] = 0;
std::string strResult = chrTemp;
delete[] chrTemp;
return strResult;
}
// Unicode 将CString字符串转换为std::string字符串。
CString CMyApp::TranslatestringToCStringByUnicode(IN const string& strSource)
{
CString strResult = _T("");
strResult = strSource.c_str();
return strResult;
}