// 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?

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.

Comments
3 years too late - FAIL

@ 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.

Edited 6 Years Ago by NathanOliver: n/a

This article has been dead for over six months. Start a new discussion instead.