Sign in to follow this  

RESOLVED - MessageBox() isn't working

This topic is 4520 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 <windows.h>. 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.

Share this post


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

Share this post


Link to post
Share on other sites

This topic is 4520 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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