uh, after reading all the articles, I still cannot clear my problem. I got a strange problem in Creating Surface with DirectDraw.
My project base in Multiple file. There are 6 files in the project
unit.h //define the UNIT functions based in Class structure. unit.cpp //the UNIT Class. ddrawex.h //define the DDraw functions. ddrawex.cpp //the DDraw functions. ( contest of Create Surface function. ) main.h //include "unit.h" and "ddrawex.h" main.cpp //main program.
In the "unit.cpp" and "ddrawex.cpp" have codes following:
#include "main.h"
that''s the way I make them liked. But If I define the LPDIRECTDRAW in "main.h" , then the compiler said "it''s already defined in ddrawex.cpp and unit.cpp" (Because they all include the "main.h") . how to make the LPDIRECTDRAW structure become a global variable?
Make sure your linking the right wrapper... In project -> settings -> link and in the libraries list, include your ddraw lib there. Make sure that the directory of this lib is at the top of your list in the Directories tab... DirectX always seems to be a bitch about this
First, if you want to make that LPDIRECTDRAW be global, you would need to use EXTERN, however, there should be one place where this file is just declared normally (i.e. WITHOUT the extern).....
so, lets say you want the LPDIRECTDRAW to be in, ddrawex.h....
//main.h #ifndef MAIN_H #define MAIN_H
#include "ddrawex.h" #include "unit.h"
LPDIRECTDRAW something;
#endif
//ddrawex.h #ifndef DDRAWEX_H #define DDRAWEX_H
#include "main.h"
extern LPDIRECTDRAW something;
//Whatever else you need here.. #endif
//unit.h #ifndef UNIT_H #define UNIT_H
#include "main.h" extern LPDIRECTDRAW something;
//Whatever else goes here... #endif
then, in your .cpp files, just include the corresponding header.
(e.g.) in UNIT.CPP, do: #include "unit.h"
I MAY not be 100% right on the use of externs when you include them in header files. If for some reason this doesn''t work, simply OMIT any line in the above header files that have extern LPDIRECTDRAW something.... But keep the one that DOESN''T start with extern....
woohoo thanks Mihkael for the help I tried the steps you gave and finnaly got my code to work with a second cpp file. I used extern in my two header files and defined them in one of my cpp files. Weeks of frustration finnaly over.