1 | /* $Id: initterm.cpp,v 1.20 2001-09-05 10:30:39 bird 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 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
10 | */
|
---|
11 |
|
---|
12 | #define INCL_DOSMODULEMGR
|
---|
13 | #define INCL_DOSPROCESS
|
---|
14 | #define INCL_DOSSEMAPHORES
|
---|
15 | #define INCL_DOSERRORS
|
---|
16 | #define INCL_OS2MM
|
---|
17 | #include <os2wrap.h> //Odin32 OS/2 api wrappers
|
---|
18 | #include <os2mewrap.h> //Odin32 OS/2 MMPM/2 api wrappers
|
---|
19 | #include <stdlib.h>
|
---|
20 | #include <stdio.h>
|
---|
21 | #include <string.h>
|
---|
22 | #ifndef __GNUC__
|
---|
23 | #include <builtin.h>
|
---|
24 | #endif
|
---|
25 | #include <misc.h> /*PLF Wed 98-03-18 23:19:26*/
|
---|
26 | #include <odin.h>
|
---|
27 | #include <win32type.h>
|
---|
28 | #include <win32api.h>
|
---|
29 | #include <winconst.h>
|
---|
30 | #include <odinlx.h>
|
---|
31 | #include <initdll.h>
|
---|
32 | #include "auxiliary.h"
|
---|
33 | #include "winmmtype.h"
|
---|
34 | #include "waveoutbase.h"
|
---|
35 | #include <win/options.h>
|
---|
36 | #include "initterm.h"
|
---|
37 | #include <custombuild.h>
|
---|
38 | #include "mixer.h"
|
---|
39 |
|
---|
40 | #define DBG_LOCALLOG DBG_initterm
|
---|
41 | #include "dbglocal.h"
|
---|
42 |
|
---|
43 | BOOL MULTIMEDIA_MciInit(void);
|
---|
44 | BOOL MULTIMEDIA_CreateIData(HINSTANCE hinstDLL);
|
---|
45 | void MULTIMEDIA_DeleteIData(void);
|
---|
46 |
|
---|
47 | extern "C" void IRTMidiShutdown(); // IRTMidi shutdown routine
|
---|
48 |
|
---|
49 | // Win32 resource table (produced by wrc)
|
---|
50 | extern DWORD winmm_PEResTab;
|
---|
51 |
|
---|
52 | static HMODULE dllHandle = 0;
|
---|
53 | static HMODULE MMPMLibraryHandle = 0;
|
---|
54 |
|
---|
55 | static const char *szBuggyAudio[] =
|
---|
56 | {
|
---|
57 | "CWAUD",
|
---|
58 | "BSAUD",
|
---|
59 | "CRYSTAL"
|
---|
60 | };
|
---|
61 |
|
---|
62 | BOOL fMMPMAvailable = TRUE;
|
---|
63 |
|
---|
64 | DWORD (APIENTRY *pfnmciSendCommand)(WORD wDeviceID,
|
---|
65 | WORD wMessage,
|
---|
66 | DWORD dwParam1,
|
---|
67 | PVOID dwParam2,
|
---|
68 | WORD wUserParm) = NULL;
|
---|
69 | DWORD (APIENTRY *pfnmciGetErrorString)(DWORD dwError,
|
---|
70 | LPSTR lpstrBuffer,
|
---|
71 | WORD wLength) = NULL;
|
---|
72 |
|
---|
73 | void WIN32API DisableWaveAudio()
|
---|
74 | {
|
---|
75 | fMMPMAvailable = FALSE;
|
---|
76 | pfnmciGetErrorString = NULL;
|
---|
77 | pfnmciSendCommand = NULL;
|
---|
78 | }
|
---|
79 |
|
---|
80 | BOOL WINAPI LibMainWinmm(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
|
---|
81 | {
|
---|
82 | static BOOL bInitDone = FALSE;
|
---|
83 | char szError[CCHMAXPATH];
|
---|
84 | char szPDDName[128];
|
---|
85 | HKEY hKey;
|
---|
86 |
|
---|
87 | switch (fdwReason)
|
---|
88 | {
|
---|
89 | case DLL_PROCESS_ATTACH:
|
---|
90 | {
|
---|
91 | if (!MULTIMEDIA_CreateIData(hinstDLL))
|
---|
92 | return FALSE;
|
---|
93 |
|
---|
94 | if (!bInitDone) { /* to be done only once */
|
---|
95 | if (!MULTIMEDIA_MciInit() /*|| !MMDRV_Init() */ ) {
|
---|
96 | MULTIMEDIA_DeleteIData();
|
---|
97 | return FALSE;
|
---|
98 | }
|
---|
99 | bInitDone = TRUE;
|
---|
100 | }
|
---|
101 | DWORD dwVolume;
|
---|
102 |
|
---|
103 | dwVolume = PROFILE_GetOdinIniInt(WINMM_SECTION, DEFVOL_KEY, 100);
|
---|
104 | dwVolume = (dwVolume*0xFFFF)/100;
|
---|
105 | dwVolume = (dwVolume << 16) | dwVolume;
|
---|
106 | WaveOut::setDefaultVolume(dwVolume);
|
---|
107 |
|
---|
108 | if(fMMPMAvailable == TRUE)
|
---|
109 | {//if audio access wasn't disabled already, check if mmpm2 is installed
|
---|
110 | // try to load the MDM library, not MMPM directly!!!
|
---|
111 | if (DosLoadModule(szError, sizeof(szError),
|
---|
112 | "MDM", &MMPMLibraryHandle) != NO_ERROR)
|
---|
113 | {
|
---|
114 | // this system has no MMPM :-(
|
---|
115 | fMMPMAvailable = FALSE;
|
---|
116 | }
|
---|
117 | else
|
---|
118 | {
|
---|
119 | /* detect if MMPM is available */
|
---|
120 | if (DosQueryProcAddr(MMPMLibraryHandle,
|
---|
121 | 1, /* ORD_MCISENDCOMMAND */
|
---|
122 | NULL,
|
---|
123 | (PFN*)&pfnmciSendCommand) != NO_ERROR)
|
---|
124 | {
|
---|
125 | fMMPMAvailable = FALSE;
|
---|
126 | }
|
---|
127 | else
|
---|
128 | {
|
---|
129 | fMMPMAvailable = TRUE;
|
---|
130 | }
|
---|
131 |
|
---|
132 | /* see if we can get the address for the mciGetErrorString function */
|
---|
133 | if (fMMPMAvailable == TRUE)
|
---|
134 | {
|
---|
135 | if (DosQueryProcAddr(MMPMLibraryHandle,
|
---|
136 | 3, /* ORD_MCIGETERRORSTRING */
|
---|
137 | NULL,
|
---|
138 | (PFN*)&pfnmciGetErrorString) != NO_ERROR)
|
---|
139 | pfnmciGetErrorString = NULL;
|
---|
140 | }
|
---|
141 | dprintf(("MMPM/2 is available; hmod %x", MMPMLibraryHandle));
|
---|
142 | dprintf(("mciSendCommand %x", pfnmciSendCommand));
|
---|
143 | dprintf(("mciGetErrorString %x", pfnmciGetErrorString));
|
---|
144 | }
|
---|
145 | }
|
---|
146 |
|
---|
147 | if(fMMPMAvailable && RegOpenKeyA(HKEY_LOCAL_MACHINE, CUSTOM_BUILD_OPTIONS_KEY, &hKey) == 0)
|
---|
148 | {
|
---|
149 | DWORD dwSize, dwType;
|
---|
150 | DWORD dwFlag;
|
---|
151 |
|
---|
152 | dwSize = sizeof(dwFlag);
|
---|
153 | LONG rc = RegQueryValueExA(hKey, DISABLE_AUDIO_KEY,
|
---|
154 | NULL, &dwType,
|
---|
155 | (LPBYTE)&dwFlag,
|
---|
156 | &dwSize);
|
---|
157 |
|
---|
158 | if(rc == 0 && dwType == REG_DWORD) {
|
---|
159 | if(dwFlag) {
|
---|
160 | fMMPMAvailable = FALSE;
|
---|
161 | pfnmciGetErrorString = NULL;
|
---|
162 | pfnmciSendCommand = NULL;
|
---|
163 | }
|
---|
164 | }
|
---|
165 | RegCloseKey(hKey);
|
---|
166 | }
|
---|
167 | if(!fMMPMAvailable || OSLibGetAudioPDDName(szPDDName) == FALSE) {
|
---|
168 | fMMPMAvailable = FALSE;
|
---|
169 | }
|
---|
170 | else
|
---|
171 | {
|
---|
172 | // Test for buggy audio drivers to turn off audio automagically
|
---|
173 | for(int i=0;i<sizeof(szBuggyAudio)/sizeof(szBuggyAudio[0]);i++)
|
---|
174 | {
|
---|
175 | if(!strncmp(szPDDName, szBuggyAudio[i], strlen(szBuggyAudio[i]))) {
|
---|
176 | dprintf(("Detected driver %s -> turning off audio!!", szPDDName));
|
---|
177 | fMMPMAvailable = FALSE;
|
---|
178 | break;
|
---|
179 | }
|
---|
180 | }
|
---|
181 | }
|
---|
182 | mixerInit();
|
---|
183 | return TRUE;
|
---|
184 | }
|
---|
185 |
|
---|
186 | case DLL_THREAD_ATTACH:
|
---|
187 | case DLL_THREAD_DETACH:
|
---|
188 | return TRUE;
|
---|
189 |
|
---|
190 | case DLL_PROCESS_DETACH:
|
---|
191 | WaveInOut::shutdown();
|
---|
192 | MULTIMEDIA_DeleteIData();
|
---|
193 | auxOS2Close(); /* Close aux device if necessary */
|
---|
194 | IRTMidiShutdown; /* Shutdown RT Midi subsystem, if running. */
|
---|
195 |
|
---|
196 | mixerExit();
|
---|
197 | if(MMPMLibraryHandle) DosFreeModule(MMPMLibraryHandle);
|
---|
198 | return TRUE;
|
---|
199 | }
|
---|
200 | return FALSE;
|
---|
201 | }
|
---|
202 |
|
---|
203 | DWORD APIENTRY mymciSendCommand(WORD wDeviceID,
|
---|
204 | WORD wMessage,
|
---|
205 | DWORD dwParam1,
|
---|
206 | PVOID dwParam2,
|
---|
207 | WORD wUserParm)
|
---|
208 | {
|
---|
209 | if(pfnmciSendCommand == NULL) {
|
---|
210 | DebugInt3();
|
---|
211 | return MCIERR_CANNOT_LOAD_DRIVER;
|
---|
212 | }
|
---|
213 | USHORT sel = RestoreOS2FS();
|
---|
214 | DWORD ret = pfnmciSendCommand(wDeviceID, wMessage, dwParam1, dwParam2, wUserParm);
|
---|
215 | SetFS(sel);
|
---|
216 | return ret;
|
---|
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 = RestoreOS2FS();
|
---|
228 | DWORD ret = pfnmciGetErrorString(dwError, lpstrBuffer, wLength);
|
---|
229 | SetFS(sel);
|
---|
230 | return ret;
|
---|
231 | }
|
---|
232 |
|
---|
233 | ULONG SYSTEM DLL_InitWinMM32(ULONG hModule)
|
---|
234 | {
|
---|
235 | CheckVersionFromHMOD(PE2LX_VERSION, hModule); /*PLF Wed 98-03-18 05:28:48*/
|
---|
236 |
|
---|
237 | ParseLogStatusWINMM();
|
---|
238 |
|
---|
239 | dllHandle = RegisterLxDll(hModule, LibMainWinmm, (PVOID)&winmm_PEResTab);
|
---|
240 | if (dllHandle == 0)
|
---|
241 | return -1;
|
---|
242 |
|
---|
243 | dprintf(("winmm init %s %s (%x)", __DATE__, __TIME__, DLL_InitWinMM32));
|
---|
244 |
|
---|
245 | return 0;
|
---|
246 | }
|
---|
247 |
|
---|
248 | void SYSTEM DLL_TermWinMM32(ULONG hModule)
|
---|
249 | {
|
---|
250 | auxOS2Close(); /* SvL: Close aux device if necessary */
|
---|
251 |
|
---|
252 | if(dllHandle)
|
---|
253 | UnregisterLxDll(dllHandle);
|
---|
254 | }
|
---|
255 |
|
---|
256 | ULONG SYSTEM DLL_Init(ULONG hModule)
|
---|
257 | {
|
---|
258 | if (DLL_InitDefault(hModule) == -1)
|
---|
259 | return -1;
|
---|
260 | return DLL_InitWinMM32(hModule);
|
---|
261 | }
|
---|
262 |
|
---|
263 | void SYSTEM DLL_Term(ULONG hModule)
|
---|
264 | {
|
---|
265 | DLL_TermWinMM32(hModule);
|
---|
266 | DLL_TermDefault(hModule);
|
---|
267 | }
|
---|