Initialize and Terminate Your DLL Environment (OS/2, Windows)

Your DLL must include a function that initializes the environment when you load a DLL and terminates the environment when you release the DLL. VisualAge C++ supplies a default function, for you to use if default initialization is adequate. The default function is included automatically, unless you provide a function to override it. You can write you own DLL initialization and termination function.

The initialization and termination entry point for a DLL is the _DLL_InitTerm function. This function is called automatically when you access the DLL. When a process uses an new instance of a DLL, the _DLL_InitTerm function initializes the necessary environment for the DLL, including storage, semaphores, and variables. When a process releases its access to the DLL, the _DLL_InitTerm function terminates the DLL environment created for that process.

To perform additional initialization or termination actions for your DLL, you must write your own version of one of the following functions:

If you do not provide either of these functions, the default versions are used.

Your function must conform to the required prototype. Providing just DllMain is usually adequate and is the simpler approach. However, you have more control with _DLL_InitTerm. For example, you can create a version of _DLL_InitTerm that does not use the VisualAge C++ run-time library.



Static and Dynamic Link Libraries
Run-Time Library Environments


Build Dynamic Link Libraries
Build Subsystems


The _DLL_InitTerm function on OS/2
The _DLL_InitTerm function on Windows