Sign in to follow this  

Compiling error " F1005 Include files nested too deep

This topic is 4807 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

Hi guys I'm a newbie to this side of the bizz, I'm getting this error wile trying to compile my first GameEngine; here is the code that seem to be causing it. #pragma once //--------------------------------------------------------------------------- // Include Files //--------------------------------------------------------------------------- #include <windows.h> #include "Resource.h" #include "GameEngine.h" //--------------------------------------------------------------------------- // Global Variables //--------------------------------------------------------------------------- GameEngine* _pGame; Can someone give me a hint? Thank you very much ernesto.

Share this post


Link to post
Share on other sites
The preprocessor can only follow a chain of includes to a certain depth. If one of your .h files in turn includes an .h file that itself includes an .h file, which also includes another .h file, etc., it will only go so deep until it backs out with an error. IIRC, this sort of behavior can also be triggered with an 'unguarded' .h file that includes itself. Without guards to force inclusion of the file only once (usually of the #ifndef/#define/#endif variet), you could conceivably get stuck in a chain whereby the file recursively includes itself until the threshold limit is reached.

So, make sure your Resource.h and GameEngine.h files do not include themselves, and check the chain of files they _do_ include to make sure you're not going over depth.

Share this post


Link to post
Share on other sites
I think I understand I have 3 .h files, they are as follows GameEngine.h Resource.h and Skeleton.h. 2 of the file they have each other in there, I will play to find out how they should be.

Thank you very much.

Ernesto.

#pragma once

//---------------------------------------------------------------------------
// Include Files
//---------------------------------------------------------------------------
#include <windows.h>
#include "Resource.h"
#include "GameEngine.h"
//---------------------------------------------------------------------------
// Global Variables
//---------------------------------------------------------------------------
GameEngine* _pGame;
=========================================================
//-----------------------------------------------------------------
// Icons Range : 1000 - 1999
//-----------------------------------------------------------------
#define IDI_SKELETON 1000
#define IDI_SKELETON_SM 1001
===========================================================
#pragma once
//---------------------------------------------------------------------------
// Include Files
//---------------------------------------------------------------------------
#include <windows.h>
#include "Resource.h"
#include "GameEngine.h"
//---------------------------------------------------------------------------
// Global Variables
//---------------------------------------------------------------------------
GameEngine* _pGame;

Share this post


Link to post
Share on other sites
Which compiler are you using? It might not recognize #pragma once. Try putting every header file into #define guards like this:


#ifndef _FILENAMEGOESHERE_
#define _FILENAMEGOESHERE_

// header file goes here
#endif

Share this post


Link to post
Share on other sites
Don't rely solely on #pragma once. Always have #ifdef/#define/#endif inclusion guards. #pragma once is just an optimization (the compiler will not reopen the file), and is known to not work properly in some cases - even on compilers that do recognize it.

Why does GameEngine.h include itself?

Share this post


Link to post
Share on other sites
I don't understand how to do this? I will need to read some more as it broke all the code. Does C++BuilderX support #pragma I understand that it's not the best to use but I'm realy lost if I try changing it to ifndef. Could I be a total bother and ask someone to explain how to use ifndef?

Sorry and thank you

Ernesto.

Which compiler are you using? It might not recognize #pragma once. Try putting every header file into #define guards like this:


#ifndef _FILENAMEGOESHERE_
#define _FILENAMEGOESHERE_

// header file goes here
#endif

Share this post


Link to post
Share on other sites
Quote:
Original post by ernestovr
I don't understand how to do this? I will need to read some more as it broke all the code. Does C++BuilderX support #pragma I understand that it's not the best to use but I'm realy lost if I try changing it to ifndef. Could I be a total bother and ask someone to explain how to use ifndef?

Sorry and thank you

Ernesto.

Which compiler are you using? It might not recognize #pragma once. Try putting every header file into #define guards like this:


#ifndef _FILENAMEGOESHERE_
#define _FILENAMEGOESHERE_

// header file goes here
#endif


Like so:

in resource.h:
#ifndef _RESOURCE_H_
#define _RESOURCE_H_

<insert code here>

#endif // _RESOURCE_H_

and similar code in GameEngine.h

Share this post


Link to post
Share on other sites
Try changing your files to look more like this



// The first 2 lines of every .h file should look something
// like this (you can change GAMEENGINE_H to a more suitable name tho)
#ifndef GAMEENGINE_H
#define GAMEENGINE_H

//---------------------------------------------------------------------------
// Include Files
//---------------------------------------------------------------------------
#include <windows.h>
#include "Resource.h"
#include "GameEngine.h"
//---------------------------------------------------------------------------
// Global Variables
//---------------------------------------------------------------------------
GameEngine* _pGame;

// this is always the last line in your .h file
#endif


#ifndef, #endif are called precomiler directives.

#ifndef checks of the name specified is not defined
if it is not, then it allows the compiler to include the whole file. If the name is defined, it jumps to #endif, without including your file.

Share this post


Link to post
Share on other sites
Thank you very much I will tryied this right now. I have notice that everyone is talking about 2 of the 3 .h files I have but not about the 3rd is there a reason? This is my first time trying it so I created a GameEngine.cpp and .h a Skeleton.cpp and .h and a Resource.rc and .h should I had put the Skeleton and the Resource together? Sorry about the names but as I stated before I'm a total begginer.

Thank you everyone

Ernesto.

Share this post


Link to post
Share on other sites
I'm very sorry I tried my best to get this to work but it did not here is every .h file and the errors are on the bottom.

Thank you.

Ernesto.

#ifndef GAMEENGINE_H
#define GAMEENGINE_H
//---------------------------------------------------------------------------
// Include Files
//---------------------------------------------------------------------------
#include <windows.h>
#include "Skeleton.h"
//---------------------------------------------------------------------------
// Global Variables
//---------------------------------------------------------------------------
GameEngine* _pGame;
// this is always the last line in your .h file
#endif
================================================================
// The first 2 lines of every .h file should look something like this
#ifndef RESOURCE_H
#define RESOURCE_H

//-----------------------------------------------------------------
// Icons Range : 1000 - 1999
//-----------------------------------------------------------------
#define IDI_SKELETON 1000
#define IDI_SKELETON_SM 1001

// this is always the last line in your .h file
#endif
===============================================================
// The first 2 lines of every .h file should look something like this
#ifndef SKELETON_H
#define SKELETON_H

//---------------------------------------------------------------------------
// Include Files
//---------------------------------------------------------------------------
#include <windows.h>
#include "Resource.h"
#include "GameEngine.h"
//---------------------------------------------------------------------------
// Global Variables
//---------------------------------------------------------------------------
//GameEngine* _pGame;
// this is always the last line in your .h file
#endif
=============================================================
"GameEngine.h": E2141 Declaration syntax error at line 13
"GameEngine.cpp": E2451 Undefined symbol 'mhWindow' in function GameEngine::SetWindow(HWND__ *) at line 43
"GameEngine.cpp": E2379 Statement missing ; in function GameEngine::SetSleep(int) at line 51
"GameEngine.cpp": E2451 Undefined symbol 'WndProc' in function GameEngine::Initialize(int) at line 139
"GameEngine.cpp": E2294 Structure required on left side of . or .* in function GameEngine::Initialize(int) at line 145
"GameEngine.cpp": E2121 Function call missing ) in function GameEngine::Initialize(int) at line 146
"GameEngine.cpp": E2451 Undefined symbol 'retrun' in function GameEngine::Initialize(int) at line 170
"GameEngine.cpp": E2379 Statement missing ; in function GameEngine::Initialize(int) at line 170

Share this post


Link to post
Share on other sites
Thank you I got all exept one and this one does not make any sence. Here is the error;

"GameEngine.cpp": E2451 Undefined symbol 'WndProc' in function GameEngine::Initialize(int) at line 139

Here is the code that were the symbol is at.
//---------------------------------------------------------------------------
// INITIALIZE
//---------------------------------------------------------------------------
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;

Thank you for any help.

Ernesto.

Share this post


Link to post
Share on other sites
Wow... what a mess..

Ok I'm going to give this a shot. First off here are my assumptions.


// Assuming this is GameEngine.h
#ifndef GAMEENGINE_H
#define GAMEENGINE_H

#include <windows.h>
#include "Skeleton.h"
GameEngine* _pGame;

#endif

// Assuming this is Resource.h
#ifndef RESOURCE_H
#define RESOURCE_H

#define IDI_SKELETON 1000
#define IDI_SKELETON_SM 1001

#endif

// Assuming this is Skeleton.h
#ifndef SKELETON_H
#define SKELETON_H

#include <windows.h>
#include "Resource.h"
#include "GameEngine.h"
GameEngine* _pGame;

#endif


Now I'm not going to make an attempt at your errors to start because there are quite a few and the problem isn't straight forward. In fact some of what I say might be wrong for what your trying to do since I cant see the .cpp files. But lets look at what your doing and try to make sense of it.

First off you are declaring an instance of GameEngine pointer named _pGame in two different header files. Generally speaking placing a global variable in a header file is a bad idea. The reason for this is that if you include the header in to two different cpp files, they will have differing versions of the variable when you compile and the linker will fail with something like "VariableX already defined in OtherCppFile.obj".

You only want one variable in the object code and allow other files to access it by externing it in a common header. Eg.


// GameEngine.cpp
#include "GameEngine.h"

class GameEngine
{
// class implementation goes here
};

// instance of your global
GameEngine *_pGame;

// GameEngine.h
#ifndef GAMEENGINE_H
#define GAMEENGINE_H
extern GameEngine *_pGame;
#endif


Now as for all three Undefined symbols in GameEngine::Initialize(), those are similar to the above. The variables/functions are located in a different cpp file. In order for the compile to know about them they have to be defined. For functions this is merely restating the definition before you try to use it. For variables it can be solved with an extern like in the previous example.

The rest of the errors look like syntax problems, I cant be much use there, just examine the lines carefully and try to correct them.

Hope this helps somewhat.

Share this post


Link to post
Share on other sites
Illumini: Thank you very much, you were right, there were some syntax error and I use your examples to correct some of my problems. After correcting my .h files and some syntax error I only have one error left but I have been looking around everywere and I can't find any info so I was hoping you could help me again. Here are the files.

Thank you.

Ernesto.

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ERROR
"GameEngine.cpp": E2451 Undefined symbol 'WndProc' in function GameEngine::Initialize(int) at line 137
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
CODE WERE THE ERROR IS COMING FROM
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//---------------------------------------------------------------------------
// INITIALIZE
//---------------------------------------------------------------------------
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;


++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ALL THE CODE
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++// GAMEENGINE.CPP
//---------------------------------------------------------------------------
#include "GameEngine.h"
BOOL GameInitialize(HINSTANCE hInstance);
void GameStart(HWND hWindow);
void GameEnd();
void GameActivate(HWND hWindow);
void GameDeactivate(HWND hWindow);
void GamePaint(HDC hDC);
void GameCycle();
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 GetFrameRate(int iFrameRate) { m_iFrameDelay = 1000 / iFrameRate; };
BOOL GetSleep() { return m_bSleep; };
void SetSleep(BOOL bSleep) { m_bSleep = bSleep; };
};
//---------------------------------------------------------------------------
// WINMAIN
//---------------------------------------------------------------------------
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;
}
//---------------------------------------------------------------------------
// CONSTRUCTOR
//---------------------------------------------------------------------------
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()
{
}
//---------------------------------------------------------------------------
// INITIALIZE
//---------------------------------------------------------------------------
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;
}
//---------------------------------------------------------------------------
// HANDLEEVENT
//---------------------------------------------------------------------------
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_ACTIVATE:
// ACTIVE/DEACTIVATE THE GAME AND UPDATE THE SLEEP STATUS
if (wParam != WA_INACTIVE)
{
GameActivate(hWindow);
SetSleep(FALSE);
}
else
{
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);
}
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// GameEngine.h
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#ifndef GAMEENGINE_H
#define GAMEENGINE_H

#include <windows.h>
#include "Skeleton.h"
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Resource.h
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#ifndef RESOURCE_H
#define RESOURCE_H

#define IDI_SKELETON 1000
#define IDI_SKELETON_SM 1001

//-----------------------------------------------------------------
// Icons Range : 1000 - 1999
//-----------------------------------------------------------------
#define IDI_SKELETON 1000
#define IDI_SKELETON_SM 1001
#endif

#endif
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Resource.rc
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Include Files
//-----------------------------------------------------------------
#include "Resource.h"
//-----------------------------------------------------------------
// Icons
//-----------------------------------------------------------------
IDI_SKELETON ICON "Skeleton.ico"
IDI_SKELETON_SM ICON "Skeleton_sm.ico"
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Skeleton.cpp
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//---------------------------------------------------------------------------
// Include Files
//---------------------------------------------------------------------------
#include "Skeleton.h"
//---------------------------------------------------------------------------
// Game Engine Functions
//---------------------------------------------------------------------------
BOOL GameInitialize(HINSTANCE hInstance)
{
// Create the game engine
_pGame = new GameEngine(hInstance, TEXT("Game Skeleton"),
TEXT("Game Skeleton"), IDI_SKELETON, IDI_SKELETON_SM);
if (_pGame == NULL)
return FALSE;

// Set the frame rate
_pGame->SetFrameRate(15);

return TRUE;
}

void GameStart(HWND hWindow)
{
// Seed the random number generator
srand(GetTickCount());
}

void GameEnd()
{
// Cleanup the game engine
delete _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("Activated!"), -1, &rect,
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
ReleaseDC(hWindow, hDC);
}

void GameDeactivation text on the game screen
{
HDC hDC;
RECT rect;

// Draw deactivation text on the game screen
GetClientRect(hWindow, &rect);
hDC = GetDC(hWindow);
DrawText(hDC, TEXT("Deactivated!"), -1, &rect,
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
ReleaseDC(hWindow, hDC);
}

void GamePaint(HDC hDC)
{
}

void GameCycle()
{
HDC hDC;
HWND hWindow = _pGame->GetWindow();

// Draw the skeleton icon at random positions on the game screen
hDC = GetDC(hWindow);
DrawIcon(hDC, rand() % _pGame->GetWidth(), rand() % _pGame->getHeight(),
(HICON)(WORD)GetClassLong(hWindow, GCL_HICON));
ReleaseDC(hWindow, hDC);
}
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Skeleton.h
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#ifndef SKELETON_H
#define SKELETON_H

//---------------------------------------------------------------------------
// Include Files
//---------------------------------------------------------------------------
#include <windows.h>
#include "Resource.h"
#include "GameEngine.h"
//---------------------------------------------------------------------------
// Global Variables
//---------------------------------------------------------------------------
#endif
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Simple question: Why even try writing a "game engine" when you dont even understand the language enough to solve problems like these? Im not saying that you should give up or anything, but merely recommending a smaller project at first. Most of the important stuff can be experimented with using a simple console application. Way too many beginners seem to start out this way, but hey people, mastering a language and programming paradigm takes time. Accept it and start small. You will be rewarded in the long run.

Share this post


Link to post
Share on other sites
I understand that it may be a bigger project that I should be taken on but I'm waiting for a class to start and I'm trying to get my hands wet. I bought one of this books that give you some lesons it was no big deal getting the skeleton done so I thought I could go forward. I'm starting to think that I should wait for the class. Thank you very much.

Share this post


Link to post
Share on other sites
If an example is not working, then you've set up your compiler wrong. Btw - have you provided the WndProc function?

I'll throw an example of very basic Win32 application - does nothing, but creates an empty window, but it may be helpful to you:


#include <windows.h>

const char *className = "win32app";

//just a declaration - so the compiler knows "there's something called WndProc"
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);

//this is the entry point of the application
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE, LPSTR, int)
{
//now - I'll register the window class
WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW; //I want the window to be redrawn whenever vertical or horizontal resize happens
wc.lpfnWndProc = WndProc; //the compiler already knows, there's someting called WndProc (look above)
wc.cbClsExtra = 0; //I don't want an extra bytes
wc.cbWndExtra = 0; //here neither
wc.hInstance = hInstance; //the handle of instance
wc.hIcon = LoadIcon (0, IDI_APPLICATION); //standard windows-provided icon - because I don't have one =)
wc.hCursor = LoadCursor (0, IDC_ARROW); //standard arrow cursor
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); //use standard window background
wc.lpszMenuName = 0; //no menu
wc.lpszClassName = className; //the name of the class

RegisterClass (&wc); //register the class

//now - I'll create the window
HWND hWnd = CreateWindowEx (
0, //no extended window style
className, //the name of the class I've just registered
"A simple win32 application", //window title
WS_OVERLAPPEDWINDOW, //window style
CW_USEDEFAULT, //x-position - just use default positioning
CW_USEDEFAULT, //y-position...
CW_USEDEFAULT, //width
CW_USEDEFAULT, //height
0, //handle of parent - I'm creating toplevel window - it doesn't have a parent
0, //handle of menu - the window doesn't have any
hInstance, //handle of instance
0 //an extra parameter
);

//next, I'll make the window visible
ShowWindow (hWnd, SW_SHOW);
UpdateWindow (hWnd);

//then, I'll enter the game message loop (game, because, that's probably what you're interested in)
MSG msg;

while (true) {
//see, wheter there's a message
if (PeekMessage (&msg, 0, 0, 0, PM_REMOVE)) {
//yes, there's one
//is it WM_QUIT?
if (msg.message == WM_QUIT)
break; //yes, break the loop

//no, it's something other - process it
TranslateMessage (&msg);
DispatchMessage (&msg);
} else {
//no, there's no message
//let's do something fancy here =)
}
}

return msg.wParam; //the end
}

//the window procedure
LRESULT CALLBACK WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
//see, what message it is
switch (msg) {
case WM_DESTROY: {
//window-destruction (closing) message (so, the window is able to be closed)
PostQuitMessage (0);
return 0;
}
}

//no message, I'm interested in - pass it back to the OS
return DefWindowProc (hWnd, msg, wParam, lParam);
}





This won't create any basic game or whatever, but it'll create a window. [smile]

If there's something unclear about it - just ask [smile]

Oxyd

Share this post


Link to post
Share on other sites

This topic is 4807 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this