// Windows Programming Tutorial Series
#include "stdafx.h"
#include <windows.h>
int WINAPI
WinMain(HINSTANCE hInst, 
     HINSTANCE hPrevInstance,
 LPSTR lpCmdLine,
        int nCmdShow)
{
 MessageBox (NULL, "Hello World! This is my first WIN32 program", 
                "Lesson 1", MB_OK);
 return 0;
}

2 errors:
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/a.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
a.exe - 2 error(s), 0 warning(s)

Who can make some suggestions please?
I guess it may be I did not include the lib well.

Where are the code tags?
Where is main() defined (unresolved external symbol _main)
Did you link with the debug library?

Make sure you created a Win32 project and not a console project (how to do that depends on your IDE)

when I include this C++ source file into a "Win32 Application" project, it works;
when include it into a "Win32 Console Application" project, it fails;
my question is how to change the settings of the latter to make it work, without creating a new project of Wind32 Application.
I tried include the macro _WINDOWS in the setting->c/c++->preprocess definitions , but it did not work.

Visual Studio? Try Linker->System->Subsystem (/SUBSYSTEM:WINDOWS)

Although I can't guarantee there aren't other options that are normally set for a Win32 project, and I don't know why you would want to do this.

Why do you want a console application to be windowed? I mean, there are ways, but it seems silly.

// Windows Programming Tutorial Series
      #include "stdafx.h"
      #include <windows.h>
      int WINAPI
      WinMain(HINSTANCE hInst,
      HINSTANCE hPrevInstance,
      LPSTR lpCmdLine,
      int nCmdShow)
      {
      MessageBox (NULL, "Hello World! This is my first WIN32 program",
      "Lesson 1", MB_OK);
      return 0;
      }

I think I may know your problem, and for a million dollars ill solve it for you :D.

you forgot a ";"

Guess where?

// Windows Programming Tutorial Series
#include "stdafx.h"
#include <windows.h>
int WINAPI
WinMain(HINSTANCE hInst,
HINSTANCE hPrevInstance,

The lack of a ";" is messing up your winmain. that's why it has a problem.

Least... im pretty sure. Beginner at C++ myself but im good at PHP and that would create a problem in most languages, if im right.

commented: 3 years too late - FAIL -4

@ ookamioni The problem OP is having is he is trying to make a win32 app work as a win32 console. In a console you generally have int main() not WinMain(). He is not missing a ";" anywhere.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.