source: trunk/src/winmm/initterm.cpp

Last change on this file was 21916, checked in by dmik, 14 years ago

Merge branch gcc-kmk to trunk.

File size: 7.8 KB
RevLine 
[21841]1/* $Id: initterm.cpp,v 1.20 2001-09-05 10:30:39 bird Exp $
[6640]2 *
[6375]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
[7196]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
[6375]19#include <stdlib.h>
20#include <stdio.h>
21#include <string.h>
[21841]22#ifndef __GNUC__
[6375]23#include <builtin.h>
[21841]24#endif
[6375]25#include <misc.h> /*PLF Wed 98-03-18 23:19:26*/
26#include <odin.h>
27#include <win32type.h>
[7232]28#include <win32api.h>
[6375]29#include <winconst.h>
30#include <odinlx.h>
31#include <initdll.h>
32#include "auxiliary.h"
33#include "winmmtype.h"
34#include "waveoutbase.h"
[21720]35#include <win/options.h>
[21841]36#include "initterm.h"
[7232]37#include <custombuild.h>
[8472]38#include "mixer.h"
[6375]39
40#define DBG_LOCALLOG DBG_initterm
41#include "dbglocal.h"
42
43BOOL MULTIMEDIA_MciInit(void);
44BOOL MULTIMEDIA_CreateIData(HINSTANCE hinstDLL);
45void MULTIMEDIA_DeleteIData(void);
46
[21841]47extern "C" void IRTMidiShutdown(); // IRTMidi shutdown routine
[6375]48
[21841]49// Win32 resource table (produced by wrc)
50extern DWORD winmm_PEResTab;
51
[6375]52static HMODULE dllHandle = 0;
[7196]53static HMODULE MMPMLibraryHandle = 0;
[6375]54
[21841]55static const char *szBuggyAudio[] =
56{
57 "CWAUD",
58 "BSAUD",
59 "CRYSTAL"
[10569]60};
61
[8857]62BOOL fMMPMAvailable = TRUE;
[7196]63
64DWORD (APIENTRY *pfnmciSendCommand)(WORD wDeviceID,
[21841]65 WORD wMessage,
66 DWORD dwParam1,
67 PVOID dwParam2,
68 WORD wUserParm) = NULL;
[7196]69DWORD (APIENTRY *pfnmciGetErrorString)(DWORD dwError,
[21841]70 LPSTR lpstrBuffer,
71 WORD wLength) = NULL;
[7196]72
[7674]73void WIN32API DisableWaveAudio()
74{
[8857]75 fMMPMAvailable = FALSE;
[7674]76 pfnmciGetErrorString = NULL;
[8857]77 pfnmciSendCommand = NULL;
[7674]78}
[21841]79
[6375]80BOOL WINAPI LibMainWinmm(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
81{
[7196]82 static BOOL bInitDone = FALSE;
83 char szError[CCHMAXPATH];
[10569]84 char szPDDName[128];
[7232]85 HKEY hKey;
[6375]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);
[7196]107
[21720]108 if(fMMPMAvailable == TRUE)
[8857]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),
[21358]112 "MDM", &MMPMLibraryHandle) != NO_ERROR)
[7196]113 {
[8857]114 // this system has no MMPM :-(
[7196]115 fMMPMAvailable = FALSE;
[21720]116 }
[7196]117 else
118 {
[8857]119 /* detect if MMPM is available */
[7196]120 if (DosQueryProcAddr(MMPMLibraryHandle,
[8857]121 1, /* ORD_MCISENDCOMMAND */
[7196]122 NULL,
[8857]123 (PFN*)&pfnmciSendCommand) != NO_ERROR)
124 {
125 fMMPMAvailable = FALSE;
[21720]126 }
[8857]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));
[7196]144 }
145 }
[8857]146
[21720]147 if(fMMPMAvailable && RegOpenKeyA(HKEY_LOCAL_MACHINE, CUSTOM_BUILD_OPTIONS_KEY, &hKey) == 0)
[7232]148 {
149 DWORD dwSize, dwType;
150 DWORD dwFlag;
[7196]151
[7232]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 }
[10576]167 if(!fMMPMAvailable || OSLibGetAudioPDDName(szPDDName) == FALSE) {
[10569]168 fMMPMAvailable = FALSE;
169 }
[21720]170 else
[10569]171 {
172 // Test for buggy audio drivers to turn off audio automagically
[21720]173 for(int i=0;i<sizeof(szBuggyAudio)/sizeof(szBuggyAudio[0]);i++)
[10569]174 {
[10571]175 if(!strncmp(szPDDName, szBuggyAudio[i], strlen(szBuggyAudio[i]))) {
[10569]176 dprintf(("Detected driver %s -> turning off audio!!", szPDDName));
177 fMMPMAvailable = FALSE;
178 break;
179 }
180 }
181 }
[8472]182 mixerInit();
[6375]183 return TRUE;
184 }
185
186 case DLL_THREAD_ATTACH:
187 case DLL_THREAD_DETACH:
188 return TRUE;
189
190 case DLL_PROCESS_DETACH:
[9671]191 WaveInOut::shutdown();
[6375]192 MULTIMEDIA_DeleteIData();
[8510]193 auxOS2Close(); /* Close aux device if necessary */
194 IRTMidiShutdown; /* Shutdown RT Midi subsystem, if running. */
[7196]195
[8472]196 mixerExit();
[7196]197 if(MMPMLibraryHandle) DosFreeModule(MMPMLibraryHandle);
[6375]198 return TRUE;
199 }
200 return FALSE;
201}
202
[7196]203DWORD 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 }
[8568]213 USHORT sel = RestoreOS2FS();
[7196]214 DWORD ret = pfnmciSendCommand(wDeviceID, wMessage, dwParam1, dwParam2, wUserParm);
215 SetFS(sel);
216 return ret;
217}
[21841]218
[7196]219DWORD APIENTRY mymciGetErrorString(DWORD dwError,
220 LPSTR lpstrBuffer,
221 WORD wLength)
222{
223 if(pfnmciGetErrorString == NULL) {
224 DebugInt3();
225 return MCIERR_CANNOT_LOAD_DRIVER;
226 }
[8568]227 USHORT sel = RestoreOS2FS();
[7196]228 DWORD ret = pfnmciGetErrorString(dwError, lpstrBuffer, wLength);
229 SetFS(sel);
230 return ret;
231}
[21841]232
233ULONG 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
248void SYSTEM DLL_TermWinMM32(ULONG hModule)
249{
250 auxOS2Close(); /* SvL: Close aux device if necessary */
251
252 if(dllHandle)
253 UnregisterLxDll(dllHandle);
254}
255
256ULONG SYSTEM DLL_Init(ULONG hModule)
257{
258 if (DLL_InitDefault(hModule) == -1)
259 return -1;
260 return DLL_InitWinMM32(hModule);
261}
262
263void SYSTEM DLL_Term(ULONG hModule)
264{
265 DLL_TermWinMM32(hModule);
266 DLL_TermDefault(hModule);
267}
Note: See TracBrowser for help on using the repository browser.