This is not my code, I have gotten it from a book and am trying to figure out how to get it to run. It has 5 sections (or 6) and I either get some error with external _main or unexpected end.

Here are the pieces

//---------------------------------
// Blizzard Application
// C++ Source - Blizzard.cpp
//---------------------------------
//---------------------------------
// Include Files
//---------------------------------
#include "Blizzard.h"
//---------------------------------
// Game Engine Functions
//---------------------------------
BOOL GameInitialize(HINSTANCE hInstance)
{
// Create the game engine
g_pGame = new GameEngine(hInstance, TEXT("Blizzard"),
TEXT("Blizzard"), IDI_BLIZZARD, IDI_BLIZZARD_SM);
if (g_pGame == NULL)
return FALSE;
// Set the frame rate
g_pGame->SetFrameRate(15);
return TRUE;
}
void GameStart(HWND hWindow)
{
// Seed the random number generator
srand(GetTickCount());
}
void GameEnd()
{
// Cleanup the game engine
delete g_pGame;
}
void GameActivate(HWND hWindow)
{
HDC  hDC;
RECT rect;
// Draw activation text on the game screen
GetClientRect(hWindow, &rect);
hDC = GetDC(hWindow);
DrawText(hDC, TEXT("Here comes the blizzard!"), -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
ReleaseDC(hWindow, hDC);
}
void GameDeactivate(HWND hWindow)
{
HDC  hDC;
RECT rect;
// Draw deactivation text on the game screen
GetClientRect(hWindow, &rect);
hDC = GetDC(hWindow);
DrawText(hDC, TEXT("The blizzard has passed."), -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
ReleaseDC(hWindow, hDC);
}
void GamePaint(HDC hDC)
{
}
void GameCycle()
{
HDC  hDC;
HWND hWindow = g_pGame->GetWindow();
// Draw the snowflake icon at random positions on the game screen
hDC = GetDC(hWindow);
DrawIcon(hDC, rand() % g_pGame->GetWidth(), rand() % g_pGame->GetHeight(),
(HICON)(WORD)GetClassLong(hWindow, GCL_HICON));
ReleaseDC(hWindow, hDC);
}
//Listing 2.7 The Complete GameEngine.cpp Source Code//

#include "GameEngine.h"
//--------------------------------
// Static Variable Initialization
//---------------------------------
GameEngine *GameEngine::m_pGameEngine = NULL;
//---------------------------------
// Windows Functions
//---------------------------------
// Listing 2.2 contains the source code for 
// the game engine's WinMain() function.
//---------------------------------
// Listing 2.2 The WinMain() Function in the 
// Game Engine Makes Calls to Game Engine Functions 
// and Methods and Provides a Neat Way of Separating 
// Standard Windows Program Code from Game Code
//---------------------------------

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
MSG     msg;
static int iTickTrigger = 0;
int     iTickCount;
if (GameInitialize(hInstance))
{
// Initialize the game engine
if (!GameEngine::GetEngine()->Initialize(iCmdShow))
return FALSE;
// Enter the main message loop
while (TRUE)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
// Process the message
if (msg.message == WM_QUIT)
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
// Make sure the game engine isn't sleeping
if (!GameEngine::GetEngine()->GetSleep())
{
// Check the tick count to see if a game cycle has elapsed
iTickCount = GetTickCount();
if (iTickCount > iTickTrigger)
{
iTickTrigger = iTickCount +
GameEngine::GetEngine()->GetFrameDelay();
GameCycle();
}
}
}
}
return (int)msg.wParam;
}
// End the game
GameEnd();
return TRUE;
}
LRESULT CALLBACK WndProc(HWND hWindow, UINT msg, WPARAM wParam, LPARAM lParam)
{
// Route all Windows messages to the game engine
return GameEngine::GetEngine()->HandleEvent(hWindow, msg, wParam, lParam);
}
//---------------------------------
// GameEngine Constructor(s)/Destructor
//---------------------------------
// Listing 2.3 The GameEngine::GameEngine()  
// Constructor Takes Care of Initializing
// Game Engine Member Variables, Whereas the 
// Destructor is Left Empty for Possible Future Use
//---------------------------------
GameEngine::GameEngine(HINSTANCE hInstance, LPTSTR szWindowClass,
LPTSTR szTitle, WORD wIcon, WORD wSmallIcon, int iWidth, int iHeight)
{
// Set the member variables for the game engine
m_pGameEngine = this;
m_hInstance = hInstance;
m_hWindow = NULL;
if (lstrlen(szWindowClass) > 0)
lstrcpy(m_szWindowClass, szWindowClass);
if (lstrlen(szTitle) > 0)
lstrcpy(m_szTitle, szTitle);
m_wIcon = wIcon;
m_wSmallIcon = wSmallIcon;
m_iWidth = iWidth;
m_iHeight = iHeight;
m_iFrameDelay = 50;  // 20 FPS default
m_bSleep = TRUE;
}
GameEngine::~GameEngine()
{
}
//---------------------------------
// Game Engine General Methods
//---------------------------------
// Listing 2.4 The GameEngine::Initialize() 
// Method Handles Some of the Dirty Work that
// Usually Takes Place in WinMain()
//---------------------------------

