basic dialog

hey i tried to make a basic program with just an windows and an message,
but when i try to compile it in Microsoft Visual Studio I get a failed error:
[code]c:documents and settings...noikmijn documentenvisual studio
2005projectsasics est1 est1main.cpp(25) : error C2664: 'MessageBoxW'
: cannot convert parameter 2 from 'const char [11]' to 'LPCWSTR'[/code]

but when i compile it in devc++ it works fine, what am i doing wrong in the M$ program??

my code is :

//create the main window
0, // for now supply this 0
WC_DIALOG, // window class name, predefined constant WC_DIALOG is used to create dialog boxes
"Mijn eigen window", // title text of the window
WS_OVERLAPPEDWINDOW | WS_VISIBLE, // style -WS_VISIBLE means make this window visible
400, // X coordinates on screen
100, // Y coordinates on screen
200, // Width of the window in pixels
200, // Height of the window in pixels
NULL // parent window handle - for now supply NULL
//display a message box
NULL, // parent window handle, supply NULL for fow
"Am message", // message that is displayed
"Am title", // title of the message box
0// style - supply 0 for now, means no style
return 0;


or is this just a confilict between a C or a C++ compiler?

P.S. where to learn more about Visual C++?


  • : sorry found my soultion
    : [link=
    : Message.aspx?S=B20000#359090]here[/link]
    : but what is the explanation for this change?

    At a guess you are using Visual Studio 2005 - the projects this version creates generates code in UNICODE but your string literal you are passing to the messagebox function is deemed to be the standard char array. The clue is given in the warning about MessageBoxW (the W bit being the important one). MessageBox function actually gets mapped to one of two functions depending on the UNICODE setting. MessageBoxA for standard char strings and MessageBoxW for unicode strings. The best way to get around this is to surround all your string literals with:
    [b]TEXT("[color=Red]your string goes here[/color]"). [/b]This means that if, later, you code for char-type strings, it will still work.

    Incidentally, if you convert a project from one character representation to another without using the wizard, you may come up with an entry-point error. You may have to set the entry point ([italic]Properties::Linker::Advanced::Entry Point[/italic]) to [color=Blue][b]wWinMainCRTStartup[/b][/color] for UNICODE and blank for MBCS/Not Set.

    Hope this is the answer you required and that it helps.

    Kind regards

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!