Jump to content
  • Advertisement
Sign in to follow this  
Dangling Pointer

Which header to include?

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

I've got a class that's being used in two related programs. One of them uses MFC, and the other one is using DirectX without MFC. I'm having trouble figuring out what to include for the windows types. If I include <afx.h>, it will compile by itself, but when I try to build I get an error in my non-MFC program that says not to explicitly include windows.h in an MFC program (because I include windows.h in another file). If I include <windows.h>, the same thing happens in my MFC program. Is there a header somewhere that I can include with the windows types (HDC, BOOL, etc..) that will let me get around this? Another approach I tried, but had no success with, was to try something like: #ifdef USE_MFC #include <afx.h> #else #include <windows.h> #endif but this didn't work either. Any help is much appreciated!

Share this post


Link to post
Share on other sites
Advertisement
Umm, im not up to scratch with using MFC, but, do you define around your own headers.

ie.


imaginary header.h

#ifndef _MYHEADER_FILE_HEADER_H_
#define _MYHEADER_FILE_HEADER_H_

/*

... // header file code here


*/


#endif // end this preprocessor directive



What this code does is first it checks to see if '_MYHEADER_FILE_HEADER_H_' has been registered in this program, ie, has this header file already been included. If not it defines the '_MYHEADER_FILE_HEADER_H_', then includes ur own header file, if it does exist it leaves the header.

Although this probably isnt the soluttion it is the only thing i can think of.

ace

Share this post


Link to post
Share on other sites
I've heard that MFC isnt appreciated by the majority of programmers.

There is nothing more educational than doing all of the work urself, even though the coding standard probs won't be as high as the mfc stuff.

I don't use it

ace

Share this post


Link to post
Share on other sites
Okay, I fiddled around some, and my idea of using the preprocesser directives seems to be working for the MFC one. However, it's still not working properly for the non-mfc one.

In my class, I need to call LoadImage to load a bitmap from a resource. To do this, I need to get call AfxGetInstanceHandle, so I still need the afxwin.h header.

Through playing around, and a bit of googling, apparently the order in which I include the files matters. If I go:

#include <windows.h>
#include <afxwin.h>

I'll get the error I mentioned above, about not including windows.h in mfc applications.


I'm playing around a bit more now, but it's looking promising.. still open to suggestions if there's a nicer way of solving this

Share this post


Link to post
Share on other sites
Hmm... now I'm getting some other issues (assertion fails) when I try to call AfxGetInstanceHandle.. for now, I'm just gonna comment that out, since I'm not actually loading my image from a resource... just thought it'd be good to leave that capability there.

In the meantime, I'll look for another way to get a handle to the instance besides the above mentioned function.

Share this post


Link to post
Share on other sites
Seems strange. Maybe it'd be worth checking out the code for afx.h

It is incredibly unlikely but there might be something wrong in there. I'm thinking that maybe windows.h includes afx.h and since ur re-including it there is a conflict. But i honestly can't see this as the likely reason.

If you want, whack up ur code here, with

tags and i might be able to spot something.

ace

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!