SAMPLE: Windows Application to Unload DLLs from MemoryLast reviewed: February 15, 1996Article ID: Q96312 |
The information in this article applies to:
SUMMARYDuring development, dynamic-link libraries (DLLs) can sometimes be left in memory with no applications using them. To unload DLLs that have been left in memory, developers must exit and then restart Windows, which can be very inconvenient. DLL UNLOADER is a sample Windows-based application that lets developers select a DLL, show information about it, and unload it from the system if desired; this eliminates the need to restart Windows. Download UNLOADER.EXE, a self-extracting file, from the Microsoft Software Library (MSL) on the following services:
MORE INFORMATIONThere are two ways that a DLL can be left in memory after all applications that use it have exited:
If a DLL is left in memory with no application using it, and is then recompiled and executed, the new version of the DLL will not be loaded because Windows thinks the DLL is already loaded (because the module names are the same). If you try to debug the DLL with CodeView for Windows, the source code window will display the latest version's source code; however, the old version's code, which is still in memory, will be executed. This version mismatch causes CodeView to appear to not be working properly. To resolve this problem, you must either exit and restart Windows or force Windows to unload the old version of the DLL. The DLL UNLOADER sample calls ToolHelp to obtain the list of modules currently loaded in the system. Because this list contains modules that belong to both DLLs and applications (which are tasks), DLL UNLOADER filters out the modules that belong to tasks so that they cannot be unloaded accidentally and cause the system to crash. The list box stores the module name and handle for each module that doesn't belong to a task. When the user selects a module, its handle is used to obtain information about it and/or unload it. To unload a DLL, DLL UNLOADER first calls GetModuleUsage() to retrieve its usage count and then repeatedly calls FreeLibrary() until the usage count drops to zero; then Windows unloads the DLL. To obtain information about a DLL, DLL UNLOADER calls ModuleFindHandle() and displays the information in a dialog box. Finally, DLL UNLOADER creates an .INI file in the directory where its executable file resides to remember its last position on the screen before it exits.
|
Additional reference words: 3.10 softlib UNLOADER.EXE
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |