L"text" will not compile?

Sep 15, 2011 at 1:05pm
Hi, I was wondering if someone could explain to me why the following code will not compile..

1
2
3
4
5
6
7
8
9
10
11
#include <windows.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
    //create a "Hello World" message box using MessageBox()
    MessageBox(NULL,
               L"Press OK if George is Frickin Awesome!!!!",
               L"George",
               MB_ICONEXCLAMATION | MB_OK);

    return 0;
}


I get an error.. but if i remove the L before "Press okay.." & "George" the code compiles just fine.

I am running CodeBlocks on windows 7 64 bit.
Sep 15, 2011 at 1:14pm
closed account (1vRz3TCk)
Because of the UNICODE settings. Most Windows API functions are now hidden behind macros for example MessageBox will call either MessageBoxA or MessageBoxW depending on the UNICODE define along with this you will require L"Whatever" or just "Whatever", to make sure you have the correct one use the text macro:
TEXT("whatever")
Last edited on Sep 15, 2011 at 1:15pm
Sep 15, 2011 at 1:31pm
If you want to use unicode strings then the proper entry point should be

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nShowCmd)
Sep 15, 2011 at 1:35pm
Or just
 
int _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
Last edited on Sep 15, 2011 at 1:35pm
Sep 15, 2011 at 1:43pm
Thanks for the replies everyone (;
Sep 15, 2011 at 2:08pm
Or just

int _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)


I just don't see the point in using ASCII strings anymore in Windows apps so I've developed the habit of using unicode explicitly.
Topic archived. No new replies allowed.