|
The term dynamic link libraries (DLL) refers to the general notion of a library which is not part of any program image, but rather is loaded as a separate entity when a program is run. Typical usage scenarios for DLLs include:
Both scenarios eliminate the need for duplicate code and reduce the total system memory required for the task in question. Static libraries may also eliminate the need for duplicate code by compiling one version of source code into an object file which gets linked into multiple program images. Static libraries will not however achieve the same total memory savings as dynamic libraries since a copy of the object file is included in each program using the library.
The Win32 API provides two methods for accessing routines in a DLL. These are implicit loading and explicit loading. In the former case, an executable is linked with a .LIB file which contains sufficient information to allow the operating system to automatically ensure the necessary DLLs are loaded, and resolve references to functions provided by the DLL, before the executable begins running.
In the second case, the application developer includes explicit calls inside the program to LoadLibrary, GetProcAddress and FreeLibrary, which, respectively, ensure a DLL is loaded into memory, resolve the address of functions provided by the DLL, and indicate to Windows the DLL is no longer needed by a particular thread.
In both Win32 methods, the DLL is simply a code container and is not an independent program. There are no processes or threads associated with a DLL itself. Code within a DLL always runs in the context of a calling thread/process. The entry point in a DLL (DllMain) is called whenever a new thread/process attaches to a DLL, and in most cases when a process detaches from a DLL. When processes terminate abnormally DllMain is not guaranteed to be called. For more information on the exact semantics of DLL attach and detach please refer to the MSDN documentation.
An introduction to Windows DLLs can be found on Windows MSDN (www.msdn.com). It is strongly recommended developers familiarize themselves with the concepts of Win32 DLLs.
RTX provides real-time DLL solutions with behavior similar to Win32 DLLs. While many of the features of Win32 DLLs have been provided, providing the deterministic real-time performance of RTX has required some deviations from exact Win32 behavior. In the next section we describe how the two approaches have been implemented in RTX, and highlight the key differences between RTX DLLs and Win32 DLLs.