Thursday, October 8, 2009

Generate .lib from 3rd party DLL without .lib file

1. Open up the Visual Studio Tools command promopt (something like Start -> Program Files -> Microsoft Visual Studio -> Visual Studio Tools -> Visual Studio Command Prompt

2. List down all the function in anydll.dll with following command
dumpbin /exports C:\path\to\anydll.dll

3. Build .def by copy all the function into the anydll.def
the definition must start with EXPORTS
eg.
EXPORTS
anydll_function1
anydll_function2
......

3 Generate the lib file
lib /def:C:\path\to\anydll.def /out:C:\path\to\anydll.lib /machine:x86

2 comments:

Cheah Wei said...

do we still use .lib file nowaday?

tsong said...

There is 2 way to link a DLL,
implicit or explicit link.

With implicit linking, the executable using the DLL links to an import library (.LIB file) provided by the maker of the DLL

while explicitly linking, application will use LoadLibrary function to load the DLL.

implicat linking will be more easy to used.