标签:multibytetowidechar widechartomulitbyte
(1)ANSI转UNICODE
wchar_t * AnsiToUnicode(const char *pAnsi) { int nLen = MultiByteToWideChar(CP_ACP,0,pAnsi,strlen(pAnsi),nullptr,0); wchar_t *pUnicode = new wchar_t[nLen+1]; MultiByteToWideChar(CP_ACP,0,pAnsi,strlen(pAnsi),pUnicode,nLen); pUnicode[nLen]= ‘\0‘; return pUnicode; }
(2)UNICODE转ANSI
char * UnicodeToAnsi(const wchar_t *pUnicode) { int nLen = WideCharToMultiByte(CP_ACP,0,pUnicode,wcslen(pUnicode),nullptr,0,nullptr,nullptr); char *pAnsi = new char[nLen+1]; WideCharToMultiByte(CP_ACP,0,pUnicode,wcslen(pUnicode),pAnsi,nLen,nullptr,nullptr); pAnsi[nLen] = ‘\0‘; return pAnsi; }
本文出自 “whatever957” 博客,请务必保留此出处http://whatever957.blog.51cto.com/6835003/1652609
标签:multibytetowidechar widechartomulitbyte
原文地址:http://whatever957.blog.51cto.com/6835003/1652609