Do you have an extern declaration in every other source file (e.g. in a header you include in them)? What are your errors?
I have the extern declaration in main.h, and I have main.h included in each of the source files, this setup works when I have the redeclaration in one of the source files. When I take out the redeclarations altogether I get the following linker errors that basically say hWnd cannot be found:
MS3DLoad.obj : error LNK2001: unresolved external symbol "struct HWND__ * hWnd" (?hWnd@@3PAUHWND__@@A)
Lesson1.obj : error LNK2001: unresolved external symbol "struct HWND__ * hWnd" (?hWnd@@3PAUHWND__@@A)
Debug/lesson1.exe : fatal error LNK1120: 1 unresolved externals
Strange huh
edit:
contents of Main.h
Code:
#ifndef MAIN_H
#define MAIN_H
typedef unsigned char byte;
typedef unsigned short word;
#include <windows.h> // Header File For Windows
#include <gl\gl.h> // Header File For The OpenGL32 Library
#include <gl\glu.h> // Header File For The GLu32 Library
#include <gl\glaux.h> // Header File For The Glaux Library]
#include <fstream.h>
#include <stdio.h>
#include "MS3D.H"
extern HWND hWnd;
void LoadModel(char *); //PROTOTYPES SUCK ASS
#endif
snippet from one of the source files
Code:
#include "Main.h"
void LoadModel(char * fileName) {
ifstream fin;
fin.open(fileName, ios::in | ios::binary | ios::nocreate);
if(fin.fail()){
MessageBox(NULL, "UNABLE TO OPEN MODEL FILE", "ERROR", MB_OK);
return;
}
fin.seekg(0, ios::end); //SEEK TO END OF FILE
long filesize = fin.tellg(); //GET SIZE IN BYTES OF FILE
fin.seekg(0 ,ios::beg); //SEEK BACK TO BEGINNING
byte *buffer = new byte[filesize]; //ALLOCATE MEMORY FOR BUFFER
fin.read(buffer, filesize); //READ STUFF FROM FILE INTO A BUFFER
fin.close();
byte *ptr = buffer; //CREATE POINTER TO BUFFER
MS3DHeader *pHeader = (MS3DHeader*) ptr;
ptr += sizeof(MS3DHeader);
char numvert[50];
int numverts = *(word*) ptr;
sprintf(numvert,"Number Verts: %d", 5);
SetWindowText(hWnd, "**** **** ****");
snippet from the other source file
Code:
#include "Main.h"
HDC hDC=NULL; // Private GDI Device Context
HGLRC hRC=NULL; // Permanent Rendering Context
HWND hWnd;
HINSTANCE hInstance; // Holds The Instance Of The Application
bool keys[256]; // Array Used For The Keyboard Routine
bool active=TRUE; // Window Active Flag Set To TRUE By Default
bool fullscreen=TRUE; // Fullscreen Flag Set To Fullscreen Mode By Default
Like I said, strange.