| 1 | /* $Id: initwinmm.cpp,v 1.11 2003-01-14 19:38:37 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 |
|
|---|
| 56 | BOOL MULTIMEDIA_MciInit(void);
|
|---|
| 57 | BOOL MULTIMEDIA_CreateIData(HINSTANCE hinstDLL);
|
|---|
| 58 | void MULTIMEDIA_DeleteIData(void);
|
|---|
| 59 |
|
|---|
| 60 | extern "C" {
|
|---|
| 61 | void IRTMidiShutdown(); // IRTMidi shutdown routine
|
|---|
| 62 |
|
|---|
| 63 | //Win32 resource table (produced by wrc)
|
|---|
| 64 | extern DWORD winmm_PEResTab;
|
|---|
| 65 | }
|
|---|
| 66 | static HMODULE dllHandle = 0;
|
|---|
| 67 | static HMODULE MMPMLibraryHandle = 0;
|
|---|
| 68 |
|
|---|
| 69 | BOOL fMMPMAvailable = TRUE;
|
|---|
| 70 |
|
|---|
| 71 | DWORD (APIENTRY *pfnmciSendCommand)(WORD wDeviceID,
|
|---|
| 72 | WORD wMessage,
|
|---|
| 73 | DWORD dwParam1,
|
|---|
| 74 | PVOID dwParam2,
|
|---|
| 75 | WORD wUserParm) = NULL;
|
|---|
| 76 | DWORD (APIENTRY *pfnmciGetErrorString)(DWORD dwError,
|
|---|
| 77 | LPSTR lpstrBuffer,
|
|---|
| 78 | WORD wLength) = NULL;
|
|---|
| 79 |
|
|---|
| 80 | //******************************************************************************
|
|---|
| 81 | //******************************************************************************
|
|---|
| 82 | void WIN32API DisableWaveAudio()
|
|---|
| 83 | {
|
|---|
| 84 | fMMPMAvailable = FALSE;
|
|---|
| 85 | pfnmciGetErrorString = NULL;
|
|---|
| 86 | pfnmciSendCommand = NULL;
|
|---|
| 87 | }
|
|---|
| 88 | //******************************************************************************
|
|---|
| 89 | //******************************************************************************
|
|---|
| 90 | BOOL 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 | WaveInOut::shutdown();
|
|---|
| 186 | MULTIMEDIA_DeleteIData();
|
|---|
| 187 | auxOS2Close(); /* Close aux device if necessary */
|
|---|
| 188 | IRTMidiShutdown; /* Shutdown RT Midi subsystem, if running. */
|
|---|
| 189 |
|
|---|
| 190 | mixerExit();
|
|---|
| 191 | if(MMPMLibraryHandle) DosFreeModule(MMPMLibraryHandle);
|
|---|
| 192 | return TRUE;
|
|---|
| 193 | }
|
|---|
| 194 | return FALSE;
|
|---|
| 195 | }
|
|---|
| 196 | /****************************************************************************/
|
|---|
| 197 | /* _DLL_InitTerm is the function that gets called by the operating system */
|
|---|
| 198 | /* loader when it loads and frees this DLL for each process that accesses */
|
|---|
| 199 | /* this DLL. However, it only gets called the first time the DLL is loaded */
|
|---|
| 200 | /* and the last time it is freed for a particular process. The system */
|
|---|
| 201 | /* linkage convention MUST be used because the operating system loader is */
|
|---|
| 202 | /* calling this function. */
|
|---|
| 203 | /****************************************************************************/
|
|---|
| 204 | ULONG APIENTRY inittermWinmm(ULONG hModule, ULONG ulFlag)
|
|---|
| 205 | {
|
|---|
| 206 | /*-------------------------------------------------------------------------*/
|
|---|
| 207 | /* If ulFlag is zero then the DLL is being loaded so initialization should */
|
|---|
| 208 | /* be performed. If ulFlag is 1 then the DLL is being freed so */
|
|---|
| 209 | /* termination should be performed. */
|
|---|
| 210 | /*-------------------------------------------------------------------------*/
|
|---|
| 211 |
|
|---|
| 212 | switch (ulFlag)
|
|---|
| 213 | {
|
|---|
| 214 | case 0 :
|
|---|
| 215 | ParseLogStatusWINMM();
|
|---|
| 216 |
|
|---|
| 217 | dllHandle = RegisterLxDll(hModule, LibMainWinmm, (PVOID)&winmm_PEResTab);
|
|---|
| 218 | if(dllHandle == 0)
|
|---|
| 219 | return 0UL;/* Error */
|
|---|
| 220 |
|
|---|
| 221 | dprintf(("winmm init %s %s (%x)", __DATE__, __TIME__, inittermWinmm));
|
|---|
| 222 | break;
|
|---|
| 223 | case 1 :
|
|---|
| 224 | auxOS2Close(); /* SvL: Close aux device if necessary */
|
|---|
| 225 | if(dllHandle) {
|
|---|
| 226 | UnregisterLxDll(dllHandle);
|
|---|
| 227 | }
|
|---|
| 228 | break;
|
|---|
| 229 | default :
|
|---|
| 230 | return 0UL;
|
|---|
| 231 | }
|
|---|
| 232 |
|
|---|
| 233 | /***********************************************************/
|
|---|
| 234 | /* A non-zero value must be returned to indicate success. */
|
|---|
| 235 | /***********************************************************/
|
|---|
| 236 | return 1UL;
|
|---|
| 237 | }
|
|---|
| 238 | //******************************************************************************
|
|---|
| 239 | //******************************************************************************
|
|---|
| 240 | DWORD APIENTRY mymciSendCommand(WORD wDeviceID,
|
|---|
| 241 | WORD wMessage,
|
|---|
| 242 | DWORD dwParam1,
|
|---|
| 243 | PVOID dwParam2,
|
|---|
| 244 | WORD wUserParm)
|
|---|
| 245 | {
|
|---|
| 246 | if(pfnmciSendCommand == NULL) {
|
|---|
| 247 | DebugInt3();
|
|---|
| 248 | return MCIERR_CANNOT_LOAD_DRIVER;
|
|---|
| 249 | }
|
|---|
| 250 | USHORT sel = RestoreOS2FS();
|
|---|
| 251 | DWORD ret = pfnmciSendCommand(wDeviceID, wMessage, dwParam1, dwParam2, wUserParm);
|
|---|
| 252 | SetFS(sel);
|
|---|
| 253 | return ret;
|
|---|
| 254 | }
|
|---|
| 255 | //******************************************************************************
|
|---|
| 256 | //******************************************************************************
|
|---|
| 257 | DWORD APIENTRY mymciGetErrorString(DWORD dwError,
|
|---|
| 258 | LPSTR lpstrBuffer,
|
|---|
| 259 | WORD wLength)
|
|---|
| 260 | {
|
|---|
| 261 | if(pfnmciGetErrorString == NULL) {
|
|---|
| 262 | DebugInt3();
|
|---|
| 263 | return MCIERR_CANNOT_LOAD_DRIVER;
|
|---|
| 264 | }
|
|---|
| 265 | USHORT sel = RestoreOS2FS();
|
|---|
| 266 | DWORD ret = pfnmciGetErrorString(dwError, lpstrBuffer, wLength);
|
|---|
| 267 | SetFS(sel);
|
|---|
| 268 | return ret;
|
|---|
| 269 | }
|
|---|
| 270 | //******************************************************************************
|
|---|
| 271 | //******************************************************************************
|
|---|