DLL vs LIB
A library is a collection of resources that can be used to develop applications. A library is usually made up of subroutines, functions, classes, values and types. During the linking process (usually done by a linker), libraries and executables make reference to each other. Library files are divided in to static and dynamic libraries depending on the time at which the subroutines are loaded to the target application. Accordingly, LIB files are statically linked libraries and DLL files are dynamically linked libraries.
What is DLL?
Dynamic Link Library (more commonly known as DLL) is a shared library implementation developed by Microsoft. It uses the .dll, .ocx or .drv extensions and they are used in Microsoft Windows and OS/2 operating systems. .dll is used by the regular DLL files. And .ocx extension is used by libraries that contain ActiveX controls and .drv extension is used by legacy system driver files. The DLL file format is same as the Windows EXE files (Portable Executable files on 32-bit/64-bit Windows, and New Executable on 16-bit Windows). Therefore, any combination of code, data and resources can be contained in DLL files (just like in EXE files). As a mater of fact, data files with the DLL file format are called resource DLLs. Icon libraries (with .icl extension) and font files (with .fon and .fot extensions) are examples of resource DLLs.
Components called sections make up a DLL and each section has its own attributes like read-only/writable and executable/non executable. Code sections are executable, while data sections are non executable. The code sections are shared and data sections are private. That means all processes using the DLL will use the same copy of the code, while each process will have its own copy of the data. The primary dynamic library for Windows is kernel32.dll, which contains the base functions (file and memory related functionality) on Windows. COM (Component Object Model) is the extension of DLL to OOP (Object Oriented Programming). Conventional DLLs are easier to use than COM files.
What is LIB?
LIB files are static libraries (also known as statically linked libraries). LIB files contain a collection of subroutines, external functions and variables. LIB files are resolved at compile-time (as opposed to run-time). The code is actually copied in to the target application. A compiler, linker or a binder will do this resolution and produce an object file and an executable file. This process is called static build process.
What is the difference between DLL and LIB?
LIB libraries can be called during compile time, but DLL libraries can only be called during the run-time. LIB files are significantly larger than DLL files. A very common problem with DLL files is the versioning problem. This happens when the code of the DLL is changed and the application uses a wrong version of a DLL. This is not a problem associated with LIB files. In terms of reusability, when writing new versions of systems or completely new applications, DLLs are always better than LIBs.