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

Last reviewed: July 17, 1997
Article ID: Q98374
1.00 1.50 WINDOWS kbprg

The information in this article applies to:

  • The Microsoft Foundation Classes (MFC), included with:

        - Microsoft Visual C++ for Windows, versions 1.0 and 1.5
    

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 reference words: kbinf 1.00 1.50 2.00 2.50 destructer
destructers
KBCategory: kbprg kbfasttip
KBSubcategory: MfcDLL
Keywords : kb16bitonly
Technology : kbMfc


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 17, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.