Thread: need help with handelling multiple source files

  1. #16
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    So what do your files look like now, and what errors are you getting?
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  2. #17
    Registered User
    Join Date
    Apr 2006
    Posts
    49
    no errors, it compiles and runs, but it doesnt show the colors, it seems like it thinks the functions are void when they shouldnt be.


    main.cpp:

    Code:
    #include "global.h"
    #include "color.h"
    color.hno includes)

    Code:
    // INTERFACE FUNCTIONS:
    // font colors>>
    
    void tred();
    void tgreen();
    void tblue();
    void tmagenta();
    void tteal();
    void ttan();
    void tdefault();
    void tred_i();
    void tgreen_i();
    void tblue_i();
    void tmagenta_i();
    void tteal_i();
    void ttan_i();
    void tdefault_i();
    
    // background colors:
    
    void bred();
    void bgreen();
    void bblue();
    void bmagenta();
    void bteal();
    void btan();
    void bdefault();
    void bred_i();
    void bgreen_i();
    void bblue_i();
    void bmagenta_i();
    void bteal_i();
    void btan_i();
    void bdefault_i();
    void face_intro();
    void face_darktech();
    void face_menu_titlebar();
    void cosmos_logo();
    void dark_logo();
    void light_side();
    void red_i();
    void green_i();
    void blue_white();
    void teal_white();
    void blue_grey();
    colorIt.cpp:

    Code:
    #include "color.h"
    
    #define _WIN32_WINNT WINVER
    
    #ifdef WIN32
    #endif
    
    // INTERFACE FUNCTIONS:
    // font colors>>
    
    void tred()
    {
    	#ifdef WIN32
    		HANDLE hstdo;
    		hstdo = GetStdHandle(STD_OUTPUT_HANDLE);
    		SetConsoleTextAttribute(hstdo, FOREGROUND_RED);
    	#endif   
    }
    
    // ect.. other color functions like tred()

  3. #18
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Did you add WIN32 to your preprocessor definitions? From your previous post, it sounds like WIN32 is not defined.
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  4. #19
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Maybe you ought to change the order of #includes to match how it was previously, if that has changed. Like maybe "color.h" needs to see _WIN32_WINNT.
    Code:
    #include "color.h"
    
    #define _WIN32_WINNT WINVER
    What the little #else #error test showed you is that you are compiling nothing right now. Before may have been great, but you may have inadvertently changed the magic order.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  5. #20
    Registered User
    Join Date
    Apr 2006
    Posts
    49
    well i defined something in colorIt.cpp, that is about WIN32. Its actually also defined in main.cpp also. But what do you mean by defining it as a predepressor? It has worked before, but only when it was in the main.cpp file.

  6. #21
    Registered User
    Join Date
    Apr 2006
    Posts
    49
    I just tryed putting color.h below and it still does not show color. Oh im really sorry for all hte trouble im causing.

  7. #22
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    >>well i defined something in colorIt.cpp, that is about WIN32.

    "something" isn't good enough. You need to define WIN32 if you want that code between #ifdef WIN32 and #endif to run. Ideally, you should use a preprocessor option passed to the compiler, but if you just put #define WIN32 at the top of your files (or in files included) it should work.
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  8. #23
    Registered User
    Join Date
    Apr 2006
    Posts
    49
    But if I put #define WIN32 in the C/C++ compiler properties under predpresser, it will give me infinite errors, like it doesnt know any of my variables when I do that.

    I even tryed it the other way, but putting
    #define WIN32 at the VERY top of every file, and same result

  9. #24
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Quote Originally Posted by DarkMortar
    But if I put #define WIN32 in the C/C++ compiler properties under predpresser, it will give me infinite errors, like it doesnt know any of my variables when I do that.
    Investigate how you are supposed to use a #define for the IDE?

    What variables? You haven't show us any yet.
    Quote Originally Posted by DarkMortar
    I even tryed it the other way, but putting
    #define WIN32 at the VERY top of every file, and same result
    We can't read your computer screen, perhaps you could share the mystery with us... or wait until our crystal balls get back from cleaing.

    Do you still get the #error statement even with this attempt?
    Last edited by Dave_Sinkula; 05-25-2006 at 10:25 PM.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  10. #25
    Registered User
    Join Date
    Apr 2006
    Posts
    49
    Ok this time, I properly defined WIN32 in the predepresser and it compiles and runs now. Nothing else was changed. BUT it STILL doesnt show the colors like it should.

    BUT: the #error in blue_grey() function generates an error in the compile when I add this:

    Code:
    #else
    #error !WIN32
    ERROR:
    1>.\colorIt.cpp(366) : fatal error C1189: #error : !WIN32

    So now you know that information, now what?

  11. #26
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Quote Originally Posted by DarkMortar
    BUT: the #error in blue_grey() function generates an error in the compile when I add this:

    Code:
    #else
    #error !WIN32
    ERROR:
    1>.\colorIt.cpp(366) : fatal error C1189: #error : !WIN32

    So now you know that information, now what?
    As you can see, for the functions you want to show color, you are in fact compiling no code to change the color. So how could it run with the latest changes?

    [edit]'predepresser' - funny.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  12. #27
    Registered User
    Join Date
    Apr 2006
    Posts
    49
    but dood, when I even left out the #error statements in the color functions, it compiled but didnt show the color! hmm?

  13. #28
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Quote Originally Posted by DarkMortar
    but dood, when I even left out the #error statements in the color functions, it compiled but didnt show the color! hmm?
    Don't take it out. That's what tells you when you are doing it right or not.
    Code:
    #include <stdio.h>
    
    int main(void)
    {
    #define MACRO
    #ifdef MACRO
       puts("MACRO is defined");
    #else
       puts("MACRO is NOT defined");
    #endif
    
    #undef MACRO
    #ifdef MACRO
       puts("MACRO is defined");
    #else
       puts("MACRO is NOT defined");
    #endif
       return 0;
    }
    
    /* my output
    MACRO is defined
    MACRO is NOT defined
    */
    When you are doing it right, the message will go away.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  14. #29
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    Example!
    Code:
    #include <iostream>
    
    #define X1
    
    #ifdef X1
    void x1()
    {
        std::cout<<"HI!!!!!";
    }
    #endif
    
    #ifdef X2
    //This functon does not get called!
    void x1()
    {
        std::cout<<"Hello!!!!!!!";
    }
    #endif
    
    int main()
    {
        x1();
        std::cin.get();
    }
    Code:
    #include <iostream>
    
    #define X2
    
    #ifdef X1
    //This functon does not get called!
    void x1()
    {
        std::cout<<"HI!!!!!";
    }
    #endif
    
    #ifdef X2
    
    void x1()
    {
        std::cout<<"Hello!!!!!!!";
    }
    #endif
    
    int main()
    {
        x1();
        std::cin.get();
    }
    Woop?

  15. #30
    Registered User
    Join Date
    Apr 2006
    Posts
    49
    Ok that does make sense to me now, but I put #define WIN32 at the top and it gives me errors in the functions like this:

    Code:
    1>.\colorIt.cpp(235) : error C3861: 'SetConsoleTextAttribute': identifier not found
    1>.\colorIt.cpp(242) : error C2146: syntax error : missing ';' before identifier 'hstdo'
    1>.\colorIt.cpp(243) : error C3861: 'GetStdHandle': identifier not found
    1>.\colorIt.cpp(244) : error C3861: 'SetConsoleTextAttribute': identifier not found
    1>.\colorIt.cpp(251) : error C2146: syntax error : missing ';' before identifier 'hstdo'
    1>.\colorIt.cpp(252) : error C3861: 'GetStdHandle': identifier not found
    1>.\colorIt.cpp(253) : error C3861: 'SetConsoleTextAttribute': identifier not found
    1>.\colorIt.cpp(260) : error C2146: syntax error : missing ';' before identifier 'hstdo'
    1>.\colorIt.cpp(261) : error C3861: 'GetStdHandle': identifier not found
    1>.\colorIt.cpp(262) : error C3861: 'SetConsoleTextAttribute': identifier not found
    1>.\colorIt.cpp(271) : error C2146: syntax error : missing ';' before identifier 'hstdo'
    1>.\colorIt.cpp(272) : error C3861: 'GetStdHandle': identifier not found
    1>.\colorIt.cpp(273) : error C3861: 'SetConsoleTextAttribute': identifier not found
    1>.\colorIt.cpp(280) : error C2146: syntax error : missing ';' before identifier 'hstdo'
    1>.\colorIt.cpp(281) : error C3861: 'GetStdHandle': identifier not found
    1>.\colorIt.cpp(282) : error C3861: 'SetConsoleTextAttribute': identifier not found
    1>.\colorIt.cpp(282) : fatal error C1003: error count exceeds 100; stopping compilation

    ect...

    What the file looks like:

    Code:
    #define WIN32
    #define _WIN32_WINNT WINVER
    
    #include "color.h"
    
    #ifdef WIN32
    #endif
    
    // INTERFACE FUNCTIONS:
    // font colors>>
    
    void tred()
    {
    	#ifdef WIN32
    		HANDLE hstdo;
    		hstdo = GetStdHandle(STD_OUTPUT_HANDLE);
    		SetConsoleTextAttribute(hstdo, FOREGROUND_RED);
    	#endif   
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multiple source files in one project
    By mintsmike in forum C++ Programming
    Replies: 8
    Last Post: 06-27-2009, 07:20 AM
  2. Confusion on header and source files
    By dnguyen1022 in forum C++ Programming
    Replies: 4
    Last Post: 01-17-2009, 03:42 AM
  3. multiple source files
    By AmazingRando in forum C Programming
    Replies: 6
    Last Post: 03-13-2005, 03:39 PM
  4. Multiple Source Files!?!?
    By Padawan in forum C Programming
    Replies: 14
    Last Post: 04-04-2004, 12:19 AM
  5. Linking multiple source files: Undefiled Reference to...
    By Inquirer in forum C++ Programming
    Replies: 4
    Last Post: 05-03-2003, 05:47 PM