DLLs & Lib files

Hi,

My apologies, this isn't much of a programming question, although you're the guys who are likely to know. ;)

Please explain the difference between dll's and lib files, and how they fit in with DLL export declerations in a source file. Also, how I can go about viewing the contents of each  - dll's there's a Visual Studio tool I can use to see the function defintions contained?, but I don't know about libs.

Thanks,
Uni
LVL 3
Unimatrix_001Asked:
Who is Participating?
 
DefreeComanCommented:
DLLs can be loaded at runtime to call the functions within them while LIBs contain data that is put into the application at link time.  When you use a DLL, the machine code for the functions you call from it isn't actually contained in your executable; when you use a LIB it is (if that LIB contains the machine code for the functions rather than information on how to import it from a DLL).  The reason for the dllexport declarations in source files for DLLs is to indicate which functions/pieces of data should be made available for export (some functions/data may be just for internal use of the DLL and not need to be exported).  Functions declared with __declspec(dllexport) are given an entry in the DLL's export table, which gives applications the memory address in the DLL to go to when calling the function (since functions from LIBs are put into the application at link time, the application already has the information it needs to call them).  I don't know of any good tools for viewing function *definitions* that are in LIB files; if it is declarations you want, that information would be in the header file for the library.  You can see the names of the functions in a LIB by opening it in a text editor and reading the parts that are legible or by using a dump utility (such as dumpbin.exe for MS Visual Studio).
0
 
peprCommented:
Basically, lib files are linked statically to the exe by the linker. The code becames part of the exe that is indistinguishable from the code produced from your sources. You have to have documentation and the header files to use the lib files.

The dll files are linked dynamically to the application. This means that the code remains inside the dll file that has to be distributed with the application because it will not be a part of the exe. However, dll's are of more kinds. The plain old dll are not used these days very much. For them, you have to know the function names and argument types (entry point of the DLL). It is more usual to use COM dll's these day. Only some fixed "plain old" entry points are usually used inside them. Moreover, they are used for Object Oriented (or better to say component oriented approach) in the sense that thery implement classes and allow to create their instances. The plain old dll's contained usually plain functions (imperative or procedural approach to programming). COM can be of two kinds: one that do implement so called dispatch interface and the other that do not implement it. Using the dispatch interface, you can use the implemented functionality also from scripting languages -- basically, you can call a functions by its name stored in a string variable. The more powerfull COM is less wrapped and you must have description of the interface in some meta form. It is created in IDL (Interface Definition Language) and the compiled form is part of the DLL (type library). Visual C++ has tools to decompile the information and generate header (.tlh) and some related wrapper implementation source files (.tli).

The lib files do not contain any metainformation like the type library. Therefore it is more difficult to use undocumented libs. You have to decompile it which may be forbidden by law means. Even successful decompilation may be not very understandable if you are not used to that kind of work. Unless you are bad kind of hacker, it is likely that you can find the way to get the documentation and the headers. Start with ReadMe.txt that may come with the lib ;-)
0
 
Unimatrix_001Author Commented:
Thank you both. :)

DefreeComan: Apologies, for the delayed reply, although I'm afraid I didn't get an e-mail notifying me of your reply...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.