DLLs & Lib files

Posted on 2007-07-20
Last Modified: 2013-12-14

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.

Question by:Unimatrix_001
    LVL 3

    Accepted Solution

    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).
    LVL 28

    Assisted Solution

    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 ;-)
    LVL 3

    Author Comment

    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...

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project ( automates most of the tasks discussed in this article. You can even fin…
    After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
    The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
    The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now