Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Cant compile this please help!

This topic is 5577 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

well ive got some error at build time and i cant figure it out what it is (sorry for posting the hole cpp but i dont know what to do Compiling... WinMain.cpp Linking... LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main Debug/WinMain.exe : fatal error LNK1120: 1 unresolved externals Error executing link.exe. WinMain.exe - 2 error(s), 0 warning(s)

//Building my Application Framework

//For Future Win32 programs

//Armando Alva@2003

//Source help thanks to Jim Adams and A. LaMothe


// INCLUDES /////////////////////////////////////////////////

#include <windows.h>
#include <windowsx.h>
#include <stdio.h>
#include <stdarg.h>

// MAIN APLICATION INSTANCES ////////////////////////////////

HINSTANCE g_hInstance;	//Global instance handle

HWND	g_hWnd;			//Global window handle


#define WNDWIDTH 400
#define WNDHEIGHT 400

const char g_szClass[] = "FrameClass";
const char g_szCaption[] = "FrameCaption";

// FUNCTION PROTOTYPES //////////////////////////////////////

//Entry Point

int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
				   LPSTR szCmdLine, int nCmdShow);

//Function to display an error message

void AppError(BOOL Fatal, char *Text, ...);

//Message Procedure

long FAR PASCAL WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam,
						   LPARAM lParam);

//Functions to register and unregister windows' classes

BOOL RegisterWindowClasses(HINSTANCE hInstance);

BOOL UnregisterWindowClasses(HINSTANCE hInstance);

//Function to create the application window

HWND CreateMainWindow(HINSTANCE hInstance);

//Functions to init, shutdown, and handle per-frame functions

BOOL DoInit();

BOOL DoShutdown();

BOOL DoPreFrame();

BOOL DoFrame();

BOOL DoPostFrame();

// Function Development!???

int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
				   LPSTR szCmdLine, int nCmdShow)

	MSG Msg;

	// Save application instance

	g_hInstance = hInstance;

	// Register Window Classes - Return on FALSE

	if (RegisterWindowClasses(hInstance) == FALSE)
		return FALSE;

	// Create Window - return on FALSE

	if ((g_hWnd = CreateMainWindow(hInstance)) == NULL)
		return FALSE;

	// Do application initialization -  return on FALSE

	if (DoInit() == TRUE) {

		//Enter the message Pump

		ZeroMemory(&Msg, sizeof(MSG));

		while (Msg.message != WM_QUIT) {
			// Handle Window Messages (if any)

			if (PeekMessage(&Msg, NULL, 0,0, PM_REMOVE)) {

			} else {
				// Do pre-frame processing, break on FALSE return value!

				if(DoPreFrame() == FALSE)

				// Do frame processing, break on FALSE return value

				if(DoFrame() == FALSE)

				// Do post-frame processing, break on FALSE return value

				if(DoPostFrame() == FALSE)


	// Do shutdown functions


	// Unregister window


	return TRUE;

BOOL RegisterWindowClasses(HINSTANCE hInstance)

	//Create Window Class here and register it 

	wcex.cbSize			= sizeof(wcex);
	wcex.style			= CS_CLASSDC;
	wcex.lpfnWndProc	= WindowProc;
	wcex.cbClsExtra		= 0;
	wcex.cbWndExtra		= 0;
	wcex.hInstance		= hInstance;
	wcex.hIcon			= LoadIcon(NULL, IDI_APPLICATION);
	wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground	= NULL;
	wcex.lpszMenuName	= NULL;
	wcex.lpszClassName  = g_szClass;
	wcex.hIconSm		= LoadIcon(NULL, IDI_APPLICATION);

	if (!RegisterClassEx(&wcex))
		return FALSE;

	return TRUE;

BOOL UnregisterWindowClasses(HINSTANCE hInstance)
	// Unregister Window Class

	UnregisterClass(g_szClass, hInstance);

	return TRUE;


HWND CreateMainWindow(HINSTANCE hInstance)
	HWND hWnd;

	// Create Main Window

	hWnd = CreateWindow(g_szClass, g_szCaption, WNDTYPE, 0,0,

	if (!hWnd)
		return NULL;

	//show and update the window

	ShowWindow(hWnd, SW_NORMAL);

	//return the window handle

	return hWnd;

void AppError(BOOL Fatal, char *Text, ...)
	char CaptionText[12];
	char ErrorText[2048];
	va_list valist;

	// Build the message box caption based on fatal flag

	if (Fatal == FALSE)
		strcpy(CaptionText, "Error");
		strcpy(CaptionText, "Fatal Error");

	// Build variable text buffer

	va_start(valist, Text);
	vsprintf(ErrorText, Text, valist);

	// Display the message box

	MessageBox(NULL, ErrorText, CaptionText,
	// Post a quit message if error was fatal

	if (Fatal == TRUE)

// !!The message procedure - empty except for destroy message!!

long FAR PASCAL WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, 
						   LPARAM lParam)

	switch (uMsg) {
		case WM_DESTROY:
			return 0;

	return DefWindowProc(hWnd, uMsg, wParam, lParam);

BOOL DoInit()
	//Perform application initialization functions here

	//such as those that set up the graphics, sound, network, etc

	//Return a value of TRUE for success, FALSE otherwise

	return TRUE;

BOOL DoShutdown()
	//Perform application shutdown functions here

	//such as those that shut down the graphics, sound, etc,

	//Return a value of TRUE foe succes, FALSE otherwise

	return TRUE;

BOOL DoPreFrame()
	//Perform pre-frame processing, such as setting up a timer,

	//Return a TRUE on success, FALSE otherwise

	return TRUE;

BOOL DoFrame()
	//Perform frame processing, such as rendering,

	//Return a TRUE on success, FALSE otherwise

	return TRUE;

BOOL DoPostFrame()
	//Perform post-frame processing, such as time synching etc.

	//Return TRUE on success, FALSE otherwise

	return TRUE;
Just remember there are three types of ppl in this world: those who can count and those who cant peace [edited by - EvilNando on June 17, 2003 5:25:51 PM]

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!