20.1.3 Dynamic-Link Libraries and Tasks

One of the basic differences between an application module and a dynamic-link module is in the notion of the task. A task is the fundamental unit of scheduling in Windows. An application module is said to be a tasked executable module. When an application module is loaded, a call is made to its entry point, the WinMain function, which typically contains the message loop. As the application module creates windows and begins to interact with the user, the message loop connects the application module to the Windows scheduler. As long as the user is interacting with the application's windows, messages are fed to the application module and the module retains control of the processor.

A dynamic-link library is sometimes said to be a nontasked executable module. Like the application module, a dynamic-link module may contain an entry point. When the module is loaded, the entry point for the library is called but, typically, performs only minor initialization. Unlike the application module, a dynamic-link module does not interact with the Windows scheduler by means of a message loop; instead, the dynamic-link module waits for tasks to request its services.

Application modules are the active components of Windows. They receive system- and user-generated messages and, when necessary, call library modules for specific data and services. Library modules exist to provide services to application modules.

Note:

Some dynamic-link libraries are not completely passive; for example, some are device drivers for interrupt-driven devices such as the keyboard, mouse, and communication ports. However, the interaction of such libraries is carefully controlled to avoid disrupting the Windows scheduler. If you require a dynamic-link library to take an active role, you should write it according to the guidelines described in Section 20.2.4, “Device Drivers.”