Run-time Library Behavior (Windows Embedded CE 6.0)
1/5/2010
The C/C++ run-time library code performs the DLL startup sequence.
Included in the C/C++ run-time library code is the DLL entry-point function called _DllMainCRTStartup.
In addition to initializing the C run-time library, _DllMainCRTStartup initializes the associated DLL.
The C/C++ run-time library code calls constructors and destructors on static, nonlocal variables.
For example, in the following example code, Equus and Sugar are two static, nonlocal objects of class CHorse, defined in HORSES.H. Because the objects are defined outside of any function, no function in source code contains calls to a constructor or destructor function for CHorse.
The following example code shows how the run-time library functions perform any necessary calls to these constructors and destructors.
#include "horses.h"
CHorse Equus( ARABIAN, MALE );
CHorse Sugar( THOROUGHBRED, FEMALE );
BOOL WINAPI DllMain (HANDLE hInst,
ULONG ul_reason_for_call,
LPVOID lpReserved)
...
Each time a new process attempts to use the DLL, the OS creates a separate copy of the DLL's data.
The run-time library code for the DLL calls the constructors for all global objects, if any, and then calls the DllMain function with process attach selected.
When the process completes, the run-time library code calls DllMain with process detach selected, and then calls a list of termination functions, including atexit functions, destructors for the global objects, and destructors for the static objects.
The order of events in process attach is the reverse of that in process detach.
The run-time library code is also called during thread attach and thread detach, but the run-time code does no initialization or termination on its own.
See Also
Concepts
C Run-Time Library Overview
Linking to the CRT
CRT Entry Points