What is a DLL?

A DLL is an executable module containing functions that Windows applications can call in order to perform useful tasks. DLLs exist primarily to provide services to application modules. DLLs play an important role in the Windows environment; Windows uses them to make Windows functions and resources available to Windows applications.

Summary: DLLs are linked during run time.

DLLs are similar to run-time libraries, such as the C run-time libraries. The main difference is that DLLs are linked with the application at run time, not when you link the application files using the linker. Linking a library with an application at run time is called “dynamic linking”; linking a library with an application using the linker is called “static linking.”

One way to understand DLLs is to compare them to static-link libraries. An example of a static-link library is MLIBCEW.LIB, the medium-model Windows C run-time library. MLIBCEW.LIB contains the executable code for C run-time routines such as strcpy and strlen. You use C run-time routines in your application without having to include the source code for those routines. When you link your C application, the linker incorporates information from the appropriate static-link library. Wherever the application's code uses a C run-time routine, the linker copies that routine to the application's .EXE file.

The primary advantage of static-link libraries is that they make a standard set of routines available to applications, and do not require the applications to include the original source code for those routines.

However, static-link libraries can be inefficient in a multitasking environment like Windows. If two applications are running simultaneously, and they use the same static-library routine, there will be two copies of that routine present in the system. This is an inefficient use of memory. It would be more efficient for both applications to share a single copy of the routine; however, static-link libraries provide no facility for sharing code between applications.

Summary: DLLs let multiple applications share code and other resources.

DLLs, on the other hand, allow several applications to share a single copy of a routine. Every standard Windows function, such as GetMessage, CreateWindow and TextOut, resides in one of three DLLs: KERNEL.EXE, USER.EXE, and GDI.EXE. If two Windows applications are running at the same time, and both use a particular Windows function, both share a single copy of the source code for that function.

In addition to letting applications share code, DLLs can be used to share other resources, such as data and hardware. For example, Windows fonts are actually text-drawing data that applications can share via DLLs. Likewise, Windows device drivers are actually DLLs that allow applications to share hardware resources.

All Windows libraries are DLLs. For example, the GDI.EXE, USER.EXE, and KERNEL.EXE files that comprise the major part of Windows are DLLs. You can develop your own custom DLLs to share code, data, or hardware among your applications.