| 1 | /* $Id: initterm.cpp,v 1.11 2000-12-03 22:18:17 sandervl Exp $ */ | 
|---|
| 2 |  | 
|---|
| 3 | /* | 
|---|
| 4 | * WINMM DLL entry point | 
|---|
| 5 | * | 
|---|
| 6 | * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl) | 
|---|
| 7 | * Copyright 1998 Peter Fitzsimmons | 
|---|
| 8 | * Copyright 2000 Chris Wohlgemuth | 
|---|
| 9 | * | 
|---|
| 10 | * | 
|---|
| 11 | * Project Odin Software License can be found in LICENSE.TXT | 
|---|
| 12 | * | 
|---|
| 13 | */ | 
|---|
| 14 |  | 
|---|
| 15 | /*-------------------------------------------------------------*/ | 
|---|
| 16 | /* INITERM.C -- Source for a custom dynamic link library       */ | 
|---|
| 17 | /*              initialization and termination (_DLL_InitTerm) */ | 
|---|
| 18 | /*              function.                                      */ | 
|---|
| 19 | /*                                                             */ | 
|---|
| 20 | /* When called to perform initialization, this sample function */ | 
|---|
| 21 | /* gets storage for an array of integers, and initializes its  */ | 
|---|
| 22 | /* elements with random integers.  At termination time, it     */ | 
|---|
| 23 | /* frees the array.  Substitute your own special processing.   */ | 
|---|
| 24 | /*-------------------------------------------------------------*/ | 
|---|
| 25 |  | 
|---|
| 26 |  | 
|---|
| 27 | /* Include files */ | 
|---|
| 28 | #define  INCL_DOSMODULEMGR | 
|---|
| 29 | #define  INCL_DOSPROCESS | 
|---|
| 30 | #include <os2wrap.h>    //Odin32 OS/2 api wrappers | 
|---|
| 31 | #include <stdlib.h> | 
|---|
| 32 | #include <stdio.h> | 
|---|
| 33 | #include <string.h> | 
|---|
| 34 | #include <builtin.h> | 
|---|
| 35 | #include <misc.h>       /*PLF Wed  98-03-18 23:19:26*/ | 
|---|
| 36 | #include <odin.h> | 
|---|
| 37 | #include <win32type.h> | 
|---|
| 38 | #include <winconst.h> | 
|---|
| 39 | #include <odinlx.h> | 
|---|
| 40 | #include "auxiliary.h" | 
|---|
| 41 |  | 
|---|
| 42 | #define DBG_LOCALLOG    DBG_initterm | 
|---|
| 43 | #include "dbglocal.h" | 
|---|
| 44 |  | 
|---|
| 45 | BOOL MULTIMEDIA_MciInit(void); | 
|---|
| 46 | BOOL    MULTIMEDIA_CreateIData(HINSTANCE hinstDLL); | 
|---|
| 47 | void MULTIMEDIA_DeleteIData(void); | 
|---|
| 48 |  | 
|---|
| 49 | extern "C" { | 
|---|
| 50 | void IRTMidiShutdown();  // IRTMidi shutdown routine | 
|---|
| 51 | void CDECL _ctordtorInit( void ); | 
|---|
| 52 | void CDECL _ctordtorTerm( void ); | 
|---|
| 53 |  | 
|---|
| 54 |  | 
|---|
| 55 | //Win32 resource table (produced by wrc) | 
|---|
| 56 | extern DWORD _Resource_PEResTab; | 
|---|
| 57 | } | 
|---|
| 58 | static HMODULE dllHandle = 0; | 
|---|
| 59 |  | 
|---|
| 60 | //****************************************************************************** | 
|---|
| 61 | //****************************************************************************** | 
|---|
| 62 | BOOL WINAPI LibMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad) | 
|---|
| 63 | { | 
|---|
| 64 | static BOOL                   bInitDone = FALSE; | 
|---|
| 65 |  | 
|---|
| 66 | switch (fdwReason) | 
|---|
| 67 | { | 
|---|
| 68 | case DLL_PROCESS_ATTACH: | 
|---|
| 69 | if (!MULTIMEDIA_CreateIData(hinstDLL)) | 
|---|
| 70 | return FALSE; | 
|---|
| 71 |  | 
|---|
| 72 | if (!bInitDone) { /* to be done only once */ | 
|---|
| 73 | if (!MULTIMEDIA_MciInit() /*|| !MMDRV_Init() */ ) { | 
|---|
| 74 | MULTIMEDIA_DeleteIData(); | 
|---|
| 75 | return FALSE; | 
|---|
| 76 | } | 
|---|
| 77 | bInitDone = TRUE; | 
|---|
| 78 | } | 
|---|
| 79 |  | 
|---|
| 80 | return TRUE; | 
|---|
| 81 |  | 
|---|
| 82 | case DLL_THREAD_ATTACH: | 
|---|
| 83 | case DLL_THREAD_DETACH: | 
|---|
| 84 | return TRUE; | 
|---|
| 85 |  | 
|---|
| 86 | case DLL_PROCESS_DETACH: | 
|---|
| 87 | MULTIMEDIA_DeleteIData(); | 
|---|
| 88 | auxOS2Close(); /* SvL: Close aux device if necessary */ | 
|---|
| 89 | IRTMidiShutdown;  /* JT: Shutdown RT Midi subsystem, if running. */ | 
|---|
| 90 | _ctordtorTerm(); | 
|---|
| 91 | return TRUE; | 
|---|
| 92 | } | 
|---|
| 93 | return FALSE; | 
|---|
| 94 | } | 
|---|
| 95 | /****************************************************************************/ | 
|---|
| 96 | /* _DLL_InitTerm is the function that gets called by the operating system   */ | 
|---|
| 97 | /* loader when it loads and frees this DLL for each process that accesses   */ | 
|---|
| 98 | /* this DLL.  However, it only gets called the first time the DLL is loaded */ | 
|---|
| 99 | /* and the last time it is freed for a particular process.  The system      */ | 
|---|
| 100 | /* linkage convention MUST be used because the operating system loader is   */ | 
|---|
| 101 | /* calling this function.                                                   */ | 
|---|
| 102 | /****************************************************************************/ | 
|---|
| 103 | unsigned long _System _DLL_InitTerm(unsigned long hModule, unsigned long | 
|---|
| 104 | ulFlag) | 
|---|
| 105 | { | 
|---|
| 106 | size_t i; | 
|---|
| 107 | APIRET rc; | 
|---|
| 108 |  | 
|---|
| 109 | /*-------------------------------------------------------------------------*/ | 
|---|
| 110 | /* If ulFlag is zero then the DLL is being loaded so initialization should */ | 
|---|
| 111 | /* be performed.  If ulFlag is 1 then the DLL is being freed so            */ | 
|---|
| 112 | /* termination should be performed.                                        */ | 
|---|
| 113 | /*-------------------------------------------------------------------------*/ | 
|---|
| 114 |  | 
|---|
| 115 | switch (ulFlag) { | 
|---|
| 116 | case 0 : | 
|---|
| 117 | _ctordtorInit(); | 
|---|
| 118 |  | 
|---|
| 119 | ParseLogStatus(); | 
|---|
| 120 |  | 
|---|
| 121 | CheckVersionFromHMOD(PE2LX_VERSION, hModule); /*PLF Wed  98-03-18 05:28:48*/ | 
|---|
| 122 |  | 
|---|
| 123 | dllHandle = RegisterLxDll(hModule, LibMain, (PVOID)&_Resource_PEResTab); | 
|---|
| 124 | if(dllHandle == 0) | 
|---|
| 125 | return 0UL;/* Error */ | 
|---|
| 126 |  | 
|---|
| 127 | break; | 
|---|
| 128 | case 1 : | 
|---|
| 129 | auxOS2Close(); /* SvL: Close aux device if necessary */ | 
|---|
| 130 | if(dllHandle) { | 
|---|
| 131 | UnregisterLxDll(dllHandle); | 
|---|
| 132 | } | 
|---|
| 133 | break; | 
|---|
| 134 | default  : | 
|---|
| 135 | return 0UL; | 
|---|
| 136 | } | 
|---|
| 137 |  | 
|---|
| 138 | /***********************************************************/ | 
|---|
| 139 | /* A non-zero value must be returned to indicate success.  */ | 
|---|
| 140 | /***********************************************************/ | 
|---|
| 141 | return 1UL; | 
|---|
| 142 | } | 
|---|
| 143 | //****************************************************************************** | 
|---|
| 144 | //****************************************************************************** | 
|---|
| 145 |  | 
|---|
| 146 |  | 
|---|
| 147 |  | 
|---|