16,466
社区成员
发帖
与我相关
我的任务
分享
int WideCharToMultiByte(
UINT CodePage, // code page
DWORD dwFlags, // performance and mapping flags
LPCWSTR lpWideCharStr, // address of wide-character string
int cchWideChar, // number of characters in string
LPSTR lpMultiByteStr, // address of buffer for new string
int cchMultiByte, // size of buffer
LPCSTR lpDefaultChar, // address of default for unmappable
// characters
LPBOOL lpUsedDefaultChar // address of flag set when default
// char. used
);
void ConvertCString2string(CString& strSrc,std::string& strDes)
{
#ifndef UNICODE
strDes = strSrc;
#else
USES_CONVERSION;
strDes = W2A(strSrc.LockBuffer());
strSrc.UnlockBuffer();
#endif
}
CString str;
char Buf[255];
// CString ------>WCHAR *
WCHAR *pChar = str.GetBuffer(str.GetLength());
// WCHAR *------->char *
WideCharToMultiByte(CP_UTF8, 0, (LPCWSTR)pChar, -1, Buf, sizeof(Buf), NULL, NULL);
str.ReleaseBuffer();