create a console function, translate ansi char(chinese) to utf8 char
by Zhangfujian · in Torque Game Engine · 06/23/2010 (7:08 am) · 0 replies
The code from “fiona1011“
//----------------
// ansi(chinese) to unicode
char* szAnsi = "abcd1234你我他";
//get the utf8-char size
int wcsLen = ::MultiByteToWideChar(CP_ACP, NULL, szAnsi, strlen(szAnsi), NULL, 0);
//don't forget the '\0'.(wcsLen + 1)
wchar_t* wszString = new wchar_t[wcsLen + 1];
//translation
::MultiByteToWideChar(CP_ACP, NULL, szAnsi, strlen(szAnsi), wszString, wcsLen);
//add '\0'
wszString[wcsLen] = '\0';
//----------------
//----------------
// ansi(chinese) to unicode
char* szAnsi = "abcd1234你我他";
//get the utf8-char size
int wcsLen = ::MultiByteToWideChar(CP_ACP, NULL, szAnsi, strlen(szAnsi), NULL, 0);
//don't forget the '\0'.(wcsLen + 1)
wchar_t* wszString = new wchar_t[wcsLen + 1];
//translation
::MultiByteToWideChar(CP_ACP, NULL, szAnsi, strlen(szAnsi), wszString, wcsLen);
//add '\0'
wszString[wcsLen] = '\0';
//----------------