Results 1 to 3 of 3

Thread: stdafx.h, precompiled headers and windows.h

  1. #1

    Thread Starter
    Hyperactive Member chuddy's Avatar
    Join Date
    Oct 2002
    Posts
    333

    stdafx.h, precompiled headers and windows.h

    This is one of those things that I do not have a full grip of and have been ignoring for quite a while... what is the relationship between stdafx.h and precompiled headers?

    I have had many times when I have needed to add #include <windows.h> and then later find that I cannot use this as this inclusion is apparently made in my stdafx.h (although this has nothing but just #include stdafx.h - including itself?!)..

    The only things I know are (pls correct if I am wrong)...

    + if you want to use precompiled headers for a file you must include stdafx.h in the file
    + if you include a file with stdafx.h you cannot then have another file that includes <windows.h>

    Any material to shed light would be great

    Cheers!

  2. #2
    Fanatic Member twanvl's Avatar
    Join Date
    Dec 2001
    Posts
    771

    Re: stdafx.h, precompiled headers and windows.h

    Precompiled headers work like this:
    1. a header is selected as the precompiled header, by default this is stdafx.h
    2. all files that include that header as the first thing get to use the precompiled header.
    3. a source file must be designated to generate the precompiled header, but iirc this can sometimes be done behind the scenes.

    Including things in stdafx.h does not mean you are not allowed to include it elsewhere as well.

  3. #3
    Frenzied Member dis1411's Avatar
    Join Date
    Mar 2001
    Posts
    1,048

    Re: stdafx.h, precompiled headers and windows.h

    i assume the real problem is that something didn't work, you saw 'include windows.h' and tried that.

    if that's the case, know that with an MFC app you're already including a windows.h as you've figured out. you don't need to explicitly include it. the problem is that the windows.h your project is using predates whatever example you were looking at. so, it's simply time to begin using a newer version of windows.h

    this is done by grabbing the latest windows/platform sdk (that's compatible with your IDE). once you install it, tell your IDE to use the newer files instead of the ones that came with the product.

    you do this by digging around the IDE's options and add the paths to the appropriate subsection (make sure they are listed before the original paths):

    Executable files: C:\Program Files\Microsoft Platform SDK\Bin
    Include files: C:\Program Files\Microsoft Platform SDK\include
    Library files: C:\Program Files\Microsoft Platform SDK\lib
    Last edited by dis1411; Mar 3rd, 2006 at 04:19 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width