int __stdcall CMFCControlContainer::UTF8ToString(LPCSTR lpSrc, CString& strDst, int nLength)
{
LPTSTR lpDst = NULL;
int count = ::MultiByteToWideChar(CP_UTF8, 0, lpSrc, nLength, NULL, 0);
if (count <= 0)
{
return 0;
}
LPWSTR lpWide = new WCHAR[count + 1];
memset(lpWide, 0, (count + 1) * sizeof(WCHAR));
::MultiByteToWideChar(CP_UTF8, 0, lpSrc, nLength, lpWide, count);
#ifdef _UNICODE
lpDst = lpWide;
#else
count = ::WideCharToMultiByte(::GetACP(), 0, lpWide, -1, NULL, 0, NULL, 0);
if (count > 0)
{
lpDst = new char[count + 1];
memset(lpDst, 0, count + 1);
::WideCharToMultiByte(::GetACP(), 0, lpWide, -1, lpDst, count, NULL, 0);
}
delete [] lpWide;
#endif
strDst = lpDst;
delete[] lpDst;
return count;
}
MFC2010自带的一个字符集转换函数UTF8ToString(LPCSTR lpSrc, CString& strDst, int nLength)
最新推荐文章于 2021-02-12 22:55:13 发布