Summary This article explains what a dynamic link library (DLL) is and the various problems that can occur when using a DLL. Then, this article explains some advanced issues you should consider when developing your own DLL. In explaining what a DLL is, this article explains dynamic linking methods, DLL dependencies, DLL entry points, exported DLL functions, and DLL troubleshooting tools. This article will conclude with a high-level comparison of DLLs and Microsoft .NET Framework assemblies. Introduction For the Microsoft Windows operating systems listed in the "Applies to" section, much of the functionality of the operating system is provided by dynamic link libraries (DLLs). Additionally, when you run a program on one of these Windows operating systems, many of the program's functionality may be provided by DLLs. For example, some programs may contain many different modules, and each module of the program is contained in and distributed from a DLL. Using DLLs helps promote code modularity, code reuse, efficient use of memory, and reduced disk space usage. As a result, the operating system and programs load and run faster and take up less disk space in your computer. When a program uses a DLL, a problem called a dependency can prevent the program from running. When a program uses a DLL, a dependency is created. If another program overwrites and corrupts that dependency, the original program may not run successfully. With the introduction of the Microsoft .NET Framework, most dependency issues have been eliminated through the use of assemblies. What is a DLL? A DLL is a library that contains code and data that can be used by multiple programs simultaneously. For example, in Windows operating systems, the Comdlg32 DLL performs common functions related to dialog boxes. Therefore, every program can use the functionality contained in this DLL to implement the Open dialog box. This helps promote code reuse and efficient use of memory. By using DLLs, programs can be modularized and composed of relatively independent components. For example, an accounting program could be sold by module. Individual modules can be loaded into the main program at runtime (if the corresponding module is installed). Programs load faster because modules are independent of each other, and modules are only loaded when the corresponding functionality is requested. Additionally, updates can be more easily applied to individual modules without affecting other parts of the program. For example, you might have a payroll calculation program where tax rates change every year. When the changes are isolated into the DLL, you can apply the update without rebuilding or installing the entire program. The following table describes some of the files that are implemented as DLLs in the Windows operating system: ActiveX control (.ocx) files An example of an ActiveX control is the calendar control, which allows you to select a date from a calendar. ?6?1Control Panel (.cpl) Files An example of a .cpl file is an item located in Control Panel. Each entry is a private DLL. ?6?1 Device Driver (.drv) File An example of a device driver is a printer driver that controls printing to a printer. Advantages of DLLs The following table illustrates some of the advantages provided when programs use DLLs: Use fewer resources When multiple programs use the same function library, DLLs can reduce the amount of code loaded on disk and physical memory. Repeat volume. This can greatly affect not only programs running in the foreground, but also other programs running on the Windows operating system. ?6?1 Promote modular architecture DLL helps promote the development of modular programs. This can help you develop large programs that require multiple language versions or programs that require a modular architecture. An example of a modular program is an accounting program that has multiple modules that can be loaded dynamically at runtime. ?6?1 Simplify deployment and installation When functions in the DLL need to be updated or repaired, deploying and installing the DLL does not require re-establishing the link between the program and the DLL. Additionally, if multiple programs use the same DLL, then multiple programs will benefit from the update or fix. This problem may occur more frequently when you use third-party DLLs that are regularly updated or fixed. DLL Dependencies Dependencies are created when a program or DLL uses DLL functions from another DLL. Therefore, the program is no longer independent, and if this dependency becomes corrupted, the program may experience problems. For example, the program may not run if one of the following occurs: A dependent DLL is upgraded to a new version. ?6?1 Fixed dependency DLL. ?6?1The dependent DLL is overwritten by its earlier version. ?6?1Removed the dependent DLL from the computer. These operations are often called DLL conflicts. If backward compatibility is not enforced, the program may not run successfully.
The following table describes the changes introduced in Microsoft Windows 2000 and later versions of Windows operating systems to help minimize dependency issues: Windows File Protection In Windows file protection, the operating system blocks unauthorized The agent updates or removes system DLLs. Therefore, Windows File Protection will look for a valid digital signature when a program installation operation attempts to remove or update a DLL that is defined as a system DLL. ?6?1 Private DLL A private DLL protects a program from changes made to a shared DLL. Private DLLs use version-specific information or an empty .local file to enforce the version of the DLL used by the program. To use a private DLL, look for the DLL in the program root folder. Then, for new programs, add version-specific information to the DLL. For older programs, use an empty .local file. Each method tells the operating system to use a private DLL located in the program's root folder.