Thread: Including from C

  1. #1
    Registered User
    Join Date
    Apr 2015
    Posts
    10

    Including from C

    Hi,

    Im currently working on rebuilding a old game which I have the source code for, but Im getting errors.

    These are the errors:

    Code:
    netinfo.c<149> Undeclared name ntInfGetNetworkInfo 
    net.cpp<326>  Ambigious overloaded function call 
    net.cpp<330> Undeclared name ntInfGetNetworkInfo 
    net.cpp<348> Ambigious overloaded function call 
    net.cpp<349> Ambigious overloaded function call
    I have copied out some of the code because of the size of these files.

    however, I have marked the line numbers giving errors.

    There were more errors but these have been sorted out.

    Whole Netinfo.c:

    Code:
    #include "netinfo.h"
    #include <string.h>
    
    
    #define PACKET_SIZE         60
    
    
    #define    NETINFUS_START    128
    
    
    #define    PRIVATE static
    
    
    /*
     *  Version string
     */
    const char * const ntgInfUSBuild =   "\nntInfUS Ver 1.00 Build:" __DATE__ " " __TIME__ "\n";
    
    
    static const char* PLANET_WEB_SIGNATURE = "PWBrowser";
    
    
    PRIVATE bool
    wait_flash(void)
    {
        Sint32 err;
    
    
        while (true){
            err = fmMngExecServer();
            if (err == FMD_STAT_ERR)
                return false;
            if (err == FMD_STAT_COMPLETE)
                return true;
        }
    }
    
    
    PRIVATE Sint32 
    read_NetInfUS(NetInfUS *inf)
    {
       int size; 
       int num_blocks;
       int remainder;
       int block;
       Sint32 status;
       char buffer[PACKET_SIZE];
    
    
       size = sizeof(NetInfUS);
       num_blocks = size/PACKET_SIZE;
       remainder = size % PACKET_SIZE;
       if (remainder != 0) {
          num_blocks++;
       }
    
    
       for (block = 0; block < num_blocks; block++) {
          status = fmMngRead(NETINFUS_START + block, buffer);
    
    
            if (!wait_flash())
                return FMD_STAT_ERR;
    
    
          if ( block == num_blocks - 1) {
             /* Last block */
             memcpy((char*)inf + (block*PACKET_SIZE), buffer, remainder);
    
    
          } else {
             memcpy((char*)inf + (block*PACKET_SIZE), buffer, PACKET_SIZE);
    
    
          }
       }
    
    
        return FMD_OK;
    }
    
    
    Sint32 
    ntInfUSGetNetInfUS(NetInfUS *inf)
    {
        Sint32 rc;
    
    
        rc = read_NetInfUS(inf);
    
    
        if (rc != FMD_OK) {
            return (NTD_ERR_NOINFO);
    
    
       } else {
            return (NTD_OK);
       }
    }
    
    
    
    
    void copyPhoneNumber(const char* isp_number, const NetInfUS* net_info_us, char* buffer) {
       const char* area_code_start;
       const char* area_code_end;
       int   area_code_length;
       const char* phone_start;
       Bool  use_area_code;
    
    
       if (buffer == NULL || isp_number == NULL) {
          return;
       }
    
    
       if (strlen(isp_number) == 0) {
          buffer[0] = '\0';
          return;
       }
    
    
       area_code_start = strchr(isp_number, '(');
       if (area_code_start != NULL) {
          area_code_end   = strchr(area_code_start, ')');
       } else {
          area_code_end = NULL;
       }
    
    
       if (area_code_end != NULL) {
          area_code_end++;
          phone_start = area_code_end;
       } else {
          phone_start = isp_number;
          area_code_start = NULL;
       }
    
    
       area_code_length = area_code_end - area_code_start;
    
    
       use_area_code =  ( area_code_start != NULL && 
                          ( strncmp((char*)net_info_us->areaCode, area_code_start+1, area_code_length-2) != 0 || net_info_us->dialArea )
                        );
    
    
       strcpy(buffer, (char*)net_info_us->callWait);
    
    
    
    
       strcat(buffer, (char*)net_info_us->outLine);
    
    
       if (use_area_code) {
    
    
          strcat(buffer, (char*)net_info_us->longDst);
    
    
          strncat(buffer, area_code_start, area_code_length);
       }
    
    
       strcat(buffer, phone_start);
    }
    
    
    void CheckNetInfUSData(NetInfUS *usinf);
    
    
    Sint32
    ntInfUSGetPhoneNumber(char *num1, char *num2, char *num3)
    {
        Sint32 rc;
        NetworkInfo *netinfo;
        NetworkAccessInfo *isp;
        NetInfUS usinf;
    
    
        rc = ntInfInit(NULL, NULL);
        if (rc != NTD_OK)
            return (rc);
    
    
    149:    rc = ntInfGetNetworkInfo(&netinfo);
        if (rc != NTD_OK)
        {
            ntInfExit();
            return (rc);
        }
    
    
        if (((netinfo->flag)&ISP_USE2) == ISP_USE2)
            isp = &(netinfo->isp_info2);
        else
            isp = &(netinfo->isp_info1);
    
    
        rc = ntInfUSGetNetInfUS(&usinf);
        if (rc != FMD_OK)
        {
            ntInfExit();
            return (NTD_ERR_NOINFO);
        }
    
    
        CheckNetInfUSData(&usinf);
    
    
        copyPhoneNumber((char*)isp->accessPointNumber[0], &usinf, num1);
        copyPhoneNumber((char*)isp->accessPointNumber[1], &usinf, num2);
        copyPhoneNumber((char*)isp->accessPointNumber[2], &usinf, num3);
    
    
        ntInfExit();
    
    
        return (NTD_OK);
    }
    From net.cpp:

    Code:
    extern "C" 
        {
        #include <netinfo.c>
        }
    
    ..lots of other stuff
    
    
    int NetworkClass::MakeNetworkInformation()
        {
    
    
        NetworkInfo            *netinfoptr;
        NetworkAccessInfo    *ispinfoptr;
        NetInfUS            netinfous;
        int                    retval = FALSE;
    
    
        
        strcpy(net_info.HostName,    "somegameserver");
    
    
       
    326:    init_error = ntInfInit(&gNetInfo, &gNetInfoWork);
    
        if (init_error == NTD_OK)
            {
    330:        init_error = ntInfGetNetworkInfo(&netinfoptr);
            if (init_error == NTD_OK) 
                {
                
                ntInfGetNetworkAccessInfo(ISP_NUM, &ispinfoptr);
                init_error = ntInfUSGetNetInfUS(&netinfous);
                if (init_error == NTD_OK)
                    {
                    unsigned char login_id[64];
                    unsigned char password[64];
                    for (int i = 0; i < 64; i++) {
                        login_id[i] = 0;
                        password[i] = 0;
                    }
                    if (netinfoptr->flag & DIAL_PULSE)
                        net_info.DialTone = 1;
                    else
                        net_info.DialTone = 0;
    348:                ntInfGetLoginId(ISP_NUM, login_id);
    349:                ntInfGetLoginPasswd(ISP_NUM, password);
    //                strcpy(net_info.LoginName,    (char*)ispinfoptr->loginId);
    //                strcpy(net_info.PassWord,    (char*)ispinfoptr->loginPasswd);
                    strcpy(net_info.LoginName,    (char*)login_id);
                    strcpy(net_info.PassWord,    (char*)password);
                    
                    char buf1[64],buf2[64];
                    ntInfUSGetPhoneNumber((char*)net_info.TelPhone, buf1, buf2);
                    retval = TRUE;
                    
                    CheckNetInfUSData(&netinfous);
                    strcpy( base_phone_info.outLine,    (char*)netinfous.outLine );
                    strcpy( base_phone_info.callWait,    (char*)netinfous.callWait );
                    strcpy( base_phone_info.areaCode,    (char*)netinfous.areaCode );
                    strcpy( base_phone_info.longDst,    (char*)netinfous.longDst );
                    strcpy( base_phone_info.number,        (char*)ispinfoptr->accessPointNumber[0] );
                    }
                }
            }
    
    
        ntInfExit();
    
    
        return retval;
        }
    Last edited by petterk; 08-05-2015 at 10:18 AM.

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Error 1 & 3: The function wasn't declared. Ensure that you include the appropriate header where the function is declared, of if one such does not exist, create one and include it.
    For the rest of the errors, it basically says that there are two or more functions with the same name and the compiler can't figure out which one to call. Post all prototypes for those functions.
    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
    Join Date
    Apr 2015
    Posts
    10
    Quote Originally Posted by Elysia View Post
    Post all prototypes for those functions.
    from nt_utl.h:

    Code:
    /* ntInf */
    Sint32 ntInfInit(void *pNetInfo, void *pWork);
    #ifdef OLD_NTINF
    Sint32 ntInfGetNetworkInfo(NetworkInfo **ppNetInfo);
    #endif
    Sint32 ntInfGetLoginId(Sint32 isp, Uint8 *pLoginId);
    Sint32 ntInfGetLoginPasswd(Sint32 isp, Uint8 *pLoginPasswd);
    This and the 2 files posted in the first post is the only references to those functions that I have in the source tarball.

    from net.cpp again:

    Code:
    #define OLD_NTINF
    #include <nt_utl.h>
    Last edited by petterk; 08-05-2015 at 11:46 AM.

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Please explain this code.

    Code:
    extern "C" 
        {
        #include <netinfo.c>
        }
    Including an source file (that is NOT a header file) is normally wrong!

    Edit: You likely want this instead
    Code:
    extern "C" 
        {
        #include "netinfo.h"
        }
    Tim S.
    Last edited by stahta01; 08-07-2015 at 09:53 PM.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  5. #5
    Registered User
    Join Date
    Apr 2015
    Posts
    10
    Thanks alot for your replies guys. I havent gotten around to testing this out yet (netinfo.h), but I did wonder why they'd include the .c file myself.
    This is the source code for a game supposedly in its complete state, and the only errors I get are the ones posted, but its possible the developers of the game left some typos in the source files.

    I remember trying to include the netinfo.h header file aswell as the .c file with the same results, however.

    Gonna give this a try tonight.

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Don't include the .c file. Compile it separately.
    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. Including GDI
    By JMK in forum C++ Programming
    Replies: 7
    Last Post: 09-01-2010, 02:16 PM
  2. Including DLL's
    By stickman in forum C++ Programming
    Replies: 29
    Last Post: 04-10-2006, 11:34 PM
  3. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  4. Including
    By gvector1 in forum C++ Programming
    Replies: 2
    Last Post: 02-20-2003, 09:13 AM