Skip to main content
GameDev.net gamedev.net
🔒 Locked

Using Dll's without .lib

Started by brain21 Jun 28, 2004 at 7:22 PM 4 replies 1k views
Original Post
brain21
brain21
Hi, I was wondering if it was possible to use someone else's .dll file and somehow extract the functions from it? And maybe create a .lib from that. I'm not too familiar with these things. I just want to use a .dll for a program, but that company does not have a sdk for there product. Would it also be possible to use loadlib and dynamically load the dll and somehow get the address of the proc. But how would I know what the parameters are?? like int, int, char*, ect? Thanks for the help, Denny
Fruny
Fruny
EDIT: BLEH, apparently it doesn't work as advertised, or I didn't understand. So, here is a quick google search that gives some potentially helpful hits.

Hi, I was wondering if it was possible to use someone else's .dll file and somehow extract the functions from it?

LIB library /EXTRACT:member /OUT:objectfile

And maybe create a .lib from that.

LIB /DEF library

Would it also be possible to use loadlib and dynamically load the dll and somehow get the address of the proc.

Yes.

But how would I know what the parameters are?? like int, int, char*, ect?

If the public symbol name is mangled, you can infer the parameter types from it. If not, and you don't have a header file for the library, you probably will have to try to reverse engineer it directly from the ASM.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Promit
Promit
The closest thing I saw was a "dlltool.exe" that came with Dev-C++, that can generate .a files from a DLL and a DEF file. Not much help for Visual Studio, but it's at least possible.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
Promit
Promit
Bingo!

It looks like this particular method works by having you partially decompile the DLL's interface and then create a dummy DLL with the same interface, using just the LIB generated.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
Nemesis2k2
Nemesis2k2
Quote:
Would it also be possible to use loadlib and dynamically load the dll and somehow get the address of the proc.

Yes. You don't need a .lib fle to use a DLL anyway. Load the DLL using the LoadLibrary() function. Get a pointer to the function you want to call by calling GetProcAddress(). You can then just call the function through the function pointer.

Quote:
But how would I know what the parameters are?? like int, int, char*, ect?

Exported functions and values are "decorated" under C++ to encode type information into them. This can tell you exactly what the parameters and the return value is for all the functions, provided the DLL was compiled under C++, using the C++ conventions.

Download a program called "Dependency Walker". It will allow you to view all the exported values from a DLL, as well as all the functions it relies on from other modules. If the functions use the C++ name decoration, you will be able to view all the type info on them. If they're C functions, you're out of luck. You can still cal the function, but you'll have to guess about paramerers and the return value.
iMalc
iMalc
Nice Fruny. I was going to tell him the same thing, but I don't remember the parameters and I only do this stuff at work.
I have a Delphi DLL that I needed to make a Lib file for, and that is how I did it.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.