|
|
1.1 ! root 1: /**************************************************************************** ! 2: * ! 3: * mmdrv.c ! 4: * ! 5: * Multimedia kernel driver support component (mmdrv) ! 6: * ! 7: * Copyright (c) Microsoft Corporation 1992. All rights reserved. ! 8: * ! 9: * This module contains ! 10: * ! 11: * -- the entry point and startup code ! 12: * -- debug support code ! 13: * ! 14: * History ! 15: * 01-Feb-1992 - Robin Speed (RobinSp) wrote it ! 16: * 04-Feb-1992 - Reviewed by SteveDav ! 17: * ! 18: ***************************************************************************/ ! 19: ! 20: #include "mmdrv.h" ! 21: #include <stdarg.h> ! 22: ! 23: CRITICAL_SECTION mmDrvCritSec; // Serialize access to device lists ! 24: ! 25: ! 26: /************************************************************************** ! 27: ! 28: @doc EXTERNAL ! 29: ! 30: @api BOOL | DllInstanceInit | This procedure is called whenever a ! 31: process attaches or detaches from the DLL. ! 32: ! 33: @parm PVOID | hModule | Handle of the DLL. ! 34: ! 35: @parm ULONG | Reason | What the reason for the call is. ! 36: ! 37: @parm PCONTEXT | pContext | Some random other information. ! 38: ! 39: @rdesc The return value is TRUE if the initialisation completed ok, ! 40: FALSE if not. ! 41: ! 42: **************************************************************************/ ! 43: ! 44: BOOL DllInstanceInit(PVOID hModule, ULONG Reason, PCONTEXT pContext) ! 45: { ! 46: ! 47: UNREFERENCED_PARAMETER(pContext); ! 48: ! 49: if (Reason == DLL_PROCESS_ATTACH) { ! 50: #if DBG ! 51: mmdrvDebugLevel = GetProfileInt(L"MMDEBUG", L"MMDRV", 1); ! 52: dprintf2 (("Starting, debug level=%d", mmdrvDebugLevel)); ! 53: #endif ! 54: ! 55: // ! 56: // Create our process DLL heap ! 57: // ! 58: hHeap = HeapCreate(0, 800, 0); ! 59: if (hHeap == NULL) { ! 60: return FALSE; ! 61: } ! 62: ! 63: InitializeCriticalSection(&mmDrvCritSec); ! 64: ! 65: } else { ! 66: if (Reason == DLL_PROCESS_DETACH) { ! 67: dprintf2(("Ending")); ! 68: ! 69: TerminateMidi(); ! 70: TerminateWave(); ! 71: ! 72: DeleteCriticalSection(&mmDrvCritSec); ! 73: HeapDestroy(hHeap); ! 74: } ! 75: } ! 76: return TRUE; ! 77: } ! 78: ! 79: ! 80: /*************************************************************************** ! 81: * @doc INTERNAL ! 82: * ! 83: * @api LONG | DriverProc | The entry point for an installable driver. ! 84: * ! 85: * @parm DWORD | dwDriverId | For most messages, <p dwDriverId> is the DWORD ! 86: * value that the driver returns in response to a <m DRV_OPEN> message. ! 87: * Each time that the driver is opened, through the <f DrvOpen> API, ! 88: * the driver receives a <m DRV_OPEN> message and can return an ! 89: * arbitrary, non-zero value. The installable driver interface ! 90: * saves this value and returns a unique driver handle to the ! 91: * application. Whenever the application sends a message to the ! 92: * driver using the driver handle, the interface routes the message ! 93: * to this entry point and passes the corresponding <p dwDriverId>. ! 94: * This mechanism allows the driver to use the same or different ! 95: * identifiers for multiple opens but ensures that driver handles ! 96: * are unique at the application interface layer. ! 97: * ! 98: * The following messages are not related to a particular open ! 99: * instance of the driver. For these messages, the dwDriverId ! 100: * will always be zero. ! 101: * ! 102: * DRV_LOAD, DRV_FREE, DRV_ENABLE, DRV_DISABLE, DRV_OPEN ! 103: * ! 104: * @parm HANDLE | hDriver | This is the handle returned to the ! 105: * application by the driver interface. ! 106: * ! 107: * @parm UINT | wMessage | The requested action to be performed. Message ! 108: * values below <m DRV_RESERVED> are used for globally defined messages. ! 109: * Message values from <m DRV_RESERVED> to <m DRV_USER> are used for ! 110: * defined driver protocols. Messages above <m DRV_USER> are used ! 111: * for driver specific messages. ! 112: * ! 113: * @parm LONG | lParam1 | Data for this message. Defined separately for ! 114: * each message ! 115: * ! 116: * @parm LONG | lParam2 | Data for this message. Defined separately for ! 117: * each message ! 118: * ! 119: * @rdesc Defined separately for each message. ! 120: ***************************************************************************/ ! 121: LONG DriverProc(DWORD dwDriverID, HANDLE hDriver, UINT wMessage, LONG lParam1, LONG lParam2) ! 122: { ! 123: switch (wMessage) ! 124: { ! 125: case DRV_LOAD: ! 126: dprintf2(("DRV_LOAD")); ! 127: ! 128: /* ! 129: Sent to the driver when it is loaded. Always the first ! 130: message received by a driver. ! 131: ! 132: dwDriverID is 0L. ! 133: lParam1 is 0L. ! 134: lParam2 is 0L. ! 135: ! 136: Return 0L to fail the load. ! 137: ! 138: DefDriverProc will return NON-ZERO so we don't have to ! 139: handle DRV_LOAD ! 140: */ ! 141: ! 142: return 1L; ! 143: ! 144: case DRV_FREE: ! 145: dprintf2(("DRV_FREE")); ! 146: ! 147: /* ! 148: Sent to the driver when it is about to be discarded. This ! 149: will always be the last message received by a driver before ! 150: it is freed. ! 151: ! 152: dwDriverID is 0L. ! 153: lParam1 is 0L. ! 154: lParam2 is 0L. ! 155: ! 156: Return value is ignored. ! 157: */ ! 158: ! 159: return 1L; ! 160: ! 161: case DRV_OPEN: ! 162: dprintf2(("DRV_OPEN")); ! 163: ! 164: /* ! 165: Sent to the driver when it is opened. ! 166: ! 167: dwDriverID is 0L. ! 168: ! 169: lParam1 is a far pointer to a zero-terminated string ! 170: containing the name used to open the driver. ! 171: ! 172: lParam2 is passed through from the drvOpen call. ! 173: ! 174: Return 0L to fail the open. ! 175: ! 176: DefDriverProc will return ZERO so we do have to ! 177: handle the DRV_OPEN message. ! 178: */ ! 179: ! 180: return 1L; ! 181: ! 182: case DRV_CLOSE: ! 183: dprintf2(("DRV_CLOSE")); ! 184: ! 185: /* ! 186: Sent to the driver when it is closed. Drivers are unloaded ! 187: when the close count reaches zero. ! 188: ! 189: dwDriverID is the driver identifier returned from the ! 190: corresponding DRV_OPEN. ! 191: ! 192: lParam1 is passed through from the drvClose call. ! 193: ! 194: lParam2 is passed through from the drvClose call. ! 195: ! 196: Return 0L to fail the close. ! 197: ! 198: DefDriverProc will return ZERO so we do have to ! 199: handle the DRV_CLOSE message. ! 200: */ ! 201: ! 202: return 1L; ! 203: ! 204: case DRV_ENABLE: ! 205: dprintf2(("DRV_ENABLE")); ! 206: ! 207: /* ! 208: Sent to the driver when the driver is loaded or reloaded ! 209: and whenever Windows is enabled. Drivers should only ! 210: hook interrupts or expect ANY part of the driver to be in ! 211: memory between enable and disable messages ! 212: ! 213: dwDriverID is 0L. ! 214: lParam1 is 0L. ! 215: lParam2 is 0L. ! 216: ! 217: Return value is ignored. ! 218: */ ! 219: ! 220: return 1L; ! 221: ! 222: case DRV_DISABLE: ! 223: dprintf2(("DRV_DISABLE")); ! 224: ! 225: /* ! 226: Sent to the driver before the driver is freed. ! 227: and whenever Windows is disabled ! 228: ! 229: dwDriverID is 0L. ! 230: lParam1 is 0L. ! 231: lParam2 is 0L. ! 232: ! 233: Return value is ignored. ! 234: */ ! 235: ! 236: return 1L; ! 237: ! 238: case DRV_QUERYCONFIGURE: ! 239: dprintf2(("DRV_QUERYCONFIGURE")); ! 240: ! 241: /* ! 242: Sent to the driver so that applications can ! 243: determine whether the driver supports custom ! 244: configuration. The driver should return a ! 245: non-zero value to indicate that configuration ! 246: is supported. ! 247: ! 248: dwDriverID is the value returned from the DRV_OPEN ! 249: call that must have succeeded before this message ! 250: was sent. ! 251: ! 252: lParam1 is passed from the app and is undefined. ! 253: lParam2 is passed from the app and is undefined. ! 254: ! 255: Return 0L to indicate configuration NOT supported. ! 256: */ ! 257: ! 258: return 0L; // we don't do configuration at the moment ! 259: ! 260: case DRV_CONFIGURE: ! 261: dprintf2(("DRV_CONFIGURE")); ! 262: ! 263: /* ! 264: Sent to the driver so that it can display a custom ! 265: configuration dialog box. ! 266: ! 267: lParam1 is passed from the app. and should contain ! 268: the parent window handle in the loword. ! 269: lParam2 is passed from the app and is undefined. ! 270: ! 271: Return value is undefined. ! 272: ! 273: Drivers should create their own section in system.ini. ! 274: The section name should be the driver name. ! 275: */ ! 276: ! 277: return 0L; ! 278: ! 279: case DRV_INSTALL: ! 280: dprintf2(("DRV_INSTALL")); ! 281: return DRVCNF_RESTART; ! 282: ! 283: default: ! 284: return DefDriverProc(dwDriverID, hDriver, wMessage,lParam1,lParam2); ! 285: } ! 286: } ! 287: ! 288: ! 289: ! 290: #if DBG ! 291: ! 292: int mmdrvDebugLevel = 1; ! 293: ! 294: /*************************************************************************** ! 295: ! 296: @doc INTERNAL ! 297: ! 298: @api void | mmdrvDbgOut | This function sends output to the current ! 299: debug output device. ! 300: ! 301: @parm LPSTR | lpszFormat | Pointer to a printf style format string. ! 302: @parm ??? | ... | Args. ! 303: ! 304: @rdesc There is no return value. ! 305: ! 306: ****************************************************************************/ ! 307: ! 308: void mmdrvDbgOut(LPSTR lpszFormat, ...) ! 309: { ! 310: char buf[256]; ! 311: va_list va; ! 312: ! 313: OutputDebugStringA("MMDRV: "); ! 314: ! 315: va_start(va, lpszFormat); ! 316: vsprintf(buf, lpszFormat, va); ! 317: va_end(va); ! 318: ! 319: OutputDebugStringA(buf); ! 320: OutputDebugStringA("\n"); ! 321: } ! 322: ! 323: /*************************************************************************** ! 324: ! 325: @doc INTERNAL ! 326: ! 327: @api void | dDbgAssert | This function prints an assertion message. ! 328: ! 329: @parm LPSTR | exp | Pointer to the expression string. ! 330: @parm LPSTR | file | Pointer to the file name. ! 331: @parm int | line | The line number. ! 332: ! 333: @rdesc There is no return value. ! 334: ! 335: ****************************************************************************/ ! 336: ! 337: void dDbgAssert(LPSTR exp, LPSTR file, int line) ! 338: { ! 339: dprintf1(("Assertion failure:")); ! 340: dprintf1((" Exp: %s", exp)); ! 341: dprintf1((" File: %s, line: %d", file, line)); ! 342: DebugBreak(); ! 343: } ! 344: ! 345: #endif // DBG
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.