Skip to main content
GameDev.net gamedev.net
🔒 Locked

RESOLVED - MessageBox() isn't working

Started by ukdeveloper Aug 3, 2005 at 3:46 PM 2 replies 1.2k views
Original Post
ukdeveloper
ukdeveloper
Hi, Here's a weird issue I've been getting under VC++ 2005 Express Beta 2. I can't seem to get MessageBox() to work properly, and I think the problem only started recently. I've done it the "usual way" many times before using other compilers, but it's only now started playing up. Supposing I tried:


MessageBox(NULL,"Hello","Hello",MB_OK);
I've used such examples in countless programs before. But now, I get error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [6]' to 'LPCWSTR' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast I'm including . Here's the bizarre bit: If I try:

MessageBox(NULL,(LPCWSTR)"Hello",NULL,MB_OK);
this appears: That is in Chinese (seems to be, anyway, I'm no expert). And no, it isn't Photoshopped or edited - that's exactly what came out of the second code snippet. So, here's my problem. I can't just do MessageBox() the way MSDN or any other online tutorial suggests (the first code snippet), because VC++ 2005 flips out. And if I follow the compiler output telling me how to fix it, it puts my program into Chinese (or something like it). Sorry, but I'm stumped. Sod's law, and my rotten luck, suggests nobody else has experienced this problem ever. Can anybody offer any information as to what the problem is? Thanks in advance, ukdeveloper.
SiCrane
SiCrane
It seems like your project is now in unicode more. In project properties you can change it back to use narrow character if you wish. Otherwise, just change your strings to either L"Hello" or _T("Hello"). The first makes them wide strings, the second makes the narrow or wide depending on your project properties.
gunning
gunning
You can't just convert an ASCII string to a wide character string like that. Try either one of these instead:

MessageBox (NULL, L"Hello", L"Hello", MB_OK);

L" creates the string literal using wide characters.

OR

MessageBoxA (NULL, "Hello", "Hello", MB_OK);

The A at the end means that you will be using the ASCII version of the function and not the wide character version. Microsoft made the wide character version standard in the latest platform SDK or Visual Studio version (I don't know which) probably to make people start switching over.
....[size="1"]Brent Gunning
ukdeveloper
ukdeveloper
Both of these things worked, thanks!

My project is now in English.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.