Microsoft KB Archive/92731
DLL Correctly Performs Initialization and Termination
The information in this article applies to:
- Microsoft C/C++ for MS-DOS, versions 7.0, 7.0a
- Microsoft Visual C++, versions 1.0, 1.5
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.
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 query words: kbinf 7.00 7.00a 1.00 1.50 start-up constant init libmain destructer
Keywords : kb16bitonly
Issue type :
Technology : kbVCsearch kbAudDeveloper kbPTProdChange kbvc150 kbvc100 kbZNotKeyword3 kbCVC700DOS kbCVC700aDOS
Last Reviewed: May 6, 2001