BOOL GameEngine::Initialize(int iCmdShow)
{
WNDCLASSEX  wndclass;
// Create the window class for the main window
wndclass.cbSize       = sizeof(wndclass);
wndclass.style     = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc  = WndProc;
wndclass.cbClsExtra   = 0;
wndclass.cbWndExtra   = 0;
wndclass.hInstance    = m_hInstance;
wndclass.hIcon      = LoadIcon(m_hInstance,
MAKEINTRESOURCE(GetIcon()));
wndclass.hIconSm      = LoadIcon(m_hInstance,
MAKEINTRESOURCE(GetSmallIcon()));
wndclass.hCursor      = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wndclass.lpszMenuName  = NULL;
wndclass.lpszClassName = m_szWindowClass;
// Register the window class
if (!RegisterClassEx(&wndclass))
return FALSE;
// Calculate the window size and position based upon the game size
int iWindowWidth = m_iWidth + GetSystemMetrics(SM_CXFIXEDFRAME) * 2,
iWindowHeight = m_iHeight + GetSystemMetrics(SM_CYFIXEDFRAME) * 2 +
GetSystemMetrics(SM_CYCAPTION);
if (wndclass.lpszMenuName != NULL)
iWindowHeight += GetSystemMetrics(SM_CYMENU);
int iXWindowPos = (GetSystemMetrics(SM_CXSCREEN) - iWindowWidth) / 2,
iYWindowPos = (GetSystemMetrics(SM_CYSCREEN) - iWindowHeight) / 2;
// Create the window
m_hWindow = CreateWindow(m_szWindowClass, m_szTitle, WS_POPUPWINDOW |
WS_CAPTION | WS_MINIMIZEBOX, iXWindowPos, iYWindowPos, iWindowWidth,
iWindowHeight, NULL, NULL, m_hInstance, NULL);
if (!m_hWindow)
return FALSE;
// Show and update the window
ShowWindow(m_hWindow, iCmdShow);
UpdateWindow(m_hWindow);
return TRUE;
}

//----------------------------
// Listing 2.5 The GameEngine::HandleEvent() 
// Method Receives and Handles Messages that 
// Are Normally Handled in WndProc()
//----------------------------

LRESULT GameEngine::HandleEvent(HWND hWindow, UINT msg, WPARAM wParam, LPARAM lParam)
{
// Route Windows messages to game engine member functions
switch (msg)
{
case WM_CREATE:
// Set the game window and start the game
SetWindow(hWindow);
GameStart(hWindow);
return 0;
case WM_SETFOCUS:
// Activate the game and update the Sleep status
GameActivate(hWindow);
SetSleep(FALSE);
return 0;
case WM_KILLFOCUS:
// Deactivate the game and update the Sleep status
GameDeactivate(hWindow);
SetSleep(TRUE);
return 0;
case WM_PAINT:
HDC     hDC;
PAINTSTRUCT ps;
hDC = BeginPaint(hWindow, &ps);
// Paint the game
GamePaint(hDC);
EndPaint(hWindow, &ps);
return 0;
case WM_DESTROY:
// End the game and exit the application
GameEnd();
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWindow, msg, wParam, lParam);
}
//---------------------------------
// Blizzard Application
// C++ Header - Blizzard.h
//---------------------------------
#pragma once
//---------------------------------
// Include Files
//---------------------------------
#include <windows.h>
#include "Resource.h"
#include "GameEngine.h"
//---------------------------------
// Global Variables
//---------------------------------
GameEngine* g_pGame;
#pragma once
//---------------------------------
// Include Files
//GameEngine.h
//---------------------------------
#include <windows.h>
//---------------------------------
// Windows Function Declarations
//---------------------------------
int WINAPI    WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow);
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
//---------------------------------
// Game Engine Function Declarations
//---------------------------------
BOOL GameInitialize(HINSTANCE hInstance);
void GameStart(HWND hWindow);
void GameEnd();
void GameActivate(HWND hWindow);
void GameDeactivate(HWND hWindow);
void GamePaint(HDC hDC);
void GameCycle();
//---------------------------------
// GameEngine Class
//---------------------------------
//Listing 2.1 The GameEngine Class Definition 
//Reveals How the Game Engine Is Designed
//---------------------------------

class GameEngine
{
protected:
// Member Variables
static GameEngine* m_pGameEngine;
HINSTANCE      m_hInstance;
HWND        m_hWindow;
TCHAR        m_szWindowClass[32];
TCHAR        m_szTitle[32];
WORD        m_wIcon, m_wSmallIcon;
int         m_iWidth, m_iHeight;
int         m_iFrameDelay;
BOOL        m_bSleep;
public:
// Constructor(s)/Destructor
GameEngine(HINSTANCE hInstance, LPTSTR szWindowClass, LPTSTR szTitle,
WORD wIcon, WORD wSmallIcon, int iWidth = 640, int iHeight = 480);
virtual ~GameEngine();
// General Methods
static GameEngine* GetEngine() { return m_pGameEngine; };
BOOL        Initialize(int iCmdShow);
LRESULT       HandleEvent(HWND hWindow, UINT msg, WPARAM wParam,
LPARAM lParam);
// Accessor Methods
HINSTANCE GetInstance() { return m_hInstance; };
HWND      GetWindow() { return m_hWindow; };
void      SetWindow(HWND hWindow) { m_hWindow = hWindow; };
LPTSTR    GetTitle() { return m_szTitle; };
WORD    GetIcon() { return m_wIcon; };
WORD    GetSmallIcon() { return m_wSmallIcon; };
int    GetWidth() { return m_iWidth; };
int       GetHeight() { return m_iHeight; };
int     GetFrameDelay() { return m_iFrameDelay; };
void      SetFrameRate(int iFrameRate) { m_iFrameDelay = 1000 /
iFrameRate; };
BOOL      GetSleep() { return m_bSleep; };
void     SetSleep(BOOL bSleep) { m_bSleep = bSleep; };
};
//---------------------------------
// Icons          Range : 1000 - 1999
//---------------------------------
#define IDI_BLIZZARD    1000
#define IDI_BLIZZARD_SM   1001

And then this... not sure if it is needed.. but if I add it I get a cannot find that ico.

#include "Resource.h"
//---------------------------------
//Blizzard.rc
// Icons
//---------------------------------
IDI_BLIZZARD    ICON     "Res\\Blizzard.ico"
IDI_BLIZZARD_SM  ICON     "Res\\Blizzard_sm.ico"

Also get this when compiling.

/*++

Copyright (c) 1997-1998  Microsoft Corporation

Module Name:

    basetsd.h

Abstract:

    Type definitions for the basic sized types.

Author:

    Jeff Havens (jhavens)   23-Oct-1997

Revision History:

--*/

#ifndef _BASETSD_H_
#define _BASETSD_H_

#ifdef __cplusplus
extern "C" {
#endif

//
// The following types are guaranteed to be signed and 32 bits wide.
//

typedef int LONG32, *PLONG32;
typedef int INT32, *PINT32;

//
// The following types are guaranteed to be unsigned and 32 bits wide.
//

typedef unsigned int ULONG32, *PULONG32;
typedef unsigned int DWORD32, *PDWORD32;
typedef unsigned int UINT32, *PUINT32;

//
// The INT_PTR is guaranteed to be the same size as a pointer.  Its
// size with change with pointer size (32/64).  It should be used
// anywhere that a pointer is cast to an integer type. UINT_PTR is
// the unsigned variation.
//
// HALF_PTR is half the size of a pointer it intended for use with
// within strcuture which contain a pointer and two small fields.
// UHALF_PTR is the unsigned variation.
//

#ifdef _WIN64

typedef __int64 INT_PTR, *PINT_PTR;
typedef unsigned __int64 UINT_PTR, *PUINT_PTR;

#define MAXINT_PTR (0x7fffffffffffffffI64)
#define MININT_PTR (0x8000000000000000I64)
#define MAXUINT_PTR (0xffffffffffffffffUI64)

typedef unsigned int UHALF_PTR, *PUHALF_PTR;
typedef int HALF_PTR, *PHALF_PTR;

#define MAXUHALF_PTR (0xffffffffUL)
#define MAXHALF_PTR (0x7fffffffL)
#define MINHALF_PTR (0x80000000L)

#pragma warning(disable:4311)   // type cast truncation

#if !defined(__midl)
__inline
unsigned long
HandleToUlong(
    void *h
    )
{
    return((unsigned long) h );
}

__inline
unsigned long
PtrToUlong(
    void  *p
    )
{
    return((unsigned long) p );
}

__inline
unsigned short
PtrToUshort(
    void  *p
    )
{
    return((unsigned short) p );
}

__inline
long
PtrToLong(
    void  *p
    )
{
    return((long) p );
}

__inline
short
PtrToShort(
    void  *p
    )
{
    return((short) p );
}
#endif
#pragma warning(3:4311)   // type cast truncation

#else


typedef long INT_PTR, *PINT_PTR;
typedef unsigned long UINT_PTR, *PUINT_PTR;

#define MAXINT_PTR (0x7fffffffL)
#define MININT_PTR (0x80000000L)
#define MAXUINT_PTR (0xffffffffUL)

typedef unsigned short UHALF_PTR, *PUHALF_PTR;
typedef short HALF_PTR, *PHALF_PTR;

#define MAXUHALF_PTR 0xffff
#define MAXHALF_PTR 0x7fff
#define MINHALF_PTR 0x8000

#define HandleToUlong( h ) ((ULONG) (h) )
#define PtrToUlong( p ) ((ULONG) (p) )
#define PtrToLong( p ) ((LONG) (p) )
#define PtrToUshort( p ) ((unsigned short) (p) )
#define PtrToShort( p ) ((short) (p) )

#endif

//
// SIZE_T used for counts or ranges which need to span the range of
// of a pointer.  SSIZE_T is the signed variation.
//

typedef UINT_PTR SIZE_T, *PSIZE_T;
typedef INT_PTR SSIZE_T, *PSSIZE_T;

//
// The following types are guaranteed to be signed and 64 bits wide.
//

typedef __int64 LONG64, *PLONG64;
typedef __int64 INT64, *PINT64;


//
// The following types are guaranteed to be unsigned and 64 bits wide.
//

typedef unsigned __int64 ULONG64, *PULONG64;
typedef unsigned __int64 DWORD64, *PDWORD64;
typedef unsigned __int64 UINT64, *PUINT64;

#ifdef __cplusplus
}
#endif

#endif // _BASETSD_H_

The different errors I get: C:\Program Files\Microsoft Visual Studio\HomeWork\GameEngine\Blizzard.rc(5): Could not find the file Res\Blizzard.ico.

LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/GameEngine.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
(2 errors)

Those are them
Please help
Lothia

This type of program is called Win32 GUI Application programming. You dont have a main function for those programs. Instead there is a WinMain function for the starting point.

The way you start such a program is different than from a console program. This depends on the compiler you use. If you are using a Visual Studio compiler the option is to select,
New Project
Win32 Application
Win32 GUI Application (Select the empty project.)
Add the above files to your project and build

note:
Since this is compiler dependent, the exact steps may differ. I advice you to state the compiler if you find any difficulty.

Hmm I was using the 32 Counsil Application (not the 32 application) Can you explain to me the difference between the two?

I am sorry but I do not see a edit button.
I have gotten it to work but the RC file still doesn't work. So a white screen loads but no snowflakes appear.
C:\Program Files\Microsoft Visual Studio\HomeWork\GameEngine\Blizzard.rc (5): error RC2135 : file not found: Res\Blizzard.ico
C:\Program Files\Microsoft Visual Studio\HomeWork\GameEngine\Blizzard.rc (6): error RC2135 : file not found: Res\Blizzard_sm.ico

What should I have them as to work?

hi Low-thee-a
i think u do not have complete image files required for your code to run, find them and copy them to your project folder then try building it again...
and mejaour difference between console and window application is, windows application is a message driven application.

I am sorry but I do not see a edit button.
I have gotten it to work but the RC file still doesn't work. So a white screen loads but no snowflakes appear.
C:\Program Files\Microsoft Visual Studio\HomeWork\GameEngine\Blizzard.rc (5): error RC2135 : file not found: Res\Blizzard.ico
C:\Program Files\Microsoft Visual Studio\HomeWork\GameEngine\Blizzard.rc (6): error RC2135 : file not found: Res\Blizzard_sm.ico

What should I have them as to work?

It means that you haven't got the icon files, Blizzard.ico and Blizzard_sm.ico in the resource directory. Since you said that you got this code from a book, most probably the book gives you only the executable code, but not the icon files. Maybe you can find those files in the CD-ROM of the book if it comes with one, or in the website of the book if it has one.

If the above ways does not work, an easy hack will be to copy an arbitrary .ico file in your hard drive, copy two copies of it to your resource directory ,rename it as Blizzard.ico and Blizzard_sm.ico, and try running. It should work, but what you see will not be snowflakes. Maybe Blizzard_sm.ico is size 16x16 while Blizzard.ico is 32x32. But it is worth giving a try.

Okay thank you. WOuld I put the full directory into the code to find it?

Usually only the files would be enough.

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.