when linked with IHhlpapi.lib, get unknown _GetAdaterAddressess()error

K

K.Gnanaratne

Hi:
I am trying to use the example in MSDN library. I wrote the following
class to compile with other source files to generate an executable.
But always get link error saying that _GetAdapatersAddresses() function
is missing. How can I remove this error and build an executable. I am
using .NET 2003 c++ compiler.

Below I have listed file content, linker options and error output.
Thanks in advance

K. Gnanaratne

--- *.h file ---
#include <Windows.h>
#include <Winsock2.h>
#include <Iphlpapi.h>
#include <Iptypes.h>
#include <iostream>
using namespace std;

class IPhwAdapter
{
Public:
IPhwAdapter(void);
~IPhwAdapter(void);
int getHwInfo( void );
private:
IP_ADAPTER_INFO *m_hwInfoBufp;
};

--- *.cpp file ---
include "StdAfx.h"
#include ".\iphwadapter.h"

IPhwAdapter::IPhwAdapter(void):
m_hwInfoBufp(0)
{
}

IPhwAdapter::~IPhwAdapter(void)
{
delete m_hwInfoBufp;
}

int
IPhwAdapter::getHwInfo( )
{
unsigned long bufLen;
size_t blkCnt;
// allocate memory
if ( (m_hwInfoBufp = new IP_ADAPTER_ADDRESSES) == NULL ) {
cout << "IPBHipIntf::getHwInfo(): cannot allocate memory" << endl;
return -1;
}
bufLen = sizeof(IP_ADAPTER_ADDRESSES);
if ( ::GetAdaptersAddresses( AF_INET, 0, NULL, m_hwInfoBufp, &bufLen )
!= ERROR_SUCCESS ) {
delete m_hwInfoBufp;
m_hwInfoBufp = 0;
return -1;
}

return 0;
}
---linker option ----

VERBOSE /OUT:"Debug/ipHwIntf.exe" /INCREMENTAL /NOLOGO /DEBUG
/PDB:"Debug/ipHwIntf.pdb" /SUBSYSTEM:WINDOWS
/IMPLIB:"Iphlpapi.lib,ws2_32.lib" /MACHINE:X86
..\Debug\IpbhSckt.obj
..\Debug\IPhwAdapter.obj
..\Debug\ipHwIntf.obj
..\Debug\ipHwIntfDlg.obj
..\Debug\myMfcClass.obj
..\Debug\stdafx.obj
..\Debug\ipHwIntf.res
]
Creating command line "link.exe @c:\cppwork\ipHwIntf\Debug\RSP00000C.rsp"


--- ERROR GENERATED ----
PhwAdapter.obj : error LNK2019: unresolved external symbol
_GetAdaptersAddresses@20 referenced in function "public: int __thiscall
IPhwAdapter::getHwInfo(void)" (?getHwInfo@IPhwAdapter@@QAEHXZ)
Debug/ipHwIntf.exe : fatal error LNK1120: 1 unresolved externals
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top