std::string cStringToString(const CString& src, UINT codepage = CP_UTF8)
{
std::string dst;
if (src.IsEmpty())
{
dst.clear();
return "";
}
int length = ::WideCharToMultiByte(codepage, 0, src, src.GetLength(), NULL, 0, NULL, NULL);
dst.resize(length);
::WideCharToMultiByte(codepage, 0, src, src.GetLength(), &dst[0], (int)dst.size(), NULL, NULL);
return dst;
}
CString stringToCString(const std::string& src, UINT codepage = CP_UTF8)
{
CString dst;
if (src.empty())
{
return dst;
}
int length = ::MultiByteToWideChar(codepage, 0, src.data(), (int)src.size(), NULL, 0);
WCHAR* pBuffer = dst.GetBufferSetLength(length);
::MultiByteToWideChar(codepage, 0, src.data(), (int)src.size(), pBuffer, length);
return dst;
}
然後怎麼實現CString轉LPWSTR
LPWSTR = (LPWSTR)(LPCWSTR)CString