16,472
社区成员
发帖
与我相关
我的任务
分享
//ANSI转成UTF16
CStringW ANSItoUTF16(const CStringA& acp)
{
CStringW utf16;
int len = MultiByteToWideChar(CP_ACP, 0, acp, -1, NULL, 0);
if (len>1)
{
wchar_t *ptr = utf16.GetBuffer(len-1);
if (ptr) MultiByteToWideChar(CP_ACP, 0, acp, -1, ptr, len);
utf16.ReleaseBuffer();
}
return utf16;
}
//UTF16转ANSI
CStringA UTF16toANSI(const CStringW& utf16)
{
CStringA acp;
int len = WideCharToMultiByte(CP_UTF8, 0, utf16, -1, NULL, 0, 0, 0);
if (len>1)
{
char *ptr = acp.GetBuffer(len-1);
if (ptr) WideCharToMultiByte(CP_UTF8, 0, utf16, -1, ptr, len, 0, 0);
acp.ReleaseBuffer();
}
return acp;
}