home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sompar.zip / SOM / INITTERM.C < prev    next >
C/C++ Source or Header  |  1994-01-06  |  5KB  |  146 lines

  1. /* @(#) somx/initterm.c 2.2 6/2/93 01:18:05 [6/9/93 16:18:32] */
  2.  
  3. /*
  4.  * 96F8647, 96F8648 (C) Copyright IBM Corp. 1992, 1993
  5.  * All Rights Reserved
  6.  * Licensed Materials - Property of IBM
  7.  *
  8.  * DISCLAIMER OF WARRANTIES.
  9.  * The following [enclosed] code is sample code created by IBM
  10.  * Corporation. This sample code is not part of any standard or IBM
  11.  * product and is provided to you solely for the purpose of assisting
  12.  * you in the development of your applications.  The code is provided
  13.  * "AS IS". IBM MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT
  14.  * NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  15.  * FOR A PARTICULAR PURPOSE, REGARDING THE FUNCTION OR PERFORMANCE OF
  16.  * THIS CODE.  IBM shall not be liable for any damages arising out of
  17.  * your use of the sample code, even if they have been advised of the
  18.  * possibility of such damages.
  19.  *
  20.  * DISTRIBUTION.
  21.  * This sample code can be freely distributed, copied, altered, and
  22.  * incorporated into other software, provided that it bears the above
  23.  * Copyright notice and DISCLAIMER intact.
  24.  */
  25.  
  26.  
  27. #define INCL_DOSMODULEMGR
  28. #define INCL_DOSPROCESS
  29. #include <os2.h>
  30. #include <stdlib.h>
  31. #include <stdio.h>
  32. #include <string.h>
  33.  
  34. #define STATIC_LINK
  35.  
  36.  
  37. extern long SOMD_DebugFlag;
  38. extern long SOMD_TraceLevel;
  39.  
  40. // If you want to include DSOM tracing uncomment the following #define
  41.  
  42. // #define DSOM_TRACING_ENABLE    
  43.  
  44.  
  45.  
  46. /* _CRT_init is the C run-time environment initialization function.  It   */
  47. /* will return 0 to indicate success and -1 to indicate failure.          */
  48.  
  49. int _CRT_init( void );
  50.  
  51. #ifdef STATIC_LINK
  52. /* _CRT_term is the C run-time environment termination function.  It      */
  53. /* only needs to be called when the C run-time functions are statically   */
  54. /* linked.                                                                */
  55.  
  56. void _CRT_term( void );
  57. #else
  58. /* A clean up routine registered with DosExitList must be used if runtime */
  59. /* calls are required and the runtime is dynamically linked.  This will   */
  60. /* guarantee that this clean up routine is run before the library DLL is  */
  61. /* terminated.                                                            */
  62.  
  63. static void _System cleanup( ULONG ulReason );
  64. #endif
  65.  
  66. /* _DLL_InitTerm is the function that gets called by the operating system */
  67. /* loader when it loads and frees this DLL for each process that accesses */
  68. /* this DLL.  However, it only gets called the first time the DLL is      */
  69. /* loaded and the last time it is freed for a particular process.  The    */
  70. /* system linkage convention MUST be used because the operating system    */
  71. /* loader is calling this function.                                       */
  72.  
  73. unsigned long _System _DLL_InitTerm( unsigned long hModule,
  74.                      unsigned long ulFlag )
  75.    /* If ulFlag is zero then the DLL is being loaded so initialization */
  76.    /* should be performed.  If ulFlag is 1 then the DLL is being freed */
  77.    /* so termination should be performed.                              */
  78.  
  79.    switch( ulFlag )
  80.       {
  81.       case 0:
  82.          /* The C run-time environment initialization function must be */
  83.          /* called before any calls to C run-time functions that are   */
  84.      /* not inlined.                                               */
  85.  
  86.          if ( _CRT_init( ) == -1 )
  87.             return 0UL;
  88.  
  89.       #ifndef STATIC_LINK
  90.          /* A DosExitList routine must be used to clean up if runtime */
  91.          /* call are required and the runtime is dynamically linked.  */
  92.  
  93.          if ( rc = DosExitList( 0x0000FF00 | EXLST_ADD, cleanup ) )
  94.             printf( "DosExitList returned %lu\n", rc );
  95.       #endif
  96.  
  97.          /**************************************************/
  98.          /* place DLL initialization customization here    */
  99.          /**************************************************/
  100.  
  101.        #ifdef DSOM_TRACING_ENABLE    
  102.             SOMD_TraceLevel = 1;
  103.             SOMD_DebugFlag = 1;
  104.         #endif
  105.  
  106.  
  107.          break;
  108.  
  109.       case 1:
  110.       #ifdef STATIC_LINK
  111.  
  112.          /**************************************************/
  113.          /* place DLL termination customization here       */
  114.          /**************************************************/
  115.  
  116.          _CRT_term( );
  117.       #endif
  118.          break;
  119.  
  120.       default:
  121.          return 0UL; /* indicates failure */
  122.       }
  123.  
  124.    /* A non-zero value must be returned to indicate success. */
  125.  
  126.    return 1UL;
  127.    }
  128.  
  129. #ifndef STATIC_LINK
  130.  
  131. static void cleanup( ULONG ulReason )
  132. {
  133.    if ( !ulReason )
  134.       {
  135.          /**************************************************/
  136.          /* place DLL termination customization here       */
  137.          /**************************************************/
  138.       }
  139.  
  140.    DosExitList( EXLST_EXIT, cleanup );
  141.  
  142.    return;
  143. }
  144. #endif
  145.