1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
wchar_t *AnsiToUnicode(char *strAnsi)
{
wchar_t *uOutStr;
int lenA = lstrlenA(strAnsi);
int lenW = MultiByteToWideChar(CP_ACP, 0, strAnsi, lenA, NULL, 0);
if (lenW > 0)
{
uOutStr = (wchar_t *)malloc(lenW + 1);
MultiByteToWideChar(CP_ACP, 0, strAnsi, lenA, uOutStr, lenW);
uOutStr[lenW] = 0;
return uOutStr;
}else{
return NULL;
}
}
char *UnicodeToAnsi(wchar_t *strUnicode)
{
char *aOutStr;
int lenW = lstrlenW(strUnicode);
int lenA = WideCharToMultiByte(CP_ACP, 0, strUnicode, lenW, 0, 0, NULL, NULL);
if (lenA > 0)
{
aOutStr = (char *)malloc(lenA + 1);
WideCharToMultiByte(CP_ACP, 0, strUnicode, lenW, aOutStr, lenA, NULL, NULL);
return aOutStr;
}else{
return NULL;
}
}
int main(int argc, char* argv[])
{
MessageBoxW(NULL, AnsiToUnicode("Hello World!"), AnsiToUnicode("Testing 1, 2, 3..."), MB_OK);
MessageBoxA(NULL, UnicodeToAnsi(L"Hello World!"), UnicodeToAnsi(L"Testing 1, 2, 3..."), MB_OK);
return 0;
}
|