simple: saving window_handle to a global

Started by
4 comments, last by Ferinorius 22 years, 3 months ago
Ok, this isn''t a really hard question, but I am having a problem with my program. How do I save my window handle to a global, to be used throughout a few different header files? The window handle will be saved into a global that is referenced in a central header file that defines a bunch of other globals. It also has all the include files and such that is needed for all the other files. What seems to be going on is that as i declare the variables in the global header file, they are still being declared else where. I get linker errors saying things like "redefinition, main_window_handle already defined in GameEngine.cpp" crap. Well, i search all throughout the workspace and project, and find only the main_window_handles where they are expected to be. In the Global headerfile, and where they are actually used. So what can the problem be? When I click on the error in the error window in Vis. C++, it takes me to a blank line....what the hell? Neo-Toshi - The City That Never Sleeps
Advertisement
Declare the variable on every file (not sure about it) as extern (pretty sure about that).
humanity will always be slaved by its ignorance
In the .h file that you are including everywhere you should have
extern HWND g_hwnd;

In ONE (and only one) of your .cpp files, you should have a line like
HWND g_hwnd = NULL; // or whatever you want to initialize it to
Ok, at least it isnt linker errors anymore, but I am still getting these redefinition errors for these seemingly invisible HWND main_window_handle; i do searches, i look, all over.

Im going to try one more thing...

Edit:

Ok, deleted some older source files just incase they were being included still in the build, and that didnt work.

I have the browser information setup, so when I rightclick and select go to Definition of main_window_handle, it takes me to a blank spot on the scree, right before the
#endif of a headerfile that has nothing to do with this. It is also the same thing that was giving me the linker errors "already defined in balhdebalh.obj."

Here is the error...alas:
  C:\Documents and Settings\Ferinorius\My Documents\Important Documents\LegionTOD\GameEngine.cpp(13) : error C2374: 'main_window_handle' : redefinition; multiple initialization        c:\documents and settings\ferinorius\my documents\important documents\legiontod\globalhub.h(46) : see declaration of 'main_window_handle'C:\Documents and Settings\Ferinorius\My Documents\Important Documents\LegionTOD\GameEngine.cpp(14) : error C2374: 'main_instance' : redefinition; multiple initialization        c:\documents and settings\ferinorius\my documents\important documents\legiontod\globalhub.h(47) : see declaration of 'main_instance'     


Edited by - Ferinorius on January 10, 2002 8:02:45 PM
quote:Original post by Ferinorius
...it takes me to a blank spot on the scree, right before the
#endif of a headerfile that has nothing to do with this.

Which suggests that your inclusion guards may be "funky."

Also read up on the extern keyword.

[ GDNet Start Here | GDNet FAQ | MS RTFM | STL | Google ]
Thanks to Kylotan for the idea!
Well, what I discovered in my sher tiredness and overexhuastion, I figured out what I was doing.

this was in the global header file...
  extern HWND  main_window_handle = NULL; 


and in one of my files i have this...
HWND main_window_handle  =  NULL;  


Yeah, all I had to do was take the
=NULL;    
off of the end of the declaration in the global file, and all was well.

THanks for the help, sorry for the stupidity.

I once said: "My stupidity only shows when I am around intelligent people!"



Neo-Toshi - The City That Never Sleeps


Edited by - Ferinorius on January 13, 2002 3:39:16 PM

This topic is closed to new replies.

Advertisement