Thread: Externally included file and project level #define?

  1. #1
    Registered User
    Join Date
    Jun 2007
    Posts
    41

    Externally included file and project level #define?

    Don't know exactly which forum to post this in... anways below is my problem:

    1) I have a project. (obviously)
    2) In this project I have a "Resource.h" that has a series of #defines
    3) I include a header & cpp from a completely different directory and in these files they need to know about some of the #define(s) in the project's "Resource.h".

    Problem is when I try and compile/build the sucker it complains about "error C2065: 'IDD_CONTROL': undeclared identifier (for the externally included header & cpp). I know there is a way to get this to work without having to include the "Resource.h" as I've seen a project do it, but even staring at it for 30 minutes comparing settings I can't figure out what they are doing that I'm not.

    Specifically including in the external header:

    #include "..\project folder\project\Resource.h" <-- this works, but this external header & cpp are shared among multiple projects so I don't want to do that.

    Any ideas? I'm using Visual Studio's IDE.

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    All source files that require certain declarations/definitions and/or macros should include appropriate header files.
    In case it's too long for you to type, then look in your project properties for additional include paths.
    Then you can just do #include <resource.h>

    Never include a .cpp file anywhere.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    This sounds like an MFC question based on the IDD_ identifier and Resource.h. Resource.h is the proper place for the define to reside. If you try to fight where the Visual Studio GUI editor places the resources you will be in for a very long day.
    Just let it do what it wants and you should be ok.

  4. #4
    Registered User
    Join Date
    Jun 2007
    Posts
    41

    Question

    Yes it is indeed MFC related, but I was trying to be vague to protect myself from the "THIS IS NOT A MFC FORUM" or "eww MFC" crowd, but I guess I might as well post my problem in more detail in hopes of a EUREKA moment.

    1) I have a dialog that I would like to include in multiple projects.
    2) This dialog obviously consists of a header & a .cpp implementing the dialog.
    3) Rather than make copies of this implementation and include them in the multiple projects I want to put the implementation for the dialog in a neutral common folder unrelated to any project and include/add them to both projects.

    Now, the dialog resource itself will be duped (no getting around that) it will have to be in both project's "Resource.h" & "Resource.rc" file (all the defines for the controls, the dialog, etc), but I don't consider this a big deal as the dialog will never change (buttons, controls, etc all will remain the same).

    However, the implementation of the dialog will change, thus the desire to have it shared between projects so as to only have to modify it once. The problem is the dialog's implementation files need the #defines in the project's "Resource.h" to which it is being used in. The way I am doing it now is:

    Code:
    (in the shared dialogs header)
    #ifdef PROJECT_1
    #include "..\..\Project1\Resource.h"
    #elif PROJECT_2
    #include "..\..\Project2\Resource.h"
    #endif
    
    class MyDialog : public CDialog{
    enum {IDD = IDD_DIALOG}; <-- IDD_DIALOG defined projects in Resource.h.
    };
    This works, but what bothers me is I have someone else's project that faces the exact same thing I'm trying to do (include a neutral dialog's implementation), but unlike mine theirs doesn't complain about undefined #define variables and compiles/builds/and runs. In their files they make no reference to a "Resource.h" anywhere and doesn't include a header that somewhere down the line includes a "Resource.h" or any file specifying these required defines...nowhere! And their project settings are identical to mine... it has me slightly baffled as to why their project compiles (and recognizes the defines in the Resource.h) while mine doesn't. Anyone have an idea?

    P.S. I would share the project that actually compiles and mine that doesn't, but they are huge and rather confidential...

    Code:
    (Example of their shared dialog's header)
    
    // They aren't including any "Resource.h" here.. no headers that ever reference a "Resource.h" or any file that #define IDD_DIALOG yet their project builds fine..
    
     class MyDialog : public CDialog{
    enum {IDD = IDD_DIALOG}; <-- IDD_DIALOG defined in projects Resource.h.
    };
    Last edited by HyperShadow; 05-15-2008 at 10:26 PM.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Resource.h must get included somewhere. Where doesn't matter, so long as it's available in the source using the define.
    Anyhow, what you do is add the source file to the project, create a resource.h in your folder where the source is, which contains the define.
    If you'd like to share the dialog resource, as well, then cut out the dialog code from the .rc and put it in a header and include it from the .rc file. Not tested, but it should work.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help me with function call
    By NeMewSys in forum C++ Programming
    Replies: 16
    Last Post: 05-22-2008, 01:53 PM
  2. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  3. NAQ: Everything you never wanted to know about CPP
    By evildave in forum C Programming
    Replies: 21
    Last Post: 12-12-2005, 10:56 AM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM