#### Archived

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

# program organization

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

## Recommended Posts

forgive my ignorance here, but i was looking for some info on a problem ( actually two ) that seems to keep popping up for me. 1. I keep wondering how to implement some sort of global #includes for header files that almost every file in my program uses. Is there some way, or do I simply have to type it in every single file? 2. And second, when I load a bitmap with BitBlt, all I get is some wierd staticy looking stuff. What is causing that problem? is there some flag I can set that tells it what format the bmp file is in or something? or does the bmp have to be a specific format? I created several different formatted ones in photoshop, but they all do the same thing. Some more info: It changes color and amount each run. thanks in advance for anything you can help with.

##### Share on other sites
quote:
Original post by lucinpub
1. I keep wondering how to implement some sort of global #includes for header files that almost every file in my program uses. Is there some way, or do I simply have to type it in every single file?

// global.hextern type varname1;extern type varname2;...extern type varnameN;...return_type function1_decl;return_type function2_decl;...return_type functionN_decl;...etc

// in exactly one source file - global.cpptype varname1;type varname2;...type varnameN;...return_type function1_def;return_type function2_def;...return_type functionN_def;...etc

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! ]
Thanks to Kylotan for the idea!

##### Share on other sites
lucinpub: "DUH. Now I feel like a dope. that was easy."
Oluseyi: "Don't worry Newb, youll get there."
Thanks...
but that is part of what was looking for in part 1. the other is a way to #include a header file, say iostream.h or something in one file in a way such that i donot have to include it in the rest of the files, but they can still use it.

Edited by - lucinpub on February 25, 2002 1:15:28 AM

##### Share on other sites
quote:
Original post by lucinpub
but that is part of what was looking for in part 1. the other is a way to #include a header file, say iostream.h or something in one file in a way such that i donot have to include it in the rest of the files, but they can still use it.

Just include it in your global.h. make sure you have "inclusion guards" in your files, so things don''t get defined too many times (it''ll give you linker problems):
#ifndef GLOBAL_H#define GLOBAL_H  // header declarations#endif

GLOBAL_H can be anything you want. It''s an environment variable you set, and it works like this: If the variable is not defined, then we define it and declare all the stuff in the header. If it''s already defined, we skip the declarations (it''s in the environment already) and compilation proceeds without a hitch.

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! ]
Thanks to Kylotan for the idea!

##### Share on other sites
ahhh, the sweet sigh of relief....
Yeah, I always do the #ifndef first thing, so i dont forget.

I wish they taught me practical stuff like I learn on gdnet at my university...
let me make sure I understand this 100%. includes do a sort of domino effect, where everything included up the include ladder of a subsystem remains included in those further down the chain?

Edited by - lucinpub on February 25, 2002 1:49:30 AM

##### Share on other sites
>>>>>
2. And second, when I load a bitmap with BitBlt, all I get is some wierd staticy looking stuff. .... Some more info: It changes color and amount each run. thanks in advance for anything you can help with
>>>>
I use DirectDraw to load stuff

I create the DD object
Create the Surface
And using DDutil.h + ddutil2.h

ZoomBoy
Developing a iso-tile 2D RPG with skills, weapons, and adventure. See my old Hex-Tile RPG GAME, character editor, diary, 3D Art resources at Check out my web-site

##### Share on other sites
Chastise me with a hot poker if i''m wrong, but isn''t LoadImage a GDI function ? Surely you want D3DXLoadSurfaceFromFileA or D3DXLoadSurfaceFromFileW.

But LR_CREATEDIBSECTION remaps colors, so remove it from the LoadImage line and see if that helps.

##### Share on other sites
quote:
Original post by lucinpub
let me make sure I understand this 100%. includes do a sort of domino effect, where everything included up the include ladder of a subsystem remains included in those further down the chain?

Sort of. The thing that confuses people about #includes is that they are really a lot simpler than people think they are. All it means is "insert this file here". That file may in turn insert files and so on. Until you get one large eventual file, which is then compiled.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]

##### Share on other sites
include inserting files is probably misleading.

a better description would be make file available.

when you include a file, it lets the compiler know that that file may contain identifiers used in the source.

thats why you need to use ifndef HEAD #define HEAD at the very top of headers, before other includes, or you may get recursive includes.

##### Share on other sites
quote:
From MSDN
The #include directive tells the preprocessor to treat the contents of a specified file as if those contents had appeared in the source program at the point where the directive appears. You can organize constant and macro definitions into include files and then use #include directives to add these definitions to any source file. Include files are also useful for incorporating declarations of external variables and complex data types. You only need to define and name the types once in an include file created for that purpose.

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! ]
Thanks to Kylotan for the idea!

1. 1
2. 2
Rutin
20
3. 3
4. 4
frob
15
5. 5

• 10
• 9
• 14
• 9
• 33
• ### Forum Statistics

• Total Topics
632592
• Total Posts
3007296

×