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

Last change on this file since 7232 was 7232, checked in by sandervl, 24 years ago

check registry key to disable audio

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