Jump to content

VC++ compiling as DLL

Go to solution Solved by WanderingFool,

Oh sorry, I didn't read the error close enough.

"error LNK2019: unresolved external symbol _GetIfEntry@4 "

 

So the problem is this line

::GetIfEntry(&mi);

 

Sorry I have never really used that in dll's before, so I don't really know which libraries it is in.  Essentially though it can't find the lib file that contains GetIfEntry

According to MSDN it looks like you want to include Iphlpapi.lib

(Link: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365939%28v=vs.85%29.aspx look for the requirements section)

I've been creating a program, and I would like some of the features to be separate in a DLL. I have followed the steps on the microsoft guide and this guide I found on codeproject (the codeproject one is much more in depth!). However, when I compile it I get LNK2019 and LNK1120 errors - unresolved external symbols.

The code for the .cpp file is currently:

#include "stdafx.h"#include <Windows.h>#include <ifmib.h>#include <IPHlpApi.h>#include "SystemUtilisation.h"DWORD systemUtilisation::GetReceivedBytes(DWORD adapterIndex){	MIB_IFROW mi;	mi.dwIndex=adapterIndex;	::GetIfEntry(&mi);	return mi.dwInOctets;}

and the .h file (SystemUtilisation.h) is:

#pragma once //This makes no difference#ifdef SYSTEM_UTILISATION_EXPORTS#define SYSTEMUTILISATION_API __declspec(dllexport)#else#define SYSTEMUTILISATION_API __declspec(dllimport)#endif#include <Windows.h>#ifdef __cplusplus //This makes no difference, I was trying it to see whether it would helpextern "C" {#endifclass SYSTEMUTILISATION_API systemUtilisation{public:	static DWORD GetReceivedBytes(DWORD);};#ifdef __cplusplus}#endif

I am compiling with Visual Studio 2012 express, and the errors are:

Error	1	error LNK2019: unresolved external symbol _GetIfEntry@4 referenced in function "public: static unsigned long __cdecl systemUtilisation::GetReceivedBytes(unsigned long)" (?GetReceivedBytes@systemUtilisation@@[member=sakketheengineer]@Z)	A:\Users\My user name\Documents\Visual Studio 2012\Projects\ShutdownScheduler\SystemUtilisation\SystemUtilisation.obj	SystemUtilisationError	2	error LNK1120: 1 unresolved externals	A:\Users\My user name\Documents\Visual Studio 2012\Projects\ShutdownScheduler\Debug\SystemUtilisation.dll	SystemUtilisation

If anyone can help me (I'm a bit of a noob at this sort of thing), I would greatly appreciate it. :D

HTTP/2 203

Link to comment
https://linustechtips.com/topic/45618-vc-compiling-as-dll/
Share on other sites

Link to post
Share on other sites

Well my guess is your missing defining SYSTEM_UTILISATION_EXPORTS

so your program is trying to import instead of exporting

No, I defined it in the preprocessor commands and it is highlighted on the display. Commenting out the #if s makes no difference unfortunately :(

HTTP/2 203

Link to comment
https://linustechtips.com/topic/45618-vc-compiling-as-dll/#findComment-600822
Share on other sites

Link to post
Share on other sites

Oh sorry, I didn't read the error close enough.

"error LNK2019: unresolved external symbol _GetIfEntry@4 "

 

So the problem is this line

::GetIfEntry(&mi);

 

Sorry I have never really used that in dll's before, so I don't really know which libraries it is in.  Essentially though it can't find the lib file that contains GetIfEntry

According to MSDN it looks like you want to include Iphlpapi.lib

(Link: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365939%28v=vs.85%29.aspx look for the requirements section)

0b10111010 10101101 11110000 00001101

Link to comment
https://linustechtips.com/topic/45618-vc-compiling-as-dll/#findComment-600990
Share on other sites

Link to post
Share on other sites

Oh sorry, I didn't read the error close enough.

"error LNK2019: unresolved external symbol _GetIfEntry@4 "

 

So the problem is this line

::GetIfEntry(&mi);

 

Sorry I have never really used that in dll's before, so I don't really know which libraries it is in.  Essentially though it can't find the lib file that contains GetIfEntry

According to MSDN it looks like you want to include Iphlpapi.lib

(Link: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365939%28v=vs.85%29.aspx look for the requirements section)

Having commented that out, the dll now builds (thanks!), but I need to Have that code in there. I'll look around (I have a sample which I'm working off) and see how I can fix it. Thanks!

I had to link the library as well. Thanks for the help!

Edited by colonel_mortis

HTTP/2 203

Link to comment
https://linustechtips.com/topic/45618-vc-compiling-as-dll/#findComment-602980
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×