_CRT_init -- Initialize DLL Runtime Environment

Format

int _CRT_init(void);
/* no header file - defined in the runtime startup code */

Language Level: Extension
_CRT_init initializes the IBM C and C++ Compilers runtime environment for a DLL.

By default, all DLLs call the IBM C and C++ Compilers _DLL_InitTerm function, which in turn calls _CRT_init for you. However, if you are writing your own _DLL_InitTerm function (for example, to perform actions other than runtime initialization and termination), you must call _CRT_init from your version of _DLL_InitTerm before you can call any other runtime functions to insure that the runtime library is initialized. If _CRT_init has been called, there must be a matching _CRT_term to insure library termination.

If your DLL contains C++ code, you must also call __ctordtorInit after _CRT_init to ensure that static constructors and destructors are initialized properly. The prototype for __ctordtorInit is

   void __ctordtorInit(int flag)

Value 0 for flag means that destructors are called for process termination. Value 1 for flag means that only destructors for thread specific objects in the current thread should be called.

Note: If you are providing your own version of the _matherr function to be used in your DLL, you must also call the _exception_dllinit function after the runtime environment is initialized. Calling this function ensures that the proper _matherr function will be called during exception handling. _exception_dllinit is defined in the runtime startup code as:

   void _Optlink _exception_dllinit( int (*)(struct exception *) );

The parameter required is the address of your _matherr function.

Return Value
If the runtime environment is successfully initialized, _CRT_init returns 0. A return code of -1 indicates an error. If an error occurs, an error message is written to file handle 2, which is the usual destination of stderr.

Example



_CRT_term -- Terminate DLL Runtime Environment
_DLL_InitTerm -- Initialize and Terminate DLL Environment
_rmem_init -- Initialize Memory Functions for Subsystem DLL
_rmem_term -- Terminate Memory Functions for Subsystem DLL
_tmem_init -- Initialize Memory Functions for Subsystem DLL