1 char* wchar2char(const wchar_t* _wsrc, char* _dest, size_t _destLen) 2 { 3 int iTextLen = WideCharToMultiByte(CP_ACP, 4 0, 5 _wsrc, 6 -1, 7 NULL, 8 0, 9 NULL, 10 NULL); 11 12 int maxLen = (size_t)iTextLen > _destLen ? _destLen : iTextLen; 13 14 ::WideCharToMultiByte(CP_ACP, 15 0, 16 _wsrc, 17 -1, 18 _dest, 19 maxLen, 20 NULL, 21 NULL); 22 23 return _dest; 24 } 25 26 wchar_t* char2wchar(const char* _src, wchar_t* _dest, size_t _destLen) 27 { 28 int unicodeLen = ::MultiByteToWideChar(CP_ACP, 29 0, 30 _src, 31 -1, 32 NULL, 33 NULL); 34 35 int maxLen = (size_t)unicodeLen > _destLen ? _destLen : unicodeLen; 36 37 ::MultiByteToWideChar(CP_ACP, 38 0, 39 _src, 40 -1, 41 (LPWSTR)_dest, 42 maxLen); 43 44 return _dest; 45 46 }