# RESOLVED - MessageBox() isn't working

## 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 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 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 on other sites
Both of these things worked, thanks!

My project is now in English.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
627701
• Total Posts
2978705

• 21
• 14
• 12
• 10
• 12