Started looking at the win32 API on this site: http://www.winprog.org/tutorial/start.html
I've literally just compiled the first example and it's given me a message prompt in chinese/japanese, or something along those lines.
Question: Why?
Obviously as far as my understanding goes, I should be getting "Goodbye, cruel world!" in a message box (Presumably titled 'Note').
#include <windows.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
MessageBox(NULL, "Goodbye, cruel world!", "Note", MB_OK);
return 0;
}
Thanks.
Try to change the code like this:
#include <windows.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
MessageBox(NULL, L"Goodbye, cruel world!", L"Note", MB_OK);
return 0;
}
If it works is because you are missing some header that point the correct API, you seem calling MessageBoxW ( the unicode version ) with an ANSI string. If this is not just a test but you are beginning to write a real world program, consider to ensure what kind of caracter you want to use ( this is a precompiler flag usually ). Then use the macro _T(
to have your literals compatible both to unicode/ansi.
Edit from @Benoit comment: Starting a new project with VS 2008/10 sets unicode character set by default.
MessageBox(NULL, _T("Goodbye, cruel world!"), _T("Note"), MB_OK);
or
MessageBoxA(NULL, "Goodbye, cruel world!", "Note", MB_OK);
I can't get it set to default, so each new project it must be set. To find the setting: Using Visual Studio 2010 From the main Menu → Projects → Properties → Configuration Properties → General → Project Details → Character Set → "Use Multi-Byte Character set" (was set to "Use Unicode Character Set")
After that all seems well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With