(1)将Unicode转换为UTF8格式:
wchar_t * wsContent =L"";
int nContentLen = WideCharToMultiByte(CP_UTF8, 0, wsContent, -1, NULL, 0, NULL, NULL);
int nLen = nContentLen*sizeof(wchar_t);
char * pCdata = new char[nLen];
int ret = WideCharToMultiByte(CP_UTF8, 0, wsContent, -1, pCdata, nContentLen, NULL, NULL);
(2)将UTF8格式转换为Unicode:
char* pchar = "";
int nUnicodeLen = MultiByteToWideChar(CP_UTF8, 0, pchar, -1, NULL, 0);
wchar_t * pWcdata = new wchar_t[nUnicodeLen + 1];
int ret = MultiByteToWideChar(CP_UTF8, 0, pchar, -1, pWcdata, nUnicodeLen);
(3)将Unicode转换为ANSI格式:
wchar_t * wsContent =L"";
int nContentLen = WideCharToMultiByte(CP_ACP, 0, wsContent, -1, NULL, 0, NULL, NULL);
int nLen = nContentLen*sizeof(wchar_t);
char * pCdata = new char[nLen];
int ret = WideCharToMultiByte(CP_ACP, 0, wsContent, -1, pCdata, nContentLen, NULL, NULL);
(4)将ANSI格式转换为Unicode:
char* pchar = "";
int nUnicodeLen = MultiByteToWideChar(CP_ACP, 0, pchar, -1, NULL, 0);
wchar_t * pWcdata = new wchar_t[nUnicodeLen + 1];
int ret = MultiByteToWideChar(CP_ACP, 0, pchar, -1, pWcdata, nUnicodeLen);