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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. #include cpp file - how it works?

#include cpp file - how it works?

Scheduled Pinned Locked Moved C / C++ / MFC
c++debuggingquestion
6 Posts 4 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
    Vaclav_
    wrote on last edited by
    #1

    I am using DirectShow "common" dshowutil.cpp file and I just found this, to me new , usage of #include directive. It only works if included in a source file where its function(s) are used. Makes sense. Elsewhere the linker generates multiple definitions, so it must be included somewhere else, I did not search for it. Here is the #include: #pragma message("Common DirectShow support ") #include "D:\00\0 SDK\DIrectShow 8.1 SDK\samples\Multimedia\DirectShow\Common\dshowutil.cpp" And here is the usage sample: TRACE("\nFind input and output pins and connect them"); IPin * pCapOut = GetOutPin( pDocument->pC_Graph->gcap.pVCap, 0 ); In my view it prepends the working source file. I would like some other explanations from the group. Is such usage of including cpp file common? Thanks for your time. CHeers Vaclav

    J L 2 Replies Last reply
    0
    • V Vaclav_

      I am using DirectShow "common" dshowutil.cpp file and I just found this, to me new , usage of #include directive. It only works if included in a source file where its function(s) are used. Makes sense. Elsewhere the linker generates multiple definitions, so it must be included somewhere else, I did not search for it. Here is the #include: #pragma message("Common DirectShow support ") #include "D:\00\0 SDK\DIrectShow 8.1 SDK\samples\Multimedia\DirectShow\Common\dshowutil.cpp" And here is the usage sample: TRACE("\nFind input and output pins and connect them"); IPin * pCapOut = GetOutPin( pDocument->pC_Graph->gcap.pVCap, 0 ); In my view it prepends the working source file. I would like some other explanations from the group. Is such usage of including cpp file common? Thanks for your time. CHeers Vaclav

      J Offline
      J Offline
      Jochen Arndt
      wrote on last edited by
      #2

      The #include statement is a preprocessor directive. The preprocessor is reading input files, processes his commands, and writes the result to an output file (source file name with extension 'i'). The #include statement just inserts the processed content of another file. When invoking the compiler, the preprocessor is started first for each source file and the created preprocessed file is the input for the compiler. After compilation the file is deleted (the deletion can be omitted by passing a compiler option flag on the command line or setting it in the VS project setting). It is not very common to include other source files but allowed.

      1 Reply Last reply
      0
      • V Vaclav_

        I am using DirectShow "common" dshowutil.cpp file and I just found this, to me new , usage of #include directive. It only works if included in a source file where its function(s) are used. Makes sense. Elsewhere the linker generates multiple definitions, so it must be included somewhere else, I did not search for it. Here is the #include: #pragma message("Common DirectShow support ") #include "D:\00\0 SDK\DIrectShow 8.1 SDK\samples\Multimedia\DirectShow\Common\dshowutil.cpp" And here is the usage sample: TRACE("\nFind input and output pins and connect them"); IPin * pCapOut = GetOutPin( pDocument->pC_Graph->gcap.pVCap, 0 ); In my view it prepends the working source file. I would like some other explanations from the group. Is such usage of including cpp file common? Thanks for your time. CHeers Vaclav

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Vaclav_Sal wrote:

        In my view it prepends the working source file

        But that is perfectly acceptable as long as all required include files are added within that cpp file. It is just the same as adding some extra functions at the top of a source file before the #include statements required by the remainder of the source.

        V 1 Reply Last reply
        0
        • L Lost User

          Vaclav_Sal wrote:

          In my view it prepends the working source file

          But that is perfectly acceptable as long as all required include files are added within that cpp file. It is just the same as adding some extra functions at the top of a source file before the #include statements required by the remainder of the source.

          V Offline
          V Offline
          Vaclav_
          wrote on last edited by
          #4

          So are the include cpp functions global only to the attched cpp which is basically an object / class? Is that the reason I was getting multiple definitions when I included it in StdAfx header? I did not try to access the preprocessed functions outside the class. It should not work. Actually found that I was telling the DirectShow to add another filter and had no intermediate filter / pins to connect to. Fixed that so I do not need to do the connections manually.

          L L 2 Replies Last reply
          0
          • V Vaclav_

            So are the include cpp functions global only to the attched cpp which is basically an object / class? Is that the reason I was getting multiple definitions when I included it in StdAfx header? I did not try to access the preprocessed functions outside the class. It should not work. Actually found that I was telling the DirectShow to add another filter and had no intermediate filter / pins to connect to. Fixed that so I do not need to do the connections manually.

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Without seeing all the code in the included file it is impossible to answer that.

            1 Reply Last reply
            0
            • V Vaclav_

              So are the include cpp functions global only to the attched cpp which is basically an object / class? Is that the reason I was getting multiple definitions when I included it in StdAfx header? I did not try to access the preprocessed functions outside the class. It should not work. Actually found that I was telling the DirectShow to add another filter and had no intermediate filter / pins to connect to. Fixed that so I do not need to do the connections manually.

              L Offline
              L Offline
              leon de boer
              wrote on last edited by
              #6

              You are spot on Val you will get multiple inclusions if the file is multiple included, unless the file contains standard one time load #ifdef protection around the top and bottom If the programmer knew what they were doing they would have something that looks like this top/bottom of include file // PROTECTION TO STOP MULTIPLE UNIT LOADING #ifndef _FILENAME_ID_ #define _FILENAME_ID_ #endif It is still quite common in a very specific circumstance .. can you think what it might be :) I will give you a hint: I know the old version of windows.h from Microsoft did it but they changed it all a few years ago when they broke that unit up. You will probably also find it on the android source unless they worked there way around it.

              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