0
votes

I have just started using vc++ 2008. I just want to see one message (dialog box). I have created my project as a win32 project application.

I wrote the code below to see a MessageBox

MessageBoxW(NULL, "Window Registration Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK);

but I m getting an error

error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [28]' to 'LPCWSTR'

What is this error ? What do I need to do to see a simple message box display.

3

3 Answers

5
votes

MessageBoxW takes "wide string" arguments, so add an L before each string:

MessageBoxW(NULL, L"Window Registration Failed!", L"Error!", MB_ICONEXCLAMATION | MB_OK);
0
votes

Jerry already explained that the cause of your compile error is a type mismatch (you have a function that expects wide strings and are passing it a narrow string). I would recommend that you don't use the wide or narrow specific function (the ones with the W or A suffix), but use the non-suffix ones instead (MessageBox in this particular case). The Windows API header files contain code that will then select the correct version of the function depending on your build settings, ie if you're building Unicode versions of the software or not.

0
votes

You are using ASCII input string for a MessageBoxW instead of ASCII message box. Try to use the following code instead:

 MessageBoxA(NULL, "Window Registration Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK);