?
Solved

static library imports static library

Posted on 2003-02-24
9
Medium Priority
?
1,190 Views
Last Modified: 2013-12-14
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
Comment
Question by:YnoC
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 1

Expert Comment

by:codez80
ID: 8007865
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
 

Author Comment

by:YnoC
ID: 8008057
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
 
LVL 1

Expert Comment

by:codez80
ID: 8008201
you have not defined:
void cNetInfo::AdaptersInfo(void)
{
}

in your cpp file!

check again,

codez80
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:YnoC
ID: 8009513
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
 
LVL 1

Expert Comment

by:codez80
ID: 8009586
GOT IT!!!

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

good luck

codez80
0
 

Author Comment

by:YnoC
ID: 8010128
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
 

Author Comment

by:YnoC
ID: 8010229
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
 
LVL 1

Accepted Solution

by:
codez80 earned 200 total points
ID: 8010429
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
 

Author Comment

by:YnoC
ID: 8010627
i added all the other 2 libraries - the iphlpapi.lib not

sometimes you don't see the obvious.

thank you
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question