For a Unicode build your code needs to be more like this:
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPWSTR lpCmdLine, int nCmdShow)
{
MessageBox(NULL, L"Hello World!", L"Note", 1/*MB_OK*/);
printf(L"nCmdShow = %d\n", nCmdShow);
return 0;
}
At least by default this will be set to use the Windows subsystem (because the entry point is named a variant of WinMain). You can force that to the console subsystem (-subsystem:console
flag to the linker) or get it to happen by default by changing the entry point to a variant of main
instead:
int wmain(int argc, wchar_t **argv) { // ...
Obviously you won't be able to print nCmdShow
using this though (not that it really means anything in a console program). For that matter, since you're not using the command line arguments anyway, you can simplify this somewhat to:
int wmain(){ // ....
Actually, nCmdShow
is basically obsolete even for windowed programs. The first time a windowed program calls ShowWindow
, it normally passes nCmdShow
as the parameter. Windows, in turn, ignores the value passed in the first call to ShowWindow
, and instead uses the value from the process' STARTUPINFO
structure. Only in subsequent calls to ShowWindow
is the parameter used (and for these subsequent calls, you're not supposed to pass nCmdShow
either--you're supposed to pass one of the defined constants such as SW_SHOWNORMAL
).
Reference: MSDN entry for ShowWindow