0

Hello!! So I just started moving over from Java to C++ and am having problems. All I am trying to do is make a simple MessageBox and when I try to run this code:

#include <windows.h>

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd){
    MessageBox(NULL, 
            L"Hello World!", 
            L"Hello World program", 
            MB_ICONEXCLAMATION | MB_OK);
    return 0;
} 

it just gives me this error:

main.cpp:7:39: error: cannot convert ‘const wchar_t*’ to ‘LPCSTR {aka const char*}’ for argument ‘2’ to ‘int MessageBoxA(HWND, LPCSTR, LPCSTR, UINT)’
             MB_ICONEXCLAMATION | MB_OK);
                                       ^`

Any ideas why it might be broke? Thank you!!

4
Contributors
3
Replies
19
Views
3 Years
Discussion Span
Last Post by rubberman
1

In Visual C++ 2012, it works for me.

In that environment, there's a compiler option to treat wchar_t as built in type.
Project | Properties | Congifuration Properties | C/C++ | Language Yes (/Zc:wchar_t)

1

Another option is to not use Windows for this... :rolleyes: Sorry, sarcastic genes showing here.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.