1.wchar *转 char *
char *wtoc(wchar_t *wText) { DWORD dwNum = WideCharToMultiByte(CP_ACP, NULL, wText, -1,NULL, 0, NULL, FALSE);//把第五个参数设成NULL的到宽字符串的长度包括结尾符 char *psText = NULL; psText = new char[dwNum]; if(!psText) { delete []psText; psText = NULL; } WideCharToMultiByte (CP_ACP, NULL, wText, -1,psText, dwNum, NULL, FALSE); return psText; }
2. char *转wchar *
wchar_t *ctow(char *sText) { DWORD dwNum = MultiByteToWideChar (CP_ACP, 0, sText, -1, NULL, 0);//把第五个参数设成NULL的到宽字符串的长度包括结尾符 wchar_t *pwText = NULL; pwText = new wchar_t[dwNum]; if(!pwText) { delete []pwText; pwText = NULL; } unsigned nLen = MultiByteToWideChar (CP_ACP, 0, sText, -1, pwText, dwNum+10); if (nLen >= 0) {pwText[nLen] = 0;} return pwText; }
时间: 2024-10-24 14:58:40