Craig M Jones

As the title suggests, i am new to c++!

To start with i got Visual Studio 2005 and Visual C++ via that.

When following an example on the very basic first program that is the Hello World program, the code given was:

Code Block

#define WIN32_LEAN_AND_MEAN

#include <windows.h>

#include <windowsx.h>

int WINAPI WinMain(HINSTANCE hinstance,

HINSTANCE hprevinstance,

LPSTR lpcmdline,

int ncmdshow)

{

MessageBox(NULL, "What's up world!",

"My First Windows Program",MB_OK);

return(0);

}

Obviously, this just opens a message box with the text "What's up world!" in it with an OK button and a title "My first windows program". I set this up by creating a new win32 application within a new empty project and added a .cpp file with the code above. However, i got the following error message:

error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [17]' to 'LPCWSTR'

1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

Anyone able to inform as to why and point out a way round the problem



Re: Visual C++ Language Hello world compiler error.

Jonathan Caves - MSFT

Hi: you should take a look at this thread.






Re: Visual C++ Language Hello world compiler error.

Ring0

Hi Craig, You just need to add the "L" (Which is a Compiler Directive <- that fact is not often explained in texts. You are supposed to "just know that" grrrr. . Compilers these days are a _very_ complex and robust beast - as Jonathan will agree! )

This will work....

Code Block

#define WIN32_LEAN_AND_MEAN

#include <windows.h>

#include <windowsx.h>

int WINAPI WinMain(HINSTANCE hinstance,

HINSTANCE hprevinstance,

LPSTR lpcmdline,

int ncmdshow)

{

MessageBox(NULL, L"What's up world!", L"My First Windows Program", MB_OK);

return(0);

}

Ring0 The Lord Of The Execution Privileges - (Intel style anyway).