Example of a Subsystem _DLL_InitTerm Function (OS/2)

 /* _DLL_InitTerm() - called by the loader for DLL initialization/termination  */
/* This function must return a non-zero value if successful and a zero value  */
/* if unsuccessful.                                                           */


unsigned long _DLL_InitTerm( unsigned long hModule, unsigned long ulFlag )

   {

   APIRET rc;

   /* If ulFlag is zero then initialization is required:                      */
   /*    If the shared memory pointer is NULL then the DLL is being loaded    */
   /*    for the first time so acquire the named shared storage for the       */
   /*    process control structures.  A linked list of process control        */
   /*    structures will be maintained.  Each time a new process loads this   */
   /*    DLL, a new process control structure is created and it is inserted   */
   /*    at the end of the list by calling DLLREGISTER.                       */
   /*                                                                         */
   /* If ulFlag is 1 then termination is required:                            */
   /*    Call DLLDEREGISTER which will remove the process control structure   */
   /*    and free the shared memory block from its virtual address space.     */


   switch( ulFlag )

      {

   case 0:

         if ( !ulProcessCount )

            {

            _rmem_init();

  /* Create the shared mutex semaphore.                             */

            if ( ( rc = DosCreateMutexSem( SHARED_SEMAPHORE_NAME,

                                           &hmtxSharedSem,

                                           0,

                                           FALSE ) ) != NO_ERROR )

               {

               printf( "DosCreateMutexSem rc = %lu\n", rc );

               return 0;

               }

            }

  /* Register the current process.                                     */


         if ( DLLREGISTER( ) )

            return 0;



         break;

      case 1:

  /* De-register the current process.                                  */



         if ( DLLDEREGISTER( ) )

            return 0;



         _rmem_term();



         break;



      default:

         return 0;

      }


   /* Indicate success.  Non-zero means success!!!                            */

   return 1;

   }


WriteYour Own _DLL_InitTerm Function