Win32 in C++ displays in Chinese ... what did i do wrong?
c, c++, win32gui, winapi
Solution
You are calling Unicode functions but passing ASCII text in.
This cast is wrong:
(LPCWSTR) "Yes, I remember Adlestrop"
Instead, use the `L` prefix, and don't cast:
L"Yes, I remember Adlestrop"
Explanation
Prefixing a string literal with `L` means that the literal will be encoded with UTF-161 and have elements of type `wchar_t` instead of `char`. Win32 expects UTF-16, unless you `#undef UNICODE` which is generally a bad idea.
The `TEXT()` macro
You might see code which uses the `TEXT()` macro.
TEXT("Yes, I remember Adlestrop")
This is an old way of doing things to retain compatibility with code written before Unicode was available. Unless you are maintaining a legacy application, you should avoid the `TEXT()` macro, and leave `UNICODE` defined. `UNICODE` is defined by default in recent versions of Visual Studio so there is usually no need to define it yourself.
Footnotes
1: On Windows.
Problem
I am new to win32 and C++ , i just started learning followed a tutorial online and wrote this code : ``` #include <windows.h> int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { MessageBox(NULL, (LPCWSTR) "Yes, I remember Adlestrop", (LPCWSTR) "A minimal windows program", MB_OK); return 0; } ``` But when in compiled and run the code the,in the message box the text were sort of Chinese ... I know that if i don mention proper types the the output might be binary or ASCCI or hex .... But first time it turned out be Chinese .. Can any one tell me what I did wrong ? ?