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){
            L"Hello World!", 
            L"Hello World program", 
    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)’

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

Recommended Answers

All 3 Replies

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, learning, and sharing knowledge.