Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Help with Header files.

Help with Header files.

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelptutorial
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    VanHlebar
    wrote on last edited by
    #1

    I have a dll that includes a particular header file. In my main application code it too uses the same same header file. When I include the header file for my dll it tries to inclue the header file twice. How do I get the compiler to only include the file if it has not already been loaded? Example: DLL.h File - #include "Myheader.h" MainApp.h File - #include "Myheader.h" #include "DLL.h" Thanks for the help, -Eric

    M V RaviBeeR 3 Replies Last reply
    0
    • V VanHlebar

      I have a dll that includes a particular header file. In my main application code it too uses the same same header file. When I include the header file for my dll it tries to inclue the header file twice. How do I get the compiler to only include the file if it has not already been loaded? Example: DLL.h File - #include "Myheader.h" MainApp.h File - #include "Myheader.h" #include "DLL.h" Thanks for the help, -Eric

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      In Myheader.h:

      #ifndef MYHEADER_H_INCLUDED
      #define MYHEADER_H_INCLUDED

      // header contents here...

      #endif

      There is also the #pragma once command, however I prefer the #ifdef method so that I can test for the presence of the symbol to tell whether a header has been included. --Mike-- When 900 years old you reach, look as good you will not. Hmm. 1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click! My really out-of-date homepage Sonork-100.19012 Acid_Helm

      1 Reply Last reply
      0
      • V VanHlebar

        I have a dll that includes a particular header file. In my main application code it too uses the same same header file. When I include the header file for my dll it tries to inclue the header file twice. How do I get the compiler to only include the file if it has not already been loaded? Example: DLL.h File - #include "Myheader.h" MainApp.h File - #include "Myheader.h" #include "DLL.h" Thanks for the help, -Eric

        V Offline
        V Offline
        VanHlebar
        wrote on last edited by
        #3

        Ok.. I found it. Needed to use #if !defined and #endif in the header file. :D -Eric

        1 Reply Last reply
        0
        • V VanHlebar

          I have a dll that includes a particular header file. In my main application code it too uses the same same header file. When I include the header file for my dll it tries to inclue the header file twice. How do I get the compiler to only include the file if it has not already been loaded? Example: DLL.h File - #include "Myheader.h" MainApp.h File - #include "Myheader.h" #include "DLL.h" Thanks for the help, -Eric

          RaviBeeR Offline
          RaviBeeR Offline
          RaviBee
          wrote on last edited by
          #4

          The standard way to prevent multiple inclusion of a header file is to add this in each .h file. This example depicts foo.h.

          #ifndef foo_h
          #define foo_h
          ...
          #endif

          /ravi Let's put "civil" back in "civilization" http://www.ravib.com ravib@ravib.com

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups