| 1 | /* $Id: initterm.cpp,v 1.34 2003-01-21 11:22:08 sandervl Exp $ */ | 
|---|
| 2 | /* | 
|---|
| 3 | * USER32 DLL entry point | 
|---|
| 4 | * | 
|---|
| 5 | * Copyright 1998 Sander van Leeuwen | 
|---|
| 6 | * Copyright 1998 Peter Fitzsimmons | 
|---|
| 7 | * | 
|---|
| 8 | * | 
|---|
| 9 | * Project Odin Software License can be found in LICENSE.TXT | 
|---|
| 10 | * | 
|---|
| 11 | */ | 
|---|
| 12 |  | 
|---|
| 13 | /*-------------------------------------------------------------*/ | 
|---|
| 14 | /* INITERM.C -- Source for a custom dynamic link library       */ | 
|---|
| 15 | /*              initialization and termination (_DLL_InitTerm) */ | 
|---|
| 16 | /*              function.                                      */ | 
|---|
| 17 | /*                                                             */ | 
|---|
| 18 | /* When called to perform initialization, this sample function */ | 
|---|
| 19 | /* gets storage for an array of integers, and initializes its  */ | 
|---|
| 20 | /* elements with random integers.  At termination time, it     */ | 
|---|
| 21 | /* frees the array.  Substitute your own special processing.   */ | 
|---|
| 22 | /*-------------------------------------------------------------*/ | 
|---|
| 23 |  | 
|---|
| 24 |  | 
|---|
| 25 | /* Include files */ | 
|---|
| 26 | #define  INCL_DOSMODULEMGR | 
|---|
| 27 | #define  INCL_DOSPROCESS | 
|---|
| 28 | #define  INCL_DOSSEMAPHORES | 
|---|
| 29 | #define  INCL_DOSMISC | 
|---|
| 30 | #include <os2wrap.h>    //Odin32 OS/2 api wrappers | 
|---|
| 31 | #include <stdlib.h> | 
|---|
| 32 | #include <stdio.h> | 
|---|
| 33 | #include <string.h> | 
|---|
| 34 | #include <odin.h> | 
|---|
| 35 | #include <misc.h>       /*PLF Wed  98-03-18 23:18:29*/ | 
|---|
| 36 | #include <win32type.h> | 
|---|
| 37 | #include <win32api.h> | 
|---|
| 38 | #include <winconst.h> | 
|---|
| 39 | #include <odinlx.h> | 
|---|
| 40 | #include "initterm.h" | 
|---|
| 41 | #include <exitlist.h> | 
|---|
| 42 | #include <initdll.h> | 
|---|
| 43 |  | 
|---|
| 44 | #define DBG_LOCALLOG    DBG_initterm | 
|---|
| 45 | #include "dbglocal.h" | 
|---|
| 46 |  | 
|---|
| 47 | /*-------------------------------------------------------------------*/ | 
|---|
| 48 | /* A clean up routine registered with DosExitList must be used if    */ | 
|---|
| 49 | /* runtime calls are required and the runtime is dynamically linked. */ | 
|---|
| 50 | /* This will guarantee that this clean up routine is run before the  */ | 
|---|
| 51 | /* library DLL is terminated.                                        */ | 
|---|
| 52 | /*-------------------------------------------------------------------*/ | 
|---|
| 53 | static void APIENTRY cleanup(ULONG reason); | 
|---|
| 54 |  | 
|---|
| 55 | BOOL  fVersionWarp3 = FALSE; | 
|---|
| 56 |  | 
|---|
| 57 | /****************************************************************************/ | 
|---|
| 58 | /* _DLL_InitTerm is the function that gets called by the operating system   */ | 
|---|
| 59 | /* loader when it loads and frees this DLL for each process that accesses   */ | 
|---|
| 60 | /* this DLL.  However, it only gets called the first time the DLL is loaded */ | 
|---|
| 61 | /* and the last time it is freed for a particular process.  The system      */ | 
|---|
| 62 | /* linkage convention MUST be used because the operating system loader is   */ | 
|---|
| 63 | /* calling this function.                                                   */ | 
|---|
| 64 | /****************************************************************************/ | 
|---|
| 65 | ULONG DLLENTRYPOINT_CCONV DLLENTRYPOINT_NAME(ULONG hModule, ULONG ulFlag) | 
|---|
| 66 | { | 
|---|
| 67 | size_t i; | 
|---|
| 68 | APIRET rc; | 
|---|
| 69 | ULONG  version[2]; | 
|---|
| 70 |  | 
|---|
| 71 | /*-------------------------------------------------------------------------*/ | 
|---|
| 72 | /* If ulFlag is zero then the DLL is being loaded so initialization should */ | 
|---|
| 73 | /* be performed.  If ulFlag is 1 then the DLL is being freed so            */ | 
|---|
| 74 | /* termination should be performed.                                        */ | 
|---|
| 75 | /*-------------------------------------------------------------------------*/ | 
|---|
| 76 |  | 
|---|
| 77 | switch (ulFlag) { | 
|---|
| 78 | case 0 : | 
|---|
| 79 | ctordtorInit(); | 
|---|
| 80 |  | 
|---|
| 81 | rc = DosQuerySysInfo(QSV_VERSION_MAJOR, QSV_VERSION_MINOR, version, sizeof(version)); | 
|---|
| 82 | if(rc == 0){ | 
|---|
| 83 | if(version[0] >= 20 && version[1] <= 30) { | 
|---|
| 84 | fVersionWarp3 = TRUE; | 
|---|
| 85 | } | 
|---|
| 86 | } | 
|---|
| 87 |  | 
|---|
| 88 | /*******************************************************************/ | 
|---|
| 89 | /* A DosExitList routine must be used to clean up if runtime calls */ | 
|---|
| 90 | /* are required and the runtime is dynamically linked.             */ | 
|---|
| 91 | /*******************************************************************/ | 
|---|
| 92 |  | 
|---|
| 93 | rc = DosExitList(EXITLIST_USER32|EXLST_ADD, cleanup); | 
|---|
| 94 | if(rc) | 
|---|
| 95 | return 0UL; | 
|---|
| 96 |  | 
|---|
| 97 | rc = inittermUser32(hModule, ulFlag); | 
|---|
| 98 | break; | 
|---|
| 99 | case 1 : | 
|---|
| 100 | rc = inittermUser32(hModule, ulFlag); | 
|---|
| 101 | break; | 
|---|
| 102 | default  : | 
|---|
| 103 | return 0UL; | 
|---|
| 104 | } | 
|---|
| 105 |  | 
|---|
| 106 | /***********************************************************/ | 
|---|
| 107 | /* A non-zero value must be returned to indicate success.  */ | 
|---|
| 108 | /***********************************************************/ | 
|---|
| 109 | return rc; | 
|---|
| 110 | } | 
|---|
| 111 |  | 
|---|
| 112 | static void APIENTRY cleanup(ULONG ulReason) | 
|---|
| 113 | { | 
|---|
| 114 | cleanupUser32(ulReason); | 
|---|
| 115 | ctordtorTerm(); | 
|---|
| 116 |  | 
|---|
| 117 | DosExitList(EXLST_EXIT, cleanup); | 
|---|
| 118 | } | 
|---|
| 119 |  | 
|---|