Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1199
  • Last Modified:

static library imports static library

Hi,

I created a static library looking like this

#pragma once

#include "wininet.h"
#include "iphlpapi.h"
#include "ras.h"

class cNetInfo
{
public:
     cNetInfo(void);
     ~cNetInfo(void);

     bool IsConnected();
     bool IsLANConnected();

     int GetNumberOfAdapters(void);
     int GetNumberOfHWInterfaces(void);
     CString GetAdapterType(int nAdapter);
     CString GetAdapterIPAdress(int nAdapter);
     
     int GetInterfaceNumber(int nInterface);
     int GetInterfaceType(int nInterface);
     CString GetInterfaceName(int nInterface);

     unsigned long GetInterfaceDownUtilization(int nInterface);

private:
     char* pszAIBuffer; //AdapterInfoBuffer
     char* pszIFTBuffer; //IFTable Buffer
     PIP_ADAPTER_INFO pAdapterInfo; //enthält ALLE Adapter mit Name, Type, IP, Subnet, Gateway...
     PMIB_IFTABLE pIFTable;
     PMIB_IFROW pIFRow;
     unsigned long nBuffSize;

     void AdaptersInfo(void);
     void IFTableInfo(void);

     bool GetInterfaceInformation(int nInterface);

     struct InterfaceInfoEx
     {
          int nNumber;
          int nType;
          char* szName;
          int nNameLen;
          unsigned long nSpeed;
          unsigned long BytesReceived;
          unsigned long BytesSent;

     }InterfaceInfo;

};

the only problem now is, that I get this error:
netspeed error LNK2019: unresolved external symbol _GetAdaptersInfo@8 referenced in function "private: void __thiscall cNetInfo::AdaptersInfo(void)" (?AdaptersInfo@cNetInfo@@AAEXXZ)

when I try "cNetInfo cNi;" in my main-prog.

The function AdaptersInfo() is called by the Constructor

void cNetInfo::AdaptersInfo(void)
{
     unsigned long nRetCode = -1;

     nRetCode = GetAdaptersInfo(pAdapterInfo,&nBuffSize);
     while (nRetCode != NO_ERROR)
     {
          pszAIBuffer = new char[nBuffSize];
          pAdapterInfo = (PIP_ADAPTER_INFO)pszAIBuffer;
          nRetCode = GetAdaptersInfo(pAdapterInfo,&nBuffSize);
          delete [] pszAIBuffer;
     }
     
     nBuffSize = 0;
}

The Problem is the GetAdaptersInfo(pAdapter....) call.

Plz help
0
YnoC
Asked:
YnoC
  • 5
  • 4
1 Solution
 
codez80Commented:
ok,

first things first,
are u linking your app (or DLL) to that library (.lib file)?

second:
make sure that you have implemented that function in a cpp file.


codez80
0
 
YnoCAuthor Commented:
I added the .lib to the main-app-project, sorry 4 holding back that information :)
Then I added the .h to my project.

The function is implemented in a cpp file.
The Class itself compiles without error.

in the main-app-project i try to initialize the class using this code

cNetInfo* cNI = new cNetInfo();
0
 
codez80Commented:
you have not defined:
void cNetInfo::AdaptersInfo(void)
{
}

in your cpp file!

check again,

codez80
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
YnoCAuthor Commented:
void cNetInfo::AdaptersInfo(void)
{
    unsigned long nRetCode = -1;

    nRetCode = GetAdaptersInfo(pAdapterInfo,&nBuffSize);
    while (nRetCode != NO_ERROR)
    {
         pszAIBuffer = new char[nBuffSize];
         pAdapterInfo = (PIP_ADAPTER_INFO)pszAIBuffer;
         nRetCode = GetAdaptersInfo(pAdapterInfo,&nBuffSize);
         delete [] pszAIBuffer;
    }
   
    nBuffSize = 0;
}

thats the definition... It is defined.
0
 
codez80Commented:
GOT IT!!!

u need to link your application or dll (not the static library) to "Iphlpapi.lib".

good luck

codez80
0
 
YnoCAuthor Commented:
I tried it before.

Do you mean I should add the include "iphlpapi.h" to the main-prog or my cNetInfo class?
The cNetInfo Class already includes the iphlpapi.h
0
 
YnoCAuthor Commented:
I tried it before.

Do you mean I should add the include "iphlpapi.h" to the main-prog or my cNetInfo class?
The cNetInfo Class already includes the iphlpapi.h
0
 
codez80Commented:
no, you need to link to the import library
"iphlpapi.lib" (look at the extension)

if you are using VC++ go to link tab and add the library to the objects/modules list,

if not choose a cpp file and add this to it (make sure you do this to a cpp file)
#pragma comment(linker, "iphlpapi.lib")

codez80

0
 
YnoCAuthor Commented:
i added all the other 2 libraries - the iphlpapi.lib not

sometimes you don't see the obvious.

thank you
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now