views:

646

answers:

5

I have been given a small library, consisting of a .dll, a .h header and a .def file. I'm fairly sure the library was written in C, but possibly C++.

Is it possible for me to access the functions in the library without using the LoadLibrary/GetProcAddress/FreeLibrary method that is usually talked about. I have no .lib file - is it usual to have one?

I've literally spent the past 2 days looking this up. It seems that since I've been given a header file defining the functions I wish to use from the dll, and a .def file I shouldn't need to explicitly 'load' each function manually (LoadLibrary/GetProAddress/FreeLibrary) - in my case I will be using around 5 or 6 functions from the .dll, but there are around 70 available and it seems that would be a ball-ache and result in an unnecessary mess of code.

Thanks for any advice.

A: 

Try implib32.

jdigital
+1  A: 

You need a lib file - it contains the stubs that the linker needs to create the import table for your DLL.

Not sure if this would work, but you can try:

Create an .C file with empty stubs and the .DEF file. Compile as a DLL with the exact same name to generate the .lib. Throw away the new DLL, and link with the lib, if the existing DLL is in the same directory as your exe your program should be able to load and bind it.

I believe this will work because native DLL's are not strongly named.

Michael
+7  A: 

There are several ways to create an import library for a DLL - Microsoft documents a method for creating one by building your own .DEF file:

Michael Burr
+3  A: 

Visual C++ has "lib" - look it up in the online help.

Use "lib /def" to make the .lib file.

Jimmy J
A: 

Thanks for the answers guys, problem solved! (I ticked Jimmy J's answer as it took me directly to the solution and I now know of the existence of lib, but all of your answers were helpful - thankyou :) )

Richter