Using C Run-Time WEP() in MFC 2.0 or 2.5 _USRDLL Library

ID: Q98374


The information in this article applies to:

In a dynamic-link library (DLL) built with Microsoft Foundation Class Library version 2.0 or 2.5, the _USRDLL model uses the WEP() (Windows exit procedure) function provided in the C run-time library. Because the code uses the C library WEP() function, the destructors for static and global objects in the DLL are called and the CWinApp::ExitInstance() function for the DLL application object is called.

To use the WEP() function in the C run-time library, the DLL must export WEP in its module definition (.DEF) file. To do so, add the following statement to the .DEF file:

   EXPORTS
      WEP  @1 RESIDENTNAME 
While the ordinal number you choose is not important, you must specify the RESIDENTNAME attribute when you export WEP(). Do not include a WEP() function in the DLL code. If you do, Windows calls that function instead of the C library WEP() and the destructors for global objects and static objects, and CWinApp::ExitInstance() are not called.

If you DLL must contain clean-up code, overload the ExitInstance() function. If your DLL uses an import library to link to another DLL developed with the Microsoft Foundation Class Library, be sure to list the Microsoft Foundation Class Library and the C run-time library before the import library for the other DLL. This step ensures that the linker includes the WEP() in the C run-time library instead of linking in a reference to the WEP() in the other DLL.

The instructions above describe building a _USRDLL that unloads itself and cleans up properly. The text below describes the process that occurs when a DLL cleans up.

When Windows unloads the DLL, it calls the WEP() function in the DLL, which, using the procedure above, is the WEP() function in the C run- time library. WEP() calls the _WEP() function implemented in the Microsoft Foundation Class Library. The _WEP() function calls CWinApp::ExitInstance(). When ExitInstance() and _WEP() return, the WEP function calls the destructors for any static or global objects in the DLL.

For more information about using the C run-time library WEP() function in an _USRDLL, please refer to Technical Note 11: "Using MFC as Part of a DLL" in the MFC Tech Notes help file distributed with Visual C++ version 1.0.

Additional query words: kbinf 1.00 1.50 2.00 2.50 destructer destructers


Keywords          : kb16bitonly 
Version           : 
Platform          : 
Issue type        : 

Last Reviewed: July 21, 1999