[CMAKE]
[reactos.git] / dll / win32 / winmm / lolvldrv.c
1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
2
3 /*
4 * MMSYSTEM low level drivers handling functions
5 *
6 * Copyright 1999 Eric Pouech
7 * Modified for use with ReactOS by Andrew Greenwood, 2007
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24 #include "config.h"
25 #include "wine/port.h"
26
27 #include <string.h>
28 #include <stdarg.h>
29 #include <stdio.h>
30 #include <assert.h>
31 #include "windef.h"
32 #include "winbase.h"
33 #include "winreg.h"
34 #include "winemm.h"
35 #include "wine/debug.h"
36 #include "wine/exception.h"
37
38 WINE_DEFAULT_DEBUG_CHANNEL(winmm);
39
40 /* each known type of driver has an instance of this structure */
41 typedef struct tagWINE_LLTYPE {
42 /* those attributes depend on the specification of the type */
43 LPCSTR typestr; /* name (for debugging) */
44 BOOL bSupportMapper; /* if type is allowed to support mapper */
45 /* those attributes reflect the loaded/current situation for the type */
46 UINT wMaxId; /* number of loaded devices (sum across all loaded drivers) */
47 LPWINE_MLD lpMlds; /* "static" mlds to access the part though device IDs */
48 int nMapper; /* index to mapper */
49 } WINE_LLTYPE;
50
51 static int MMDrvsHi /* = 0 */;
52 static WINE_MM_DRIVER MMDrvs[8];
53 static LPWINE_MLD MM_MLDrvs[40];
54 #define MAX_MM_MLDRVS (sizeof(MM_MLDrvs) / sizeof(MM_MLDrvs[0]))
55
56 #define A(_x,_y) {#_y, _x, 0, NULL, -1}
57 /* Note: the indices of this array must match the definitions
58 * of the MMDRV_???? manifest constants
59 */
60 static WINE_LLTYPE llTypes[MMDRV_MAX] = {
61 A(TRUE, Aux),
62 A(FALSE, Mixer),
63 A(TRUE, MidiIn),
64 A(TRUE, MidiOut),
65 A(TRUE, WaveIn),
66 A(TRUE, WaveOut),
67 };
68 #undef A
69
70 /**************************************************************************
71 * MMDRV_GetNum [internal]
72 */
73 UINT MMDRV_GetNum(UINT type)
74 {
75 TRACE("(%04x)\n", type);
76 assert(type < MMDRV_MAX);
77 return llTypes[type].wMaxId;
78 }
79
80 /**************************************************************************
81 * MMDRV_Message [internal]
82 */
83 DWORD MMDRV_Message(LPWINE_MLD mld, UINT wMsg, DWORD_PTR dwParam1,
84 DWORD_PTR dwParam2)
85 {
86 LPWINE_MM_DRIVER lpDrv;
87 DWORD ret;
88 WINE_MM_DRIVER_PART* part;
89 WINE_LLTYPE* llType = &llTypes[mld->type];
90 int devID;
91
92 TRACE("(%s %u %u 0x%08lx 0x%08lx 0x%08lx)\n",
93 llTypes[mld->type].typestr, mld->uDeviceID, wMsg,
94 mld->dwDriverInstance, dwParam1, dwParam2);
95
96 if (mld->uDeviceID == (UINT16)-1) {
97 if (!llType->bSupportMapper) {
98 WARN("uDev=-1 requested on non-mappable ll type %s\n",
99 llTypes[mld->type].typestr);
100 return MMSYSERR_BADDEVICEID;
101 }
102 devID = -1;
103 } else {
104 if (mld->uDeviceID >= llType->wMaxId) {
105 WARN("uDev(%u) requested >= max (%d)\n", mld->uDeviceID, llType->wMaxId);
106 return MMSYSERR_BADDEVICEID;
107 }
108 devID = mld->uDeviceID;
109 }
110
111 lpDrv = &MMDrvs[mld->mmdIndex];
112 part = &lpDrv->parts[mld->type];
113
114 #if 0
115 /* some sanity checks */
116 if (!(part->nIDMin <= devID))
117 ERR("!(part->nIDMin(%d) <= devID(%d))\n", part->nIDMin, devID);
118 if (!(devID < part->nIDMax))
119 ERR("!(devID(%d) < part->nIDMax(%d))\n", devID, part->nIDMax);
120 #endif
121
122 assert(part->fnMessage32);
123
124 TRACE("Calling message(dev=%u msg=%u usr=0x%08lx p1=0x%08lx p2=0x%08lx)\n",
125 mld->uDeviceID, wMsg, mld->dwDriverInstance, dwParam1, dwParam2);
126 ret = part->fnMessage32(mld->uDeviceID, wMsg, mld->dwDriverInstance, dwParam1, dwParam2);
127 TRACE("=> %s\n", WINMM_ErrorToString(ret));
128
129 return ret;
130 }
131
132 /**************************************************************************
133 * MMDRV_Alloc [internal]
134 */
135 LPWINE_MLD MMDRV_Alloc(UINT size, UINT type, LPHANDLE hndl, DWORD* dwFlags,
136 DWORD_PTR* dwCallback, DWORD_PTR* dwInstance)
137 {
138 LPWINE_MLD mld;
139 UINT_PTR i;
140 TRACE("(%d, %04x, %p, %p, %p, %p)\n",
141 size, type, hndl, dwFlags, dwCallback, dwInstance);
142
143 mld = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
144 if (!mld) return NULL;
145
146 /* find an empty slot in MM_MLDrvs table */
147 for (i = 0; i < MAX_MM_MLDRVS; i++) if (!MM_MLDrvs[i]) break;
148
149 if (i == MAX_MM_MLDRVS) {
150 /* the MM_MLDrvs table could be made growable in the future if needed */
151 ERR("Too many open drivers\n");
152 HeapFree(GetProcessHeap(), 0, mld);
153 return NULL;
154 }
155 MM_MLDrvs[i] = mld;
156 *hndl = (HANDLE)(i | 0x8000);
157
158 mld->type = type;
159 if ((UINT_PTR)*hndl < MMDRV_GetNum(type) || ((UINT_PTR)*hndl >> 16)) {
160 /* FIXME: those conditions must be fulfilled so that:
161 * - we can distinguish between device IDs and handles
162 * - we can use handles as 16 or 32 bit entities
163 */
164 ERR("Shouldn't happen. Bad allocation scheme\n");
165 }
166
167 mld->dwFlags = HIWORD(*dwFlags);
168 mld->dwCallback = *dwCallback;
169 mld->dwClientInstance = *dwInstance;
170
171 return mld;
172 }
173
174 /**************************************************************************
175 * MMDRV_Free [internal]
176 */
177 void MMDRV_Free(HANDLE hndl, LPWINE_MLD mld)
178 {
179 TRACE("(%p, %p)\n", hndl, mld);
180
181 if ((UINT_PTR)hndl & 0x8000) {
182 UINT_PTR idx = (UINT_PTR)hndl & ~0x8000;
183 if (idx < sizeof(MM_MLDrvs) / sizeof(MM_MLDrvs[0])) {
184 MM_MLDrvs[idx] = NULL;
185 HeapFree(GetProcessHeap(), 0, mld);
186 return;
187 }
188 }
189 ERR("Bad Handle %p at %p (not freed)\n", hndl, mld);
190 }
191
192 /**************************************************************************
193 * MMDRV_Open [internal]
194 */
195 DWORD MMDRV_Open(LPWINE_MLD mld, UINT wMsg, DWORD_PTR dwParam1, DWORD dwFlags)
196 {
197 DWORD dwRet = MMSYSERR_BADDEVICEID;
198 DWORD_PTR dwInstance;
199 WINE_LLTYPE* llType = &llTypes[mld->type];
200 TRACE("(%p, %04x, 0x%08lx, 0x%08x)\n", mld, wMsg, dwParam1, dwFlags);
201
202 mld->dwDriverInstance = (DWORD_PTR)&dwInstance;
203
204 if (mld->uDeviceID == (UINT)-1 || mld->uDeviceID == (UINT16)-1) {
205 TRACE("MAPPER mode requested !\n");
206 /* check if mapper is supported by type */
207 if (llType->bSupportMapper) {
208 if (llType->nMapper == -1) {
209 /* no driver for mapper has been loaded, try a dumb implementation */
210 TRACE("No mapper loaded, doing it by hand\n");
211 for (mld->uDeviceID = 0; mld->uDeviceID < llType->wMaxId; mld->uDeviceID++) {
212 if ((dwRet = MMDRV_Open(mld, wMsg, dwParam1, dwFlags)) == MMSYSERR_NOERROR) {
213 /* to share this function epilog */
214 dwInstance = mld->dwDriverInstance;
215 break;
216 }
217 }
218 } else {
219 mld->uDeviceID = (UINT16)-1;
220 mld->mmdIndex = llType->lpMlds[-1].mmdIndex;
221 TRACE("Setting mmdIndex to %u\n", mld->mmdIndex);
222 dwRet = MMDRV_Message(mld, wMsg, dwParam1, dwFlags);
223 }
224 }
225 } else {
226 if (mld->uDeviceID < llType->wMaxId) {
227 mld->mmdIndex = llType->lpMlds[mld->uDeviceID].mmdIndex;
228 TRACE("Setting mmdIndex to %u\n", mld->mmdIndex);
229 dwRet = MMDRV_Message(mld, wMsg, dwParam1, dwFlags);
230 }
231 }
232 if (dwRet == MMSYSERR_NOERROR)
233 mld->dwDriverInstance = dwInstance;
234 return dwRet;
235 }
236
237 /**************************************************************************
238 * MMDRV_Close [internal]
239 */
240 DWORD MMDRV_Close(LPWINE_MLD mld, UINT wMsg)
241 {
242 TRACE("(%p, %04x)\n", mld, wMsg);
243 return MMDRV_Message(mld, wMsg, 0L, 0L);
244 }
245
246 /**************************************************************************
247 * MMDRV_GetByID [internal]
248 */
249 static LPWINE_MLD MMDRV_GetByID(UINT uDevID, UINT type)
250 {
251 TRACE("(%04x, %04x)\n", uDevID, type);
252 if (uDevID < llTypes[type].wMaxId)
253 return &llTypes[type].lpMlds[uDevID];
254 if ((uDevID == (UINT16)-1 || uDevID == (UINT)-1) && llTypes[type].nMapper != -1)
255 return &llTypes[type].lpMlds[-1];
256 return NULL;
257 }
258
259 /**************************************************************************
260 * MMDRV_Get [internal]
261 */
262 LPWINE_MLD MMDRV_Get(HANDLE _hndl, UINT type, BOOL bCanBeID)
263 {
264 LPWINE_MLD mld = NULL;
265 UINT_PTR hndl = (UINT_PTR)_hndl;
266 TRACE("(%p, %04x, %c)\n", _hndl, type, bCanBeID ? 'Y' : 'N');
267
268 assert(type < MMDRV_MAX);
269
270 if (hndl >= llTypes[type].wMaxId &&
271 hndl != (UINT16)-1 && hndl != (UINT)-1) {
272 if (hndl & 0x8000) {
273 UINT idx = hndl & ~0x8000;
274 if (idx < sizeof(MM_MLDrvs) / sizeof(MM_MLDrvs[0])) {
275 __TRY
276 {
277 mld = MM_MLDrvs[idx];
278 if (mld && mld->type != type) mld = NULL;
279 }
280 __EXCEPT_PAGE_FAULT
281 {
282 mld = NULL;
283 }
284 __ENDTRY;
285 }
286 }
287 }
288 if (mld == NULL && bCanBeID) {
289 mld = MMDRV_GetByID(hndl, type);
290 }
291 return mld;
292 }
293
294 /**************************************************************************
295 * MMDRV_GetRelated [internal]
296 */
297 LPWINE_MLD MMDRV_GetRelated(HANDLE hndl, UINT srcType,
298 BOOL bSrcCanBeID, UINT dstType)
299 {
300 LPWINE_MLD mld;
301 TRACE("(%p, %04x, %c, %04x)\n",
302 hndl, srcType, bSrcCanBeID ? 'Y' : 'N', dstType);
303
304 if ((mld = MMDRV_Get(hndl, srcType, bSrcCanBeID)) != NULL) {
305 WINE_MM_DRIVER_PART* part = &MMDrvs[mld->mmdIndex].parts[dstType];
306 if (part->nIDMin < part->nIDMax)
307 return MMDRV_GetByID(part->nIDMin, dstType);
308 }
309 return NULL;
310 }
311
312 /**************************************************************************
313 * MMDRV_PhysicalFeatures [internal]
314 */
315 UINT MMDRV_PhysicalFeatures(LPWINE_MLD mld, UINT uMsg,
316 DWORD_PTR dwParam1, DWORD_PTR dwParam2)
317 {
318 WINE_MM_DRIVER* lpDrv = &MMDrvs[mld->mmdIndex];
319
320 TRACE("(%p, %04x, %08lx, %08lx)\n", mld, uMsg, dwParam1, dwParam2);
321
322 /* all those function calls are undocumented */
323 switch (uMsg) {
324 case DRV_QUERYDRVENTRY:
325 lstrcpynA((LPSTR)dwParam1, lpDrv->drvname, LOWORD(dwParam2));
326 break;
327 case DRV_QUERYDEVNODE:
328 *(LPDWORD)dwParam1 = 0L; /* should be DevNode */
329 break;
330 case DRV_QUERYNAME:
331 WARN("NIY QueryName\n");
332 break;
333 case DRV_QUERYDRIVERIDS:
334 WARN("NIY call VxD\n");
335 /* should call VxD MMDEVLDR with (DevNode, dwParam1 and dwParam2) as pmts
336 * dwParam1 is buffer and dwParam2 is sizeof(buffer)
337 * I don't know where the result is stored though
338 */
339 break;
340 case DRV_QUERYMAPPABLE:
341 return (lpDrv->bIsMapper) ? 2 : 0;
342
343 case DRVM_MAPPER_PREFERRED_GET:
344 /* FIXME: get from registry someday */
345 *((LPDWORD)dwParam1) = -1; /* No preferred device */
346 *((LPDWORD)dwParam2) = 0;
347 break;
348
349 case DRV_QUERYDEVICEINTERFACE:
350 case DRV_QUERYDEVICEINTERFACESIZE:
351 return MMDRV_Message(mld, uMsg, dwParam1, dwParam2);
352
353 case DRV_QUERYDSOUNDIFACE: /* Wine-specific: Retrieve DirectSound interface */
354 case DRV_QUERYDSOUNDDESC: /* Wine-specific: Retrieve DirectSound driver description*/
355 return MMDRV_Message(mld, uMsg, dwParam1, dwParam2);
356
357 default:
358 WARN("Unknown call %04x\n", uMsg);
359 return MMSYSERR_INVALPARAM;
360 }
361 return 0L;
362 }
363
364 /**************************************************************************
365 * MMDRV_InitPerType [internal]
366 */
367 static BOOL MMDRV_InitPerType(LPWINE_MM_DRIVER lpDrv, UINT type, UINT wMsg)
368 {
369 WINE_MM_DRIVER_PART* part = &lpDrv->parts[type];
370 DWORD ret;
371 UINT count = 0;
372 int i, k;
373 TRACE("(%p, %04x, %04x)\n", lpDrv, type, wMsg);
374
375 part->nIDMin = part->nIDMax = 0;
376
377 /* for DRVM_INIT and DRVM_ENABLE, dwParam2 should be PnP node */
378 /* the DRVM_ENABLE is only required when the PnP node is non zero */
379 if (part->fnMessage32) {
380 ret = part->fnMessage32(0, DRVM_INIT, 0L, 0L, 0L);
381 TRACE("DRVM_INIT => %s\n", WINMM_ErrorToString(ret));
382 #if 0
383 ret = part->fnMessage32(0, DRVM_ENABLE, 0L, 0L, 0L);
384 TRACE("DRVM_ENABLE => %08lx\n", ret);
385 #endif
386 count = part->fnMessage32(0, wMsg, 0L, 0L, 0L);
387 }
388 else return FALSE;
389
390 TRACE("Got %u dev for (%s:%s)\n", count, lpDrv->drvname, llTypes[type].typestr);
391
392 if (HIWORD(count))
393 return FALSE;
394
395 /* got some drivers */
396 if (lpDrv->bIsMapper) {
397 /* it seems native mappers return 0 devices :-( */
398 if (llTypes[type].nMapper != -1)
399 ERR("Two mappers for type %s (%d, %s)\n",
400 llTypes[type].typestr, llTypes[type].nMapper, lpDrv->drvname);
401 if (count > 1)
402 ERR("Strange: mapper with %d > 1 devices\n", count);
403 llTypes[type].nMapper = MMDrvsHi;
404 } else {
405 if (count == 0)
406 return FALSE;
407 part->nIDMin = llTypes[type].wMaxId;
408 llTypes[type].wMaxId += count;
409 part->nIDMax = llTypes[type].wMaxId;
410 }
411 TRACE("Setting min=%d max=%d (ttop=%d) for (%s:%s)\n",
412 part->nIDMin, part->nIDMax, llTypes[type].wMaxId,
413 lpDrv->drvname, llTypes[type].typestr);
414 /* realloc translation table */
415 if (llTypes[type].lpMlds)
416 llTypes[type].lpMlds = (LPWINE_MLD)
417 HeapReAlloc(GetProcessHeap(), 0, llTypes[type].lpMlds - 1,
418 sizeof(WINE_MLD) * (llTypes[type].wMaxId + 1)) + 1;
419 else
420 llTypes[type].lpMlds = (LPWINE_MLD)
421 HeapAlloc(GetProcessHeap(), 0,
422 sizeof(WINE_MLD) * (llTypes[type].wMaxId + 1)) + 1;
423
424 /* re-build the translation table */
425 if (llTypes[type].nMapper != -1) {
426 TRACE("%s:Trans[%d] -> %s\n", llTypes[type].typestr, -1, MMDrvs[llTypes[type].nMapper].drvname);
427 llTypes[type].lpMlds[-1].uDeviceID = (UINT16)-1;
428 llTypes[type].lpMlds[-1].type = type;
429 llTypes[type].lpMlds[-1].mmdIndex = llTypes[type].nMapper;
430 llTypes[type].lpMlds[-1].dwDriverInstance = 0;
431 }
432 for (i = k = 0; i <= MMDrvsHi; i++) {
433 while (MMDrvs[i].parts[type].nIDMin <= k && k < MMDrvs[i].parts[type].nIDMax) {
434 TRACE("%s:Trans[%d] -> %s\n", llTypes[type].typestr, k, MMDrvs[i].drvname);
435 llTypes[type].lpMlds[k].uDeviceID = k;
436 llTypes[type].lpMlds[k].type = type;
437 llTypes[type].lpMlds[k].mmdIndex = i;
438 llTypes[type].lpMlds[k].dwDriverInstance = 0;
439 k++;
440 }
441 }
442 return TRUE;
443 }
444
445 /**************************************************************************
446 * MMDRV_Install [internal]
447 */
448 BOOL MMDRV_Install(LPCSTR drvRegName, LPCSTR drvFileName, BOOL bIsMapper)
449 {
450 int i, count = 0;
451 LPWINE_MM_DRIVER lpDrv = &MMDrvs[MMDrvsHi];
452 LPWINE_DRIVER d;
453 WINEMM_msgFunc32 func;
454
455 TRACE("('%s', '%s', mapper=%c);\n", drvRegName, drvFileName, bIsMapper ? 'Y' : 'N');
456
457 for (i = 0; i < MMDrvsHi; i++) {
458 if (!strcmp(drvRegName, MMDrvs[i].drvname)) return FALSE;
459 }
460
461 /* Be sure that size of MMDrvs matches the max number of loadable
462 * drivers !!
463 * If not just increase size of MMDrvs
464 */
465 assert(MMDrvsHi <= sizeof(MMDrvs)/sizeof(MMDrvs[0]));
466
467 memset(lpDrv, 0, sizeof(*lpDrv));
468
469 if (!(lpDrv->hDriver = OpenDriverA(drvFileName, 0, 0))) {
470 WARN("Couldn't open driver '%s'\n", drvFileName);
471 return FALSE;
472 }
473
474 d = DRIVER_FindFromHDrvr(lpDrv->hDriver);
475
476 if (!(d = DRIVER_FindFromHDrvr(lpDrv->hDriver))) {
477 CloseDriver(lpDrv->hDriver, 0, 0);
478 WARN("Couldn't get the WINE internal structure for driver '%s'\n", drvFileName);
479 return FALSE;
480 }
481
482 /* Then look for xxxMessage functions */
483 #define AA(_h,_w,_x,_y,_z) \
484 func = (WINEMM_msgFunc##_y) _z ((_h), #_x); \
485 if (func != NULL) \
486 { lpDrv->parts[_w].fnMessage##_y = func; count++; \
487 TRACE("Got %d bit func '%s'\n", _y, #_x); }
488
489 if (d->hModule) {
490 #define A(_x,_y) AA(d->hModule,_x,_y,32,GetProcAddress)
491 A(MMDRV_AUX, auxMessage);
492 A(MMDRV_MIXER, mxdMessage);
493 A(MMDRV_MIDIIN, midMessage);
494 A(MMDRV_MIDIOUT, modMessage);
495 A(MMDRV_WAVEIN, widMessage);
496 A(MMDRV_WAVEOUT, wodMessage);
497 #undef A
498 }
499 #undef AA
500
501 if (!count) {
502 CloseDriver(lpDrv->hDriver, 0, 0);
503 WARN("No message functions found\n");
504 return FALSE;
505 }
506
507 /* FIXME: being a mapper or not should be known by another way */
508 /* it's known for NE drvs (the description is of the form '*mapper: *'
509 * I don't have any clue for PE drvs
510 */
511 lpDrv->bIsMapper = bIsMapper;
512 lpDrv->drvname = strcpy(HeapAlloc(GetProcessHeap(), 0, strlen(drvRegName) + 1), drvRegName);
513
514 /* Finish init and get the count of the devices */
515 i = 0;
516 if (MMDRV_InitPerType(lpDrv, MMDRV_AUX, AUXDM_GETNUMDEVS)) i = 1;
517 if (MMDRV_InitPerType(lpDrv, MMDRV_MIXER, MXDM_GETNUMDEVS)) i = 1;
518 if (MMDRV_InitPerType(lpDrv, MMDRV_MIDIIN, MIDM_GETNUMDEVS)) i = 1;
519 if (MMDRV_InitPerType(lpDrv, MMDRV_MIDIOUT, MODM_GETNUMDEVS)) i = 1;
520 if (MMDRV_InitPerType(lpDrv, MMDRV_WAVEIN, WIDM_GETNUMDEVS)) i = 1;
521 if (MMDRV_InitPerType(lpDrv, MMDRV_WAVEOUT, WODM_GETNUMDEVS)) i = 1;
522 /* if all those func calls return FALSE, then the driver must be unloaded */
523 if (!i) {
524 CloseDriver(lpDrv->hDriver, 0, 0);
525 HeapFree(GetProcessHeap(), 0, lpDrv->drvname);
526 WARN("Driver initialization failed\n");
527 return FALSE;
528 }
529
530 MMDrvsHi++;
531
532 return TRUE;
533 }
534
535 /**************************************************************************
536 * MMDRV_Init
537 */
538 BOOL MMDRV_Init(void)
539 {
540 /* Redundant code, keeping this for reference only (for now) */
541 #if 0
542 HKEY hKey;
543 char driver_buffer[256];
544 char mapper_buffer[256];
545 char midi_buffer[256];
546 char* p;
547 DWORD type, size;
548 BOOL ret = FALSE;
549 TRACE("()\n");
550
551 strcpy(driver_buffer, WINE_DEFAULT_WINMM_DRIVER);
552 strcpy(mapper_buffer, WINE_DEFAULT_WINMM_MAPPER);
553 strcpy(midi_buffer, WINE_DEFAULT_WINMM_MIDI);
554
555 /* @@ Wine registry key: HKCU\Software\Wine\Drivers */
556 if (!RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Drivers", &hKey))
557 {
558 size = sizeof(driver_buffer);
559 if (RegQueryValueExA(hKey, "Audio", 0, &type, (LPVOID)driver_buffer, &size))
560 strcpy(driver_buffer, WINE_DEFAULT_WINMM_DRIVER);
561 }
562
563 p = driver_buffer;
564 while (p)
565 {
566 char filename[sizeof(driver_buffer)+10];
567 char *next = strchr(p, ',');
568 if (next) *next++ = 0;
569 sprintf( filename, "wine%s.drv", p );
570 if ((ret = MMDRV_Install( filename, filename, FALSE ))) break;
571 p = next;
572 }
573
574 ret |= MMDRV_Install("beepmidi.dll", "beepmidi.dll", FALSE);
575
576 ret |= MMDRV_Install("wavemapper", WINE_DEFAULT_WINMM_MAPPER, TRUE);
577 ret |= MMDRV_Install("midimapper", WINE_DEFAULT_WINMM_MIDI, TRUE);
578 return ret;
579 #else
580 INT driver_count = 0;
581
582 driver_count += LoadRegistryMMEDrivers(NT_MME_DRIVERS_KEY);
583 driver_count += LoadRegistryMMEDrivers(NT_MME_DRIVERS32_KEY);
584
585 /* Explorer doesn't like us failing */
586 return TRUE;
587 // return ( driver_count > 0 );
588 #endif
589 }
590
591 /******************************************************************
592 * ExitPerType
593 *
594 *
595 */
596 static BOOL MMDRV_ExitPerType(LPWINE_MM_DRIVER lpDrv, UINT type)
597 {
598 WINE_MM_DRIVER_PART* part = &lpDrv->parts[type];
599 DWORD ret;
600 TRACE("(%p, %04x)\n", lpDrv, type);
601
602 if (part->fnMessage32) {
603 #if 0
604 ret = part->fnMessage32(0, DRVM_DISABLE, 0L, 0L, 0L);
605 TRACE("DRVM_DISABLE => %08lx\n", ret);
606 #endif
607 ret = part->fnMessage32(0, DRVM_EXIT, 0L, 0L, 0L);
608 TRACE("DRVM_EXIT => %s\n", WINMM_ErrorToString(ret));
609 }
610
611 return TRUE;
612 }
613
614 /******************************************************************
615 * Exit
616 *
617 *
618 */
619 void MMDRV_Exit(void)
620 {
621 unsigned int i;
622 TRACE("()\n");
623
624 for (i = 0; i < sizeof(MM_MLDrvs) / sizeof(MM_MLDrvs[0]); i++)
625 {
626 if (MM_MLDrvs[i] != NULL)
627 {
628 FIXME("Closing while ll-driver open\n");
629 #if 0
630 /* FIXME: should generate a message depending on type */
631 MMDRV_Free((HANDLE)(i | 0x8000), MM_MLDrvs[i]);
632 #endif
633 }
634 }
635
636 /* unload driver, in reverse order of loading */
637 i = sizeof(MMDrvs) / sizeof(MMDrvs[0]);
638 while (i-- > 0)
639 {
640 MMDRV_ExitPerType(&MMDrvs[i], MMDRV_AUX);
641 MMDRV_ExitPerType(&MMDrvs[i], MMDRV_MIXER);
642 MMDRV_ExitPerType(&MMDrvs[i], MMDRV_MIDIIN);
643 MMDRV_ExitPerType(&MMDrvs[i], MMDRV_MIDIOUT);
644 MMDRV_ExitPerType(&MMDrvs[i], MMDRV_WAVEIN);
645 MMDRV_ExitPerType(&MMDrvs[i], MMDRV_WAVEOUT);
646 CloseDriver(MMDrvs[i].hDriver, 0, 0);
647 }
648 if (llTypes[MMDRV_AUX].lpMlds)
649 HeapFree(GetProcessHeap(), 0, llTypes[MMDRV_AUX].lpMlds - 1);
650 if (llTypes[MMDRV_MIXER].lpMlds)
651 HeapFree(GetProcessHeap(), 0, llTypes[MMDRV_MIXER].lpMlds - 1);
652 if (llTypes[MMDRV_MIDIIN].lpMlds)
653 HeapFree(GetProcessHeap(), 0, llTypes[MMDRV_MIDIIN].lpMlds - 1);
654 if (llTypes[MMDRV_MIDIOUT].lpMlds)
655 HeapFree(GetProcessHeap(), 0, llTypes[MMDRV_MIDIOUT].lpMlds - 1);
656 if (llTypes[MMDRV_WAVEIN].lpMlds)
657 HeapFree(GetProcessHeap(), 0, llTypes[MMDRV_WAVEIN].lpMlds - 1);
658 if (llTypes[MMDRV_WAVEOUT].lpMlds)
659 HeapFree(GetProcessHeap(), 0, llTypes[MMDRV_WAVEOUT].lpMlds - 1);
660 }