Problem with sample MessageBox

Excuse me, Ihave a problem, i try to digit this simple code from the Petzhold book on a Visual c++ express project.

#include<windows.h>

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,

PSTR szCmdLine,int iCmdShow)

{

MessageBox (NULL, TEXT ("Hello, Windows 98!"), TEXT ("HelloMsg"), 0) ;

return 0 ;

}

The compiler send me this message:

Build started: Project: prova, Configuration: Debug Win32

Compiling...

prova.cpp

Linking...

MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function tmainCRTStartup

C:\Documents and Settings\Poggio\Documenti\Visual Studio 2005\Projects\prova\Debug\prova.exe : fatal error LNK1120: 1 unresolved externals

Build log was saved at "file://c:\Documents and Settings\Poggio\Documenti\Visual Studio 2005\Projects\prova\prova\Debug\BuildLog.htm"

prova - 2 error(s), 0 warning(s)

========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

How can I resolve this problem?

Thankyou!

[1597 byte] By [surfcaster] at [2008-2-18]
# 1
This is down to the fact that you created it as a console application. There are some settings you need to change in order to get it to work as a windows application. There are some slight and subtle differences between the two.
First of all, project properties->c++->preprocessor->preprocessor definitions change the _CONSOLE to _WINDOWS.
Secondly project properties->linker->system->subsystem change that to subsystem:windows.
That should get it to work properly as a windows application.
The thing is, that when you create a new project, in the application wizard can you select Windows Application instead of Console Application. If you can't there is one more step that you need to do. In the visual studio install directory, for me it is D:\Program Files (x86)\Microsoft Visual Studio 8, go to the VC\VCWizards\AppWiz\Generic\Application\html\1033 and edit the file AppSettings.htm. Comment out lines 441-444 and you will then be able to select Windows Application when you go to create a console application. Use this when you want to create windows apps instead and you wont have this problem again.
crescens2k at 2007-9-8 > top of Msdn Tech,Visual Studio Express Editions,Visual C++ 2005 Express Edition...
# 2
Thank you!!! Now it's all OK!!!!! Do you hace a personal site about programming? Now i think i' continue to study the api on the Petzold. Do you think it's a good book? Bye and thanks!
surfcaster at 2007-9-8 > top of Msdn Tech,Visual Studio Express Editions,Visual C++ 2005 Express Edition...