1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
//ANSI转unicode wchar_t* AnsiToUnicode(char *str) { DWORD dwNum = MultiByteToWideChar (CP_ACP, 0, str, -1, NULL, 0); wchar_t *pwText; pwText = new wchar_t[dwNum]; if(!pwText) { delete []pwText; } MultiByteToWideChar (CP_ACP, 0, str, -1, pwText, dwNum); return pwText; } wchar_t *strUnicode = AnsiToUnicode(str); OutputDebugStringW(strUnicode); |
1 2 3 4 5 6 7 8 9 10 11 |
//Unicode转ansi wchar_t wText[20] = {L"宽字符转换实例!"}; DWORD dwNum = WideCharToMultiByte(CP_OEMCP,NULL,wText,-1,NULL,0,NULL,FALSE); char *psText; psText = new char[dwNum]; if(!psText) { delete []psText; } WideCharToMultiByte (CP_OEMCP,NULL,wText,-1,psText,dwNum,NULL,FALSE); delete []psText; |