Conversion from ASCII to Unicode char code (FreeType2)
ascii, c++, freetype, unicode
Solution
The `CodePage` parameter to `MultiByteToWideChar` is wrong. Utf-8 is not the same as ASCII. You should be using `CP_ACP` which tells is the current system code page (which is not the same as ASCII - see Unicode, UTF, ASCII, ANSI format differences)
Size is zero most likely because your test string is not a valid Utf-8 string.
For almost all Win32 functions you can call GetLastError() after the function fails to get the detailed error code, so calling that would give you more details as well.
Problem
I'm using FreeType2 in one of my projects. In order to render a letter, I need to provide a Unicode two-byte character code. The char codes a program reads are in ASCII one-byte format though. It poses no problem for char codes below 128 (the character codes are the same), but the other 128 do not match. For instance: 'a' in ASCII is 0x61, 'a' in Unicode is 0x0061 - that's fine 'ą' in ASCII is 0xB9, 'ą' in Unicode is 0x0105 - completely different I was trying to use WinAPI functions there, but I must be doing something wrong. Here's a sample: ``` unsigned char szTest1[] = "ąółź"; //ASCII format wchar_t* wszTest2; int size = MultiByteToWideChar(CP_UTF8, 0, (char*)szTest1, 4, NULL, 0); printf("size = %d\n", size); wszTest2 = new wchar_t[size]; MultiByteToWideChar(CP_UTF8, 0, (char*)szTest1, 4, wszTest2, size); printf("HEX: %x\n", wszTest2[0]); delete[] wszTest2; ``` I'm expecting a new wide string to be created, with no NULL at the end. However, the size variable always equals 0. Any idea what I'm doing wrong? Or maybe there's an easier way to solve the problem?