Sign in to follow this  

RESOLVED - MessageBox() isn't working

Recommended Posts

ukdeveloper    264
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:

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 <windows.h>. Here's the bizarre bit: If I try:
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.

Share this post

Link to post
Share on other sites
SiCrane    11839
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.

Share this post

Link to post
Share on other sites
gunning    749
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.


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.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this