SAMPLE: DLLSKEL Demonstrates DLL and Calling ApplicationLast reviewed: February 15, 1996Article ID: Q84932 |
The information in this article applies to:
SUMMARYDLLSKEL is a file in the Microsoft Software Library that contains the source code for a minimal dynamic-link library (DLL) for the Windows environment. DLLSKEL demonstrates how to correctly implement and compile a multiple-segment DLL.
MORE INFORMATIONThis sample has two parts: the multiple-segment DLL and an application for the Windows environment. The application has all the features of the Generic sample application provided with the Windows Software Development Kit and a menu item that calls a function exported from the DLL. The DLL function creates a message box when it is called by the application. The DLLSKEL sample demonstrates implicitly loading a DLL. However, the modifications required to explicitly load the DLL are straightforward. Download DLLSKEL.EXE, a self-extracting file, from the Microsoft Software Library (MSL) on the following services:
In the DLLSKEL sample, the DLL has multiple code segments. The Windows exit procedure (WEP) is placed in a fixed segment while the remainder of the code is placed in movable, discardable segments. The WEP must reside in a fixed code segment so that it can be called at all times, even when the system has very little free memory. Consider the situation in which Windows has discarded the segment containing the WEP. When Windows calls the WEP, the segment must be loaded back into the system and all relocations to other segments must be fixed up, which might require other segments to be loaded. If the system does not have enough memory to load all the required segments, or if some of the segments no longer exist, Windows will report an unrecoverable application error (UAE) or general protection (GP) fault because it cannot completely load the segment containing the WEP. If the WEP is placed in a fixed code segment, the relocations are fixed up only once, which completely avoids this situation. The WEP was originally designed to allow a DLL that hooked an interrupt to unhook it before termination, not to provide a general-purpose cleanup procedure for a DLL. Under Windows 3.0, the WEP is called on a very small stack located in the Windows Kernel, which will overflow if the WEP calls Windows functions. There is enough room to unhook an interrupt, however. Under Windows 3.1, the WEP is called on a 4K stack in the Windows Kernel, which provides enough room to call Windows functions and to perform general DLL cleanup. Because the WEP is called only once during the lifetime of a DLL, it cannot be used to clean up each application instance that uses the DLL. Under Windows versions 3.0 and 3.1, if a DLL requires each application instance to call a cleanup routine, the DLL must explicitly provide the routine, which each application instance must explicitly call. An implicitly loaded DLL is loaded into memory before the calling application is completely loaded. Therefore, the LibMain() function, which is analogous to an application's WinMain() function, will be called before the application's message queue is initialized. Therefore, the DLL must not call functions that send messages to the application in LibMain(). Similarly, an implicitly loaded DLL is terminated after the calling application has been removed from memory. Therefore, nothing in the WEP must require the application to exist. The LoadLibrary() function loads a DLL explicitly; the FreeLibrary() function unloads a DLL. To modify DLLSKEL to explicitly load and free the DLL:
|
Additional reference words: 3.10 3.00 softlib DLLSKEL.EXE
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |