Can't even get first program to run!!

I have been learning C++ with "C++ Beginners Guide" by Herbert Schildt. I have been using dev C++ with no problems throughout the whole of that course. I decided to do a bit of programming with Visual C++ Express and was going through the very first bits of a Direct X tutorial. The very first bit of code that I have copied and pasted is not working. It is supposed to put up a window with a bit of text in it.

Could anyone please identify what is wrong with this program or Visual C++? This is the code:

#include <windows.h> // include the basic windows header file

// the entry point for any Windows program
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nShowCmd)
{
// create a "Hello World" message box using MessageBox()
MessageBox(NULL,
L"Hello World!",
L"Just another Hello World program!",
MB_ICONEXCLAMATION | MB_OK);

// return 0 to Windows
return 0;
}

The Error I get is:

1>------ Build started: Project: c, Configuration: Debug Win32 ------
1> c1.cpp
1>c:\users\nathan2\documents\visual studio 2010\projects\c\c\c1.cpp(13): error C2664: 'MessageBoxA' : cannot convert parameter 2 from 'const wchar_t [13]' to 'LPCSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I would not even know where to start with working out what is wrong... Is it something to do with Visual C++ or is this program out of date? Visual C++ keeps telling me that the project is out of date each time i try to compile the program as well.
OMG! For crying out loud... it has "L" in front of the messages! I have seen this done before but I didn't spot it this time >:(

If I take the 2 "L"s off then it runs fine. I am very sorry that I didn't spot this before posting. Not a very good first post was it really?

Could anyone tell me why people put "L" in front of things like that? I am presuming it must be something that is obsolete or something.
closed account (zb0S216C)
A string that's proceeded with an "L" denotes a wide-string. Wide-strings support larger character sizes, such as Chinese. When working with such types, it's important to use the appropriate types. For instance:

1
2
std::wstring str_(L"String!\n");
std::wcout << str_;

In C++, wide-strings are represented with the wchar_t type, which is typically 2 bytes in length.

Wazzak
Last edited on
Topic archived. No new replies allowed.