1 | /* $Id: initwinmm.cpp,v 1.4 2001-10-24 22:47:41 sandervl Exp $
|
---|
2 | *
|
---|
3 | * WINMM DLL entry point
|
---|
4 | *
|
---|
5 | * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
|
---|
6 | * Copyright 1998 Peter Fitzsimmons
|
---|
7 | * Copyright 2000 Chris Wohlgemuth
|
---|
8 | *
|
---|
9 | *
|
---|
10 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
11 | *
|
---|
12 | */
|
---|
13 |
|
---|
14 | /*-------------------------------------------------------------*/
|
---|
15 | /* INITERM.C -- Source for a custom dynamic link library */
|
---|
16 | /* initialization and termination (_DLL_InitTerm) */
|
---|
17 | /* function. */
|
---|
18 | /* */
|
---|
19 | /* When called to perform initialization, this sample function */
|
---|
20 | /* gets storage for an array of integers, and initializes its */
|
---|
21 | /* elements with random integers. At termination time, it */
|
---|
22 | /* frees the array. Substitute your own special processing. */
|
---|
23 | /*-------------------------------------------------------------*/
|
---|
24 |
|
---|
25 |
|
---|
26 | /* Include files */
|
---|
27 | #define INCL_DOSMODULEMGR
|
---|
28 | #define INCL_DOSPROCESS
|
---|
29 | #define INCL_DOSSEMAPHORES
|
---|
30 | #define INCL_DOSERRORS
|
---|
31 | #define INCL_OS2MM
|
---|
32 | #include <os2wrap.h> //Odin32 OS/2 api wrappers
|
---|
33 | #include <os2mewrap.h> //Odin32 OS/2 MMPM/2 api wrappers
|
---|
34 | #include <stdlib.h>
|
---|
35 | #include <stdio.h>
|
---|
36 | #include <string.h>
|
---|
37 | #include <builtin.h>
|
---|
38 | #include <misc.h> /*PLF Wed 98-03-18 23:19:26*/
|
---|
39 | #include <odin.h>
|
---|
40 | #include <win32type.h>
|
---|
41 | #include <winconst.h>
|
---|
42 | #include <odinlx.h>
|
---|
43 | #include <initdll.h>
|
---|
44 | #include "auxiliary.h"
|
---|
45 | #include "winmmtype.h"
|
---|
46 | #include "waveoutbase.h"
|
---|
47 | #include <win\options.h>
|
---|
48 | #include "initwinmm.h"
|
---|
49 |
|
---|
50 | #define DBG_LOCALLOG DBG_initterm
|
---|
51 | #include "dbglocal.h"
|
---|
52 |
|
---|
53 | BOOL MULTIMEDIA_MciInit(void);
|
---|
54 | BOOL MULTIMEDIA_CreateIData(HINSTANCE hinstDLL);
|
---|
55 | void MULTIMEDIA_DeleteIData(void);
|
---|
56 |
|
---|
57 | extern "C" {
|
---|
58 | void IRTMidiShutdown(); // IRTMidi shutdown routine
|
---|
59 |
|
---|
60 | //Win32 resource table (produced by wrc)
|
---|
61 | extern DWORD winmm_PEResTab;
|
---|
62 | }
|
---|
63 | static HMODULE dllHandle = 0;
|
---|
64 | static HMODULE MMPMLibraryHandle = 0;
|
---|
65 |
|
---|
66 | BOOL fMMPMAvailable = FALSE;
|
---|
67 |
|
---|
68 | DWORD (APIENTRY *pfnmciSendCommand)(WORD wDeviceID,
|
---|
69 | WORD wMessage,
|
---|
70 | DWORD dwParam1,
|
---|
71 | PVOID dwParam2,
|
---|
72 | WORD wUserParm) = NULL;
|
---|
73 | DWORD (APIENTRY *pfnmciGetErrorString)(DWORD dwError,
|
---|
74 | LPSTR lpstrBuffer,
|
---|
75 | WORD wLength) = NULL;
|
---|
76 |
|
---|
77 | //******************************************************************************
|
---|
78 | //******************************************************************************
|
---|
79 | BOOL WINAPI LibMainWinmm(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
|
---|
80 | {
|
---|
81 | static BOOL bInitDone = FALSE;
|
---|
82 | char szError[CCHMAXPATH];
|
---|
83 |
|
---|
84 | switch (fdwReason)
|
---|
85 | {
|
---|
86 | case DLL_PROCESS_ATTACH:
|
---|
87 | {
|
---|
88 | if (!MULTIMEDIA_CreateIData(hinstDLL))
|
---|
89 | return FALSE;
|
---|
90 |
|
---|
91 | if (!bInitDone) { /* to be done only once */
|
---|
92 | if (!MULTIMEDIA_MciInit() /*|| !MMDRV_Init() */ ) {
|
---|
93 | MULTIMEDIA_DeleteIData();
|
---|
94 | return FALSE;
|
---|
95 | }
|
---|
96 | bInitDone = TRUE;
|
---|
97 | }
|
---|
98 | DWORD dwVolume;
|
---|
99 |
|
---|
100 | dwVolume = PROFILE_GetOdinIniInt(WINMM_SECTION, DEFVOL_KEY, 100);
|
---|
101 | dwVolume = (dwVolume*0xFFFF)/100;
|
---|
102 | dwVolume = (dwVolume << 16) | dwVolume;
|
---|
103 | WaveOut::setDefaultVolume(dwVolume);
|
---|
104 |
|
---|
105 | // try to load the MDM library, not MMPM directly!!!
|
---|
106 | if (DosLoadModule(szError, sizeof(szError),
|
---|
107 | "MDM.DLL", &MMPMLibraryHandle) != NO_ERROR)
|
---|
108 | {
|
---|
109 | // this system has no MMPM :-(
|
---|
110 | fMMPMAvailable = FALSE;
|
---|
111 | }
|
---|
112 | else
|
---|
113 | {
|
---|
114 | /* detect if MMPM is available */
|
---|
115 | if (DosQueryProcAddr(MMPMLibraryHandle,
|
---|
116 | 1, /* ORD_MCISENDCOMMAND */
|
---|
117 | NULL,
|
---|
118 | (PFN*)&pfnmciSendCommand) != NO_ERROR)
|
---|
119 | {
|
---|
120 | fMMPMAvailable = FALSE;
|
---|
121 | }
|
---|
122 | else
|
---|
123 | {
|
---|
124 | fMMPMAvailable = TRUE;
|
---|
125 | }
|
---|
126 |
|
---|
127 | /* see if we can get the address for the mciGetErrorString function */
|
---|
128 | if (fMMPMAvailable == TRUE)
|
---|
129 | {
|
---|
130 | if (DosQueryProcAddr(MMPMLibraryHandle,
|
---|
131 | 3, /* ORD_MCIGETERRORSTRING */
|
---|
132 | NULL,
|
---|
133 | (PFN*)&pfnmciGetErrorString) != NO_ERROR)
|
---|
134 | pfnmciGetErrorString = NULL;
|
---|
135 | }
|
---|
136 | dprintf(("MMPM/2 is available; hmod %x", MMPMLibraryHandle));
|
---|
137 | dprintf(("mciSendCommand %x", pfnmciSendCommand));
|
---|
138 | dprintf(("mciGetErrorString %x", pfnmciGetErrorString));
|
---|
139 | }
|
---|
140 |
|
---|
141 | return TRUE;
|
---|
142 | }
|
---|
143 |
|
---|
144 | case DLL_THREAD_ATTACH:
|
---|
145 | case DLL_THREAD_DETACH:
|
---|
146 | return TRUE;
|
---|
147 |
|
---|
148 | case DLL_PROCESS_DETACH:
|
---|
149 | MULTIMEDIA_DeleteIData();
|
---|
150 | auxOS2Close(); /* SvL: Close aux device if necessary */
|
---|
151 | IRTMidiShutdown; /* JT: Shutdown RT Midi subsystem, if running. */
|
---|
152 |
|
---|
153 | if(MMPMLibraryHandle) DosFreeModule(MMPMLibraryHandle);
|
---|
154 | return TRUE;
|
---|
155 | }
|
---|
156 | return FALSE;
|
---|
157 | }
|
---|
158 | /****************************************************************************/
|
---|
159 | /* _DLL_InitTerm is the function that gets called by the operating system */
|
---|
160 | /* loader when it loads and frees this DLL for each process that accesses */
|
---|
161 | /* this DLL. However, it only gets called the first time the DLL is loaded */
|
---|
162 | /* and the last time it is freed for a particular process. The system */
|
---|
163 | /* linkage convention MUST be used because the operating system loader is */
|
---|
164 | /* calling this function. */
|
---|
165 | /****************************************************************************/
|
---|
166 | ULONG APIENTRY inittermWinmm(ULONG hModule, ULONG ulFlag)
|
---|
167 | {
|
---|
168 | /*-------------------------------------------------------------------------*/
|
---|
169 | /* If ulFlag is zero then the DLL is being loaded so initialization should */
|
---|
170 | /* be performed. If ulFlag is 1 then the DLL is being freed so */
|
---|
171 | /* termination should be performed. */
|
---|
172 | /*-------------------------------------------------------------------------*/
|
---|
173 |
|
---|
174 | switch (ulFlag)
|
---|
175 | {
|
---|
176 | case 0 :
|
---|
177 | ParseLogStatusWINMM();
|
---|
178 |
|
---|
179 | dllHandle = RegisterLxDll(hModule, LibMainWinmm, (PVOID)&winmm_PEResTab);
|
---|
180 | if(dllHandle == 0)
|
---|
181 | return 0UL;/* Error */
|
---|
182 |
|
---|
183 | dprintf(("winmm init %s %s (%x)", __DATE__, __TIME__, inittermWinmm));
|
---|
184 | break;
|
---|
185 | case 1 :
|
---|
186 | auxOS2Close(); /* SvL: Close aux device if necessary */
|
---|
187 | if(dllHandle) {
|
---|
188 | UnregisterLxDll(dllHandle);
|
---|
189 | }
|
---|
190 | break;
|
---|
191 | default :
|
---|
192 | return 0UL;
|
---|
193 | }
|
---|
194 |
|
---|
195 | /***********************************************************/
|
---|
196 | /* A non-zero value must be returned to indicate success. */
|
---|
197 | /***********************************************************/
|
---|
198 | return 1UL;
|
---|
199 | }
|
---|
200 | //******************************************************************************
|
---|
201 | //******************************************************************************
|
---|
202 | DWORD APIENTRY mymciSendCommand(WORD wDeviceID,
|
---|
203 | WORD wMessage,
|
---|
204 | DWORD dwParam1,
|
---|
205 | PVOID dwParam2,
|
---|
206 | WORD wUserParm)
|
---|
207 | {
|
---|
208 | if(pfnmciSendCommand == NULL) {
|
---|
209 | DebugInt3();
|
---|
210 | return MCIERR_CANNOT_LOAD_DRIVER;
|
---|
211 | }
|
---|
212 | USHORT sel = GetFS();
|
---|
213 | DWORD ret = pfnmciSendCommand(wDeviceID, wMessage, dwParam1, dwParam2, wUserParm);
|
---|
214 | SetFS(sel);
|
---|
215 | return ret;
|
---|
216 | }
|
---|
217 | //******************************************************************************
|
---|
218 | //******************************************************************************
|
---|
219 | DWORD APIENTRY mymciGetErrorString(DWORD dwError,
|
---|
220 | LPSTR lpstrBuffer,
|
---|
221 | WORD wLength)
|
---|
222 | {
|
---|
223 | if(pfnmciGetErrorString == NULL) {
|
---|
224 | DebugInt3();
|
---|
225 | return MCIERR_CANNOT_LOAD_DRIVER;
|
---|
226 | }
|
---|
227 | USHORT sel = GetFS();
|
---|
228 | DWORD ret = pfnmciGetErrorString(dwError, lpstrBuffer, wLength);
|
---|
229 | SetFS(sel);
|
---|
230 | return ret;
|
---|
231 | }
|
---|
232 | //******************************************************************************
|
---|
233 | //******************************************************************************
|
---|