Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

This is a good one, so listen up.

Status
Not open for further replies.

bont

Programmer
Sep 7, 2000
200
US
The problem:

I am trying to link to a function within a dll (pre-built by someone else, who swears it is working).

In fact, he gave me code which should work, but I can't show it to you do to copyright laws.

The basic structure is this:

# include windwos
# include iostream

extern "C" { __declspec(dllimport) int _stdcall myfunction...



int Ret = myfunction (...);


------

I end up with this error:

main_ext.obj : error LNK2001: unresolved external symbol __imp__myfunction@48

I take this to mean it isn't connecting to my dll function, and I can't find a straight answer why.

I am guessing that it is interpretting the name incorrectly by adding the __imp preceeding the function name, but I can't seem to change this.

I am a linear programmer, and I hate these setting, for they are killing my on deadlines. Does anyone know how to fix this?
 
The error is telling you that it cannot find the name of the function you have specified where it is looking.

The __imp really only means the location in the file it is looking, somewhat like a ptr to the exact location of the myfunction() is what it is looking for. It's telling you that it cannot find the ptr to the function becuase it can't find the exact wording in the ptr table.

What you need to do is make sure you are spelling the function correctly and make sure the FOOLIO who wrote the DLL gave you the correct name he was using or especially if he declared the function as extern if he wrote it in C++. Also, make sure that your program is looking in the right file(DLL) to try and find the function.

What's happening is everthing appears to be linking correctly but it can't find the instance of the function or the name of the function as you are calling it.

Did you IMPORT the DLL using the #import directive??

My best guess is that the DLL hasn't been loaded properly with an #import directive in your code.

BTW, the statement __imp__myfunction@48 means the ptr to myfunction AT the Address number which usually is the Base no. that your DLL files are loaded into when they are loaded via #imports.
 
Your buddy did gave you the required .h file but he probably "forgot" about the .lib file.

Put the lib file near your .h file and go to ProjectSettings->Link->Object/lbrary modules and add mylib.lib.

s-)

Blessed is he who in the name of justice and good will, shepards the week through the valley of darknees...
 
OK, I feel stupid. You see, I learned linear C & C++ without MS Visual Studio, so I don't understand a lot of the setting. I re-installed his original files, and found a .dsw file, so I clicked on it, instead of the .cpp file.

What I don't understand, and would like someone to explain, is why when I look at the project space, I see the .lib file under source, and how do I do the same?

 
Just go to the Projects->Add to Project->Files, then browse to the appropriate file (you'll need to change the filter to see .lib files), and choose the appropriate files.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top