DLL Correctly Performs Initialization and Termination

Last reviewed: July 17, 1997
Article ID: Q92731
7.00 7.00a | 1.00 1.50
MS-DOS     | WINDOWS
kbprg

The information in this article applies to:

  • Microsoft C/C++ for MS-DOS, versions 7.0 and 7.0a
  • Microsoft Visual C++ for Windows. versions 1.0 and 1.5

SUMMARY

The text below describes using Microsoft C/C++ version 7.0 to create a dynamic-link library (DLL) that correctly handles DLL initialization and termination.

A DLL that uses these techniques calls the constructor for each global object when the DLL is loaded and the destructor for each global and static object when the DLL is freed. The DLL also correctly initializes the floating-support required by the C/C++ run-time libraries.

MORE INFORMATION

LIBENTRY.OBJ and WEP.OBJ are modules in the standard C run-time libraries for DLLs that contain the default DLL initialization and termination code, respectively. The DLL libraries are named xDLLCEW.LIB, where the letter x is replaced with a code to indicate the memory model. For example, SDLLCEW.LIB is the small memory model DLL library.

Linking a DLL directly to it's own LIBENTRY.OBJ will over-ride any initialization done by the default LIBENTRY routine in the library. This initialization code is required to construct global objects and to load floating-point support. This situation can cause the following error message when an application implicitly loads DLLs:

   Application Error
   Floating point support not loaded

If an application uses a DLL with its own WEP routine, the destructors for global and static objects are not called.

To use the default LIBENTRY.OBJ file, link with the DLL library. To replace the LIBENTRY.OBJ file, list LIBENTRY.OBJ in the list of modules to link.

To use the default WEP procedure, first make sure that none of the modules in the DLL contain a WEP procedure. Then add the following lines to the module definition (DEF) file for the DLL:

   SEGMENTS 'WEP_TEXT' FIXED PRELOAD

   EXPORTS
      WEP @1 RESIDENTNAME

The DETAILS.TXT file, distributed with Microsoft C/C++ version 7.0, describes this procedure in more detail. In Visual C++, refer to the "Programming Techniques" manual, chapters 6.3 and 6.4.


Additional reference words: kbinf 7.00 7.00a 1.00 1.50 start-up constant
init libmain destructer
KBCategory: kbprg
KBSubcategory: CRTIss
Keywords : kb16bitonly


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.