home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / rexx / rexxfunc / ezrxfunc / c / initterm.c < prev    next >
C/C++ Source or Header  |  1993-07-27  |  2KB  |  95 lines

  1. /*
  2.  * initterm.c -- The functions in this file are called when the DLL is
  3.  *               loaded and unloaded.  What "loaded" and "unloaded" mean
  4.  *               is defined in the .DEF file.  In our case, it means that
  5.  *               whenever a _process_ first loads or unloads the DLL, call
  6.  *               these routines.
  7.  */
  8.  
  9. #include "standard.h"
  10.  
  11. #define INCL_DOS
  12. #include <os2.h>
  13.  
  14. /*
  15.  * __dll_initialize -- Initialize the DLL.  In this case we don't do
  16.  *                     anything.  The C library has already been
  17.  *                     initialized.
  18.  */
  19.  
  20. int __dll_initialize( void )
  21.   {
  22.     return( TRUE );
  23.   }
  24.  
  25. /*
  26.  * __dll_terminate -- Clean things up.  The C library will be closed
  27.  *                    after this call.
  28.  */
  29.  
  30. int __dll_terminate( void )
  31.   {
  32.     return( TRUE );
  33.   }
  34.  
  35. /*
  36.  * The following code is CSET-specific.  OS/2 actually calls the
  37.  * _DLL_InitTerm function directly.  In WATCOM C, this function is in
  38.  * the library and it calls the functions __dll_initialize and
  39.  * __dll_terminate that you define.  So for consistency, with CSET
  40.  * we'll do the appropriate C library stuff and then call those same
  41.  * functions above.  So don't modify this section unless you know
  42.  * what you're doing.
  43.  */
  44.  
  45. #ifdef __IBMC__
  46.  
  47. extern int  _CRT_init( void );
  48. extern void _CRT_term( void );
  49.  
  50. /*
  51.  * _DLL_InitTerm -- Called by the system (hence uses _System linkage)
  52.  *          the first time the DLL is loaded or the last time
  53.  *          it is freed for a particular process.
  54.  */
  55.  
  56. unsigned long _System _DLL_InitTerm( ULONG hModule, ULONG ulFlag )
  57.   {
  58.     long ok = FALSE;
  59.  
  60.     /*
  61.      * If ulFlag is zero then the DLL is being loaded so initialization
  62.      * should be performed.  If ulFlag is 1 then the DLL is being freed so
  63.      * termination should be performed.             
  64.      */
  65.  
  66.     place_holder( hModule );
  67.  
  68.     if( ulFlag == 0 ){
  69.  
  70.         /* The C run-time environment initialization function must be called */
  71.         /* before any calls to C run-time functions that are not inlined.    */
  72.  
  73.         if( _CRT_init() == -1 )
  74.             goto leave;
  75.  
  76.         if( !__dll_initialize() ) goto leave;
  77.  
  78.     } else if( ulFlag == 1 ){
  79.  
  80.         __dll_terminate();
  81.  
  82.         _CRT_term();
  83.     }
  84.  
  85.     /* A non-zero value must be returned to indicate success. */
  86.  
  87.     ok = TRUE;
  88.  
  89.   leave:
  90.     return( ok );
  91.   }
  92.  
  93. #endif
  94.  
  95.