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!!

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)

Another option is to remove the L in front of the two string literals.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.