### The _DLL_InitTerm Function

The initialization and termination entry point for a DLL is the _DLL_InitTerm function.

The default _DLL_InitTerm function (supplied by IBM C and C++ Compilers) performs the actions required to initialize and terminate the runtime environment. It is called automatically when a DLL is loaded or unloaded.

When each new process gains access to the DLL, _DLL_InitTerm initializes storage, semaphores, and variables. When each process frees its access to the DLL, the _DLL_InitTerm function terminates the DLL environment created for that process.

If you require additional initialization or termination actions for your runtime environment, you will need to write your own _DLL_InitTerm function.

Note: The _DLL_InitTerm function provided in the subsystem library differs from the runtime version.

If your DLL and the modules that access it do not dynamically link to the same runtime DLL, you must use the #pragma handler directive to ensure OS/2 exceptions are handled properly within your DLL. Use #pragma handler at the entry point of each DLL function to register the library exception handler _Exception. On exit from the function, code will also be generated to deregister _Exception.

Create a DLL - An Overview
Write Your Own _DLL-InitTerm Function
Write Your Own _DLL-InitTerm Function