C++UTF8、ASCII怎样转换成宽字符?

UTF8转成宽字符

   char *pStr = text.GetBuffer(text.GetLength()); //取得str对象的原始字符串
   int nBufferSize = MultiByteToWideChar(CP_UTF8, 0, pStr, -1, NULL, 0); //取得所需缓存的多少
   wchar_t *pBuffer = (wchar_t*)malloc(nBufferSize * sizeof(wchar_t));//申请缓存空间
   MultiByteToWideChar(CP_UTF8, 0, pStr, -1 , pBuffer, nBufferSize*sizeof(wchar_t));//转码,pBuffer就是转换后的宽字符

ASCII转换成宽字符

int len=MultiByteToWideChar(CP_ACP, 0, (LPCSTR)filename, -1, NULL,0);
WCHAR* wtext = new WCHAR[len+1];
MultiByteToWideChar(CP_ACP, 0, filename, -1, wtext, len);



 

你可能感兴趣的:(随笔)