(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; }
时间: 2024-11-02 23:24:07