GetAdaptersInfo gives link error

plq
plq used Ask the Experts™
on
Hi folks. IPHlpApi is a lib and .h file in the SDKs and I'm trying to call it from MSVC6.

I get this: unresolved external symbol "unsigned long __stdcall GetAdaptersInfo(struct _IP_ADAPTER_INFO *,unsigned long *)" (?GetAdaptersInfo@@YGKPAU_IP_ADAPTER_INFO@@PAK@Z)

I had to take out the iphldapi.h header file because it contains all sorts of MS.net compiler specific stuff which doesnt work in msvc6, so I declared it all myself...

#define __allowed(p)
#define __out_bcount_opt(size)                        __allowed(on_parameter)
#define __inout                                       __allowed(on_parameter)

ULONG
WINAPI
GetAdaptersInfo(
    __out_bcount_opt(*SizePointer)  PIP_ADAPTER_INFO AdapterInfo,
    __inout                         PULONG           SizePointer
    );

And I'm sure thats the problem, but I'm not sure how to fix it !!

I did add iphlpapi.lib to the list of linker libs, and I've ensured that the path to the lib is in the paths in tools>options.

This seems to work fine in later compilers, but I really need it to work in msvc6.

thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2012
Commented:
Are you linking with IPHLPAPI.lib? Anyway, since you extracted the declaration, be sure to also add

#ifdef __cplusplus
extern "C" { // <--------------------!
#endif
ULONG
WINAPI
GetAdaptersInfo(
    __out_bcount_opt(*SizePointer)  PIP_ADAPTER_INFO AdapterInfo,
    __inout                         PULONG           SizePointer
    );
#ifdef __cplusplus
} // <--------------
#endif

to turn off C++ name mangling for that function
plq

Author

Commented:
Well gosh jkr that seems to have fixed it. Is this a new EE record ? Let me just sanity check first...
plq

Author

Commented:
It was the extern "C" thing that fixed it. I would never have got that in a million years.. thanks again jkr
jkr
Top Expert 2012

Commented:
>>Is this a new EE record ?

AFAIK the Q the quickest answer ever on EE took ~20s, so this one is not even a close runner up ;o)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial