You are on page 1of 2

Dynamic-Link Library (DLL)

DLL is an executable file that acts as a shared library of functions.

Dynamic linking provides a way for a process to call a function that is not part of
its executable code. The executable code for the function is located in a DLL,
which contains one or more functions that are compiled, linked, and stored
separately from the processes that use them.
Dynamic linking Vs Static Linking:
Dynamic linking allows an executable module (either a .dll or .exe file) to include
only the information needed at run time to locate the executable code for a DLL
In static linking, the linker gets all of the referenced functions from the static link
library and places it with your code into your executable.
Advantages of Dynamic Linking:
Sharing of data, resources, and single copy of DLL offers following advantages:
Save memory: Single DLL copy in memory
Reduce swapping: “
Save disk space: Single DLL copy on disk
Upgrade easier: No need to re-compile and re-link
Provide after-market support: Add support for new hardware
Provide a mechanism to extend the MFC library classes: Inheritance
Support multilanguage programs: Only function calling convention to be followed:
the order in which the function expects its arguments to be pushed onto the
stack, whether the function or the application is responsible for cleaning up the
stack, and whether any arguments are passed in registers.
Ease the creation of international versions: Separate resource DLL for which

DLL Vs Application
Both are executable modules
User View: DLLs cannot be directly executed
System View:
An application can have multiple instances of itself running in the system
simultaneously, whereas a DLL can have only one instance.
An application can own things such as a stack, global memory, file handles, and
a message queue, but a DLL cannot.
Differences Between Win16 and Win32 DLLs
• There is no separate startup module that you have to link with. The DLL
startup sequence is handled directly by C/C++ run-time library code linked into
your DLL.
• The run-time library code initializes any static non-local C++ objects by
calling the appropriate constructors. Each process gets its own copy of all the
DLL's static data, including objects.
• You no longer need the function LibMain or a WEP (Windows Exit
Procedure). Where you add initialization and termination code for your DLL
depends on the type of DLL you are building. Instead of LibMain, you provide
DllMain, which is called for both for both entry and exit.
• You can import and export symbols directly in your source code. If you
use the __declspec(dllexport) attribute (similar to __export in Windows 3.x),
you do not need to use a separate module-definition file for exports.
• Executables that use __declspec(dllimport) to import data, objects, and
functions from a DLL cause the compiler to generate more efficient code.
• The timing of calls to routines registered with atexit can differ.
• In addition to Win32 non-MFC DLLs, Visual C++ offers three kinds of MFC