compile error with simple Win32 Application

Started by
5 comments, last by SB4 16 years ago
hello, I'm reading Beginning Game Programming (Jonathan S. Harbour), when i want to compile simple HelloWorld Application :

#include<windows.h>

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
				   LPSTR lpCmdLine, int nCmdShow)
{
	MessageBox(NULL, "All your base are belong to us!",
		"Hello World", MB_OK | MB_ICONEXCLAMATION);
}
Visual C++ ( Visual Studio 2005 ) show me this output :

1>------ Build started: Project: 001_HelloWorld, Configuration: Debug Win32 ------
1>Compiling...
1>main.cpp
1>c:\documents and settings\toshiba\my documents\visual studio 2005\projects\001_helloworld\001_helloworld\main.cpp(10) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [32]' to 'LPCWSTR'
1>        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>Build log was saved at "file://c:\Documents and Settings\TOSHIBA\My Documents\Visual Studio 2005\Projects\001_HelloWorld\001_HelloWorld\Debug\BuildLog.htm"
1>001_HelloWorld - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

and stop compile what's the problem and how to solve it ? if the is any good books for create Win32 Application please post the name of the book thanks in advance... Regards, SB4
Advertisement
Go to your project settings, under general, and change character set from "Use Unicode Character Set" to "Use Multi-Byte Character Set"
This problem actually comes up so much I made a journal post explaining it. Feel free to read if you'd like to know why you're getting that error.

[Edited by - MJP on March 24, 2008 11:08:43 PM]
You might also want to put #define WIN32_LEAN_AND_MEAN before the include <windows.h>
** boolean010 **
SiCrane, MJP & boolean010 thank u very much

MJP link don't work show this massage :
Microsoft VBScript runtime error '800a000d'

Type mismatch: 'CLng'

/community/forums/mod/journal/journal.asp, line 224


Regards,
SB4
Sorry about that, the link seems to get mangled when I post it. I tinyurl'ed it for you, so it should work now.
thanks MJP :)

This topic is closed to new replies.

Advertisement