source: trunk/src/winmm/initwinmm.cpp@ 8857

Last change on this file since 8857 was 8857, checked in by sandervl, 23 years ago

Changed init order; do not check for MMPM2 presence if wave audio was already disabled

File size: 9.6 KB
Line 
1/* $Id: initwinmm.cpp,v 1.10 2002-07-12 08:59:24 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 <win32api.h>
42#include <winconst.h>
43#include <odinlx.h>
44#include <initdll.h>
45#include "auxiliary.h"
46#include "winmmtype.h"
47#include "waveoutbase.h"
48#include <win\options.h>
49#include "initwinmm.h"
50#include <custombuild.h>
51#include "mixer.h"
52
53#define DBG_LOCALLOG DBG_initterm
54#include "dbglocal.h"
55
56BOOL MULTIMEDIA_MciInit(void);
57BOOL MULTIMEDIA_CreateIData(HINSTANCE hinstDLL);
58void MULTIMEDIA_DeleteIData(void);
59
60extern "C" {
61void IRTMidiShutdown(); // IRTMidi shutdown routine
62
63 //Win32 resource table (produced by wrc)
64 extern DWORD winmm_PEResTab;
65}
66static HMODULE dllHandle = 0;
67static HMODULE MMPMLibraryHandle = 0;
68
69BOOL fMMPMAvailable = TRUE;
70
71DWORD (APIENTRY *pfnmciSendCommand)(WORD wDeviceID,
72 WORD wMessage,
73 DWORD dwParam1,
74 PVOID dwParam2,
75 WORD wUserParm) = NULL;
76DWORD (APIENTRY *pfnmciGetErrorString)(DWORD dwError,
77 LPSTR lpstrBuffer,
78 WORD wLength) = NULL;
79
80//******************************************************************************
81//******************************************************************************
82void WIN32API DisableWaveAudio()
83{
84 fMMPMAvailable = FALSE;
85 pfnmciGetErrorString = NULL;
86 pfnmciSendCommand = NULL;
87}
88//******************************************************************************
89//******************************************************************************
90BOOL WINAPI LibMainWinmm(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
91{
92 static BOOL bInitDone = FALSE;
93 char szError[CCHMAXPATH];
94 HKEY hKey;
95
96 switch (fdwReason)
97 {
98 case DLL_PROCESS_ATTACH:
99 {
100 if (!MULTIMEDIA_CreateIData(hinstDLL))
101 return FALSE;
102
103 if (!bInitDone) { /* to be done only once */
104 if (!MULTIMEDIA_MciInit() /*|| !MMDRV_Init() */ ) {
105 MULTIMEDIA_DeleteIData();
106 return FALSE;
107 }
108 bInitDone = TRUE;
109 }
110 DWORD dwVolume;
111
112 dwVolume = PROFILE_GetOdinIniInt(WINMM_SECTION, DEFVOL_KEY, 100);
113 dwVolume = (dwVolume*0xFFFF)/100;
114 dwVolume = (dwVolume << 16) | dwVolume;
115 WaveOut::setDefaultVolume(dwVolume);
116
117 if(fMMPMAvailable == TRUE)
118 {//if audio access wasn't disabled already, check if mmpm2 is installed
119 // try to load the MDM library, not MMPM directly!!!
120 if (DosLoadModule(szError, sizeof(szError),
121 "MDM.DLL", &MMPMLibraryHandle) != NO_ERROR)
122 {
123 // this system has no MMPM :-(
124 fMMPMAvailable = FALSE;
125 }
126 else
127 {
128 /* detect if MMPM is available */
129 if (DosQueryProcAddr(MMPMLibraryHandle,
130 1, /* ORD_MCISENDCOMMAND */
131 NULL,
132 (PFN*)&pfnmciSendCommand) != NO_ERROR)
133 {
134 fMMPMAvailable = FALSE;
135 }
136 else
137 {
138 fMMPMAvailable = TRUE;
139 }
140
141 /* see if we can get the address for the mciGetErrorString function */
142 if (fMMPMAvailable == TRUE)
143 {
144 if (DosQueryProcAddr(MMPMLibraryHandle,
145 3, /* ORD_MCIGETERRORSTRING */
146 NULL,
147 (PFN*)&pfnmciGetErrorString) != NO_ERROR)
148 pfnmciGetErrorString = NULL;
149 }
150 dprintf(("MMPM/2 is available; hmod %x", MMPMLibraryHandle));
151 dprintf(("mciSendCommand %x", pfnmciSendCommand));
152 dprintf(("mciGetErrorString %x", pfnmciGetErrorString));
153 }
154 }
155
156 if(fMMPMAvailable && RegOpenKeyA(HKEY_LOCAL_MACHINE, CUSTOM_BUILD_OPTIONS_KEY, &hKey) == 0)
157 {
158 DWORD dwSize, dwType;
159 DWORD dwFlag;
160
161 dwSize = sizeof(dwFlag);
162 LONG rc = RegQueryValueExA(hKey, DISABLE_AUDIO_KEY,
163 NULL, &dwType,
164 (LPBYTE)&dwFlag,
165 &dwSize);
166
167 if(rc == 0 && dwType == REG_DWORD) {
168 if(dwFlag) {
169 fMMPMAvailable = FALSE;
170 pfnmciGetErrorString = NULL;
171 pfnmciSendCommand = NULL;
172 }
173 }
174 RegCloseKey(hKey);
175 }
176 mixerInit();
177 return TRUE;
178 }
179
180 case DLL_THREAD_ATTACH:
181 case DLL_THREAD_DETACH:
182 return TRUE;
183
184 case DLL_PROCESS_DETACH:
185 MULTIMEDIA_DeleteIData();
186 auxOS2Close(); /* Close aux device if necessary */
187 IRTMidiShutdown; /* Shutdown RT Midi subsystem, if running. */
188
189 mixerExit();
190 if(MMPMLibraryHandle) DosFreeModule(MMPMLibraryHandle);
191 return TRUE;
192 }
193 return FALSE;
194}
195/****************************************************************************/
196/* _DLL_InitTerm is the function that gets called by the operating system */
197/* loader when it loads and frees this DLL for each process that accesses */
198/* this DLL. However, it only gets called the first time the DLL is loaded */
199/* and the last time it is freed for a particular process. The system */
200/* linkage convention MUST be used because the operating system loader is */
201/* calling this function. */
202/****************************************************************************/
203ULONG APIENTRY inittermWinmm(ULONG hModule, ULONG ulFlag)
204{
205 /*-------------------------------------------------------------------------*/
206 /* If ulFlag is zero then the DLL is being loaded so initialization should */
207 /* be performed. If ulFlag is 1 then the DLL is being freed so */
208 /* termination should be performed. */
209 /*-------------------------------------------------------------------------*/
210
211 switch (ulFlag)
212 {
213 case 0 :
214 ParseLogStatusWINMM();
215
216 dllHandle = RegisterLxDll(hModule, LibMainWinmm, (PVOID)&winmm_PEResTab);
217 if(dllHandle == 0)
218 return 0UL;/* Error */
219
220 dprintf(("winmm init %s %s (%x)", __DATE__, __TIME__, inittermWinmm));
221 break;
222 case 1 :
223 auxOS2Close(); /* SvL: Close aux device if necessary */
224 if(dllHandle) {
225 UnregisterLxDll(dllHandle);
226 }
227 break;
228 default :
229 return 0UL;
230 }
231
232 /***********************************************************/
233 /* A non-zero value must be returned to indicate success. */
234 /***********************************************************/
235 return 1UL;
236}
237//******************************************************************************
238//******************************************************************************
239DWORD APIENTRY mymciSendCommand(WORD wDeviceID,
240 WORD wMessage,
241 DWORD dwParam1,
242 PVOID dwParam2,
243 WORD wUserParm)
244{
245 if(pfnmciSendCommand == NULL) {
246 DebugInt3();
247 return MCIERR_CANNOT_LOAD_DRIVER;
248 }
249 USHORT sel = RestoreOS2FS();
250 DWORD ret = pfnmciSendCommand(wDeviceID, wMessage, dwParam1, dwParam2, wUserParm);
251 SetFS(sel);
252 return ret;
253}
254//******************************************************************************
255//******************************************************************************
256DWORD APIENTRY mymciGetErrorString(DWORD dwError,
257 LPSTR lpstrBuffer,
258 WORD wLength)
259{
260 if(pfnmciGetErrorString == NULL) {
261 DebugInt3();
262 return MCIERR_CANNOT_LOAD_DRIVER;
263 }
264 USHORT sel = RestoreOS2FS();
265 DWORD ret = pfnmciGetErrorString(dwError, lpstrBuffer, wLength);
266 SetFS(sel);
267 return ret;
268}
269//******************************************************************************
270//******************************************************************************
Note: See TracBrowser for help on using the repository browser.