Dynamic linking has the following advantages:
Many applications can use a single DLL simultaneously, sharing a single copy of the DLL in memory. This saves memory space and reduces swapping.
By simply changing a DLL you can enhance or modify an application without rebuilding it. For example, if an application uses a DLL to support video output, several displays can be supported by different DLLs. The application can use the DLL that supports the appropriate display.
Dynamic-link libraries can be used for after-market support. In the display-driver example, a modified DLL can be provided to support a display that was not available when the application was shipped. Similarly, a database application could support a new data-file format by modifying an existing DLL.
The DLL functions can be used by applications without any understanding of how the functions actually do their work. The DLL is a “black box” to the application. Future changes to the DLL are transparent to the application, as long as the input and output parameters remain the same.
A function in a DLL can be used by an application written in any programming language, as long as the application understands the function's calling convention (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).
A potential disadvantage to using dynamic link libraries is that the code for your application is not self-contained. To execute, the application depends on the existence of a separate module. If the DLL cannot be located at run-time, the functionality provided by the DLL will not be available to the application. If your application is using load-time dynamic linking, it will terminate if the DLL is not found at process startup. If your application is using run-time dynamic linking, it will receive an error message if the DLL is not available to be loaded. Load-time and run-time dynamic linking are discussed in Section 0.1.3.1, “Load-Time Dynamic Linking” and Section 0.1.3.2, “Run-Time Dynamic Linking.”