simple messagebox display in vc++
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(NU开发者_StackOverflow中文版LL, "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.
MessageBoxW
takes "wide string" arguments, so add an L
before each string:
MessageBoxW(NULL, L"Window Registration Failed!", L"Error!", MB_ICONEXCLAMATION | MB_OK);
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.
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);
精彩评论