1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
4 * MMSYTEM low level drivers handling functions
6 * Copyright 1999 Eric Pouech
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include "wine/winbase16.h"
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(mmsys);
34 extern WORD CALLBACK MMDRV_CallTo16_word_wwlll(FARPROC16,WORD,WORD,LONG,LONG,LONG);
36 /* each known type of driver has an instance of this structure */
37 typedef struct tagWINE_LLTYPE {
38 /* those attributes depend on the specification of the type */
39 LPSTR typestr; /* name (for debugging) */
40 BOOL bSupportMapper; /* if type is allowed to support mapper */
41 MMDRV_MAPFUNC Map16To32A; /* those are function pointers to handle */
42 MMDRV_MAPFUNC UnMap16To32A; /* the parameter conversion (16 vs 32 bit) */
43 MMDRV_MAPFUNC Map32ATo16; /* when hi-func (in mmsystem or winmm) and */
44 MMDRV_MAPFUNC UnMap32ATo16; /* low-func (in .drv) do not match */
45 LPDRVCALLBACK Callback; /* handles callback for a specified type */
46 /* those attributes reflect the loaded/current situation for the type */
47 UINT wMaxId; /* number of loaded devices (sum across all loaded drivers */
48 LPWINE_MLD lpMlds; /* "static" mlds to access the part though device IDs */
49 int nMapper; /* index to mapper */
52 static int MMDrvsHi /* = 0 */;
53 static WINE_MM_DRIVER MMDrvs[3];
54 static LPWINE_MLD MM_MLDrvs[40];
55 #define MAX_MM_MLDRVS (sizeof(MM_MLDrvs) / sizeof(MM_MLDrvs[0]))
57 /******************************************************************
61 BOOL MMDRV_Is32(unsigned int idx)
63 return MMDrvs[idx].bIs32;
66 /**************************************************************************
67 * MMDRV_GetDescription32 [internal]
69 static BOOL MMDRV_GetDescription32(const char* fname, char* buf, int buflen)
78 FARPROC pGetFileVersionInfoSizeA;
79 FARPROC pGetFileVersionInfoA;
80 FARPROC pVerQueryValueA;
83 #define E(_x) do {TRACE _x;goto theEnd;} while(0)
85 if (OpenFile(fname, &ofs, OF_EXIST)==HFILE_ERROR) E(("Can't find file %s\n", fname));
87 if (!(hmodule = LoadLibraryA( "version.dll" ))) goto theEnd;
88 if (!(pGetFileVersionInfoSizeA = GetProcAddress( hmodule, "GetFileVersionInfoSizeA" )))
90 if (!(pGetFileVersionInfoA = GetProcAddress( hmodule, "GetFileVersionInfoA" )))
92 if (!(pVerQueryValueA = GetProcAddress( hmodule, "pVerQueryValueA" )))
95 if (!(dw = pGetFileVersionInfoSizeA(ofs.szPathName, &h))) E(("Can't get FVIS\n"));
96 if (!(ptr = HeapAlloc(GetProcessHeap(), 0, dw))) E(("OOM\n"));
97 if (!pGetFileVersionInfoA(ofs.szPathName, h, dw, ptr)) E(("Can't get FVI\n"));
99 #define A(_x) if (pVerQueryValueA(ptr, "\\StringFileInfo\\040904B0\\" #_x, &val, &u)) \
100 TRACE(#_x " => %s\n", (LPSTR)val); else TRACE(#_x " @\n")
116 if (!pVerQueryValueA(ptr, "\\StringFileInfo\\040904B0\\ProductName", &val, &u)) E(("Can't get product name\n"));
117 lstrcpynA(buf, val, buflen);
122 HeapFree(GetProcessHeap(), 0, ptr);
123 if (hmodule) FreeLibrary( hmodule );
127 #define A(_x,_y) {#_y, _x, \
128 MMDRV_##_y##_Map16To32A, MMDRV_##_y##_UnMap16To32A, \
129 MMDRV_##_y##_Map32ATo16, MMDRV_##_y##_UnMap32ATo16, \
130 MMDRV_##_y##_Callback, 0, NULL, -1}
132 /* Note: the indices of this array must match the definitions
133 * of the MMDRV_???? manifest constants
135 static WINE_LLTYPE llTypes[MMDRV_MAX] = {
145 /**************************************************************************
146 * MMDRV_GetNum [internal]
148 UINT MMDRV_GetNum(UINT type)
150 assert(type < MMDRV_MAX);
151 return llTypes[type].wMaxId;
154 /**************************************************************************
155 * WINE_Message [internal]
157 DWORD MMDRV_Message(LPWINE_MLD mld, WORD wMsg, DWORD dwParam1,
158 DWORD dwParam2, BOOL bFrom32)
160 LPWINE_MM_DRIVER lpDrv;
162 WINE_MM_DRIVER_PART* part;
163 WINE_LLTYPE* llType = &llTypes[mld->type];
167 TRACE("(%s %u %u 0x%08lx 0x%08lx 0x%08lx %c)!\n",
168 llTypes[mld->type].typestr, mld->uDeviceID, wMsg,
169 mld->dwDriverInstance, dwParam1, dwParam2, bFrom32?'Y':'N');
171 if (mld->uDeviceID == (UINT16)-1) {
172 if (!llType->bSupportMapper) {
173 WARN("uDev=-1 requested on non-mappable ll type %s\n",
174 llTypes[mld->type].typestr);
175 return MMSYSERR_BADDEVICEID;
179 if (mld->uDeviceID >= llType->wMaxId) {
180 WARN("uDev(%u) requested >= max (%d)\n", mld->uDeviceID, llType->wMaxId);
181 return MMSYSERR_BADDEVICEID;
183 devID = mld->uDeviceID;
186 lpDrv = &MMDrvs[mld->mmdIndex];
187 part = &lpDrv->parts[mld->type];
190 /* some sanity checks */
191 if (!(part->nIDMin <= devID))
192 ERR("!(part->nIDMin(%d) <= devID(%d))\n", part->nIDMin, devID);
193 if (!(devID < part->nIDMax))
194 ERR("!(devID(%d) < part->nIDMax(%d))\n", devID, part->nIDMax);
198 assert(part->u.fnMessage32);
201 TRACE("Calling message(dev=%u msg=%u usr=0x%08lx p1=0x%08lx p2=0x%08lx\n",
202 mld->uDeviceID, wMsg, mld->dwDriverInstance, dwParam1, dwParam2);
203 ret = part->u.fnMessage32(mld->uDeviceID, wMsg, mld->dwDriverInstance, dwParam1, dwParam2);
204 TRACE("=> %lu\n", ret);
206 map = llType->Map16To32A(wMsg, &mld->dwDriverInstance, &dwParam1, &dwParam2);
208 case WINMM_MAP_NOMEM:
209 ret = MMSYSERR_NOMEM;
211 case WINMM_MAP_MSGERROR:
212 FIXME("NIY: no conversion yet 16->32 (%u)\n", wMsg);
213 ret = MMSYSERR_ERROR;
216 case WINMM_MAP_OKMEM:
217 TRACE("Calling message(dev=%u msg=%u usr=0x%08lx p1=0x%08lx p2=0x%08lx\n",
218 mld->uDeviceID, wMsg, mld->dwDriverInstance, dwParam1, dwParam2);
219 ret = part->u.fnMessage32(mld->uDeviceID, wMsg, mld->dwDriverInstance,
221 TRACE("=> %lu\n", ret);
222 if (map == WINMM_MAP_OKMEM)
223 llType->UnMap16To32A(wMsg, &mld->dwDriverInstance, &dwParam1, &dwParam2);
227 ret = MMSYSERR_NOTSUPPORTED;
232 assert(part->u.fnMessage16);
235 map = llType->Map32ATo16(wMsg, &mld->dwDriverInstance, &dwParam1, &dwParam2);
237 case WINMM_MAP_NOMEM:
238 ret = MMSYSERR_NOMEM;
240 case WINMM_MAP_MSGERROR:
241 FIXME("NIY: no conversion yet 32->16 (%u)\n", wMsg);
242 ret = MMSYSERR_ERROR;
245 case WINMM_MAP_OKMEM:
246 TRACE("Calling message(dev=%u msg=%u usr=0x%08lx p1=0x%08lx p2=0x%08lx\n",
247 mld->uDeviceID, wMsg, mld->dwDriverInstance, dwParam1, dwParam2);
248 ret = MMDRV_CallTo16_word_wwlll((FARPROC16)part->u.fnMessage16, mld->uDeviceID,
249 wMsg, mld->dwDriverInstance, dwParam1, dwParam2);
250 TRACE("=> %lu\n", ret);
251 if (map == WINMM_MAP_OKMEM)
252 llType->UnMap32ATo16(wMsg, &mld->dwDriverInstance, &dwParam1, &dwParam2);
256 ret = MMSYSERR_NOTSUPPORTED;
260 TRACE("Calling message(dev=%u msg=%u usr=0x%08lx p1=0x%08lx p2=0x%08lx\n",
261 mld->uDeviceID, wMsg, mld->dwDriverInstance, dwParam1, dwParam2);
262 ret = MMDRV_CallTo16_word_wwlll((FARPROC16)part->u.fnMessage16, mld->uDeviceID,
263 wMsg, mld->dwDriverInstance, dwParam1, dwParam2);
264 TRACE("=> %lu\n", ret);
270 /**************************************************************************
271 * MMDRV_Alloc [internal]
273 LPWINE_MLD MMDRV_Alloc(UINT size, UINT type, LPHANDLE hndl, DWORD* dwFlags,
274 DWORD* dwCallback, DWORD* dwInstance, BOOL bFrom32)
278 mld = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
279 if (!mld) return NULL;
281 /* find an empty slot in MM_MLDrvs table */
282 for (*hndl = 0; *hndl < MAX_MM_MLDRVS; (*hndl)++) {
283 if (!MM_MLDrvs[(UINT)*hndl]) break;
285 if (*hndl == MAX_MM_MLDRVS) {
286 /* the MM_MLDrvs table could be made growable in the future if needed */
287 ERR("Too many open drivers\n");
290 MM_MLDrvs[(UINT)*hndl] = mld;
291 *hndl = (HANDLE)((UINT)*hndl | 0x8000);
294 if ((UINT)*hndl < MMDRV_GetNum(type) || HIWORD(*hndl) != 0) {
295 /* FIXME: those conditions must be fulfilled so that:
296 * - we can distinguish between device IDs and handles
297 * - we can use handles as 16 or 32 bit entities
299 ERR("Shouldn't happen. Bad allocation scheme\n");
302 mld->bFrom32 = bFrom32;
303 mld->dwFlags = HIWORD(*dwFlags);
304 mld->dwCallback = *dwCallback;
305 mld->dwClientInstance = *dwInstance;
307 *dwFlags = LOWORD(*dwFlags) | CALLBACK_FUNCTION;
308 *dwCallback = (DWORD)llTypes[type].Callback;
309 *dwInstance = (DWORD)mld; /* FIXME: wouldn't some 16 bit drivers only use the loword ? */
314 /**************************************************************************
315 * MMDRV_Free [internal]
317 void MMDRV_Free(HANDLE hndl, LPWINE_MLD mld)
319 if ((UINT)hndl & 0x8000) {
320 unsigned idx = (UINT)hndl & ~0x8000;
321 if (idx < sizeof(MM_MLDrvs) / sizeof(MM_MLDrvs[0])) {
322 MM_MLDrvs[idx] = NULL;
323 HeapFree(GetProcessHeap(), 0, mld);
327 ERR("Bad Handle %08x at %p (not freed)\n", hndl, mld);
330 /**************************************************************************
331 * MMDRV_Open [internal]
333 DWORD MMDRV_Open(LPWINE_MLD mld, UINT wMsg, DWORD dwParam1, DWORD dwFlags)
335 DWORD dwRet = MMSYSERR_BADDEVICEID;
337 WINE_LLTYPE* llType = &llTypes[mld->type];
339 mld->dwDriverInstance = (DWORD)&dwInstance;
341 if (mld->uDeviceID == (UINT)-1 || mld->uDeviceID == (UINT16)-1) {
342 TRACE("MAPPER mode requested !\n");
343 /* check if mapper is supported by type */
344 if (llType->bSupportMapper) {
345 if (llType->nMapper == -1) {
346 /* no driver for mapper has been loaded, try a dumb implementation */
347 TRACE("No mapper loaded, doing it by hand\n");
348 for (mld->uDeviceID = 0; mld->uDeviceID < llType->wMaxId; mld->uDeviceID++) {
349 if ((dwRet = MMDRV_Open(mld, wMsg, dwParam1, dwFlags)) == MMSYSERR_NOERROR) {
350 /* to share this function epilog */
351 dwInstance = mld->dwDriverInstance;
356 mld->uDeviceID = (UINT16)-1;
357 mld->mmdIndex = llType->lpMlds[-1].mmdIndex;
358 TRACE("Setting mmdIndex to %u\n", mld->mmdIndex);
359 dwRet = MMDRV_Message(mld, wMsg, dwParam1, dwFlags, TRUE);
363 if (mld->uDeviceID < llType->wMaxId) {
364 mld->mmdIndex = llType->lpMlds[mld->uDeviceID].mmdIndex;
365 TRACE("Setting mmdIndex to %u\n", mld->mmdIndex);
366 dwRet = MMDRV_Message(mld, wMsg, dwParam1, dwFlags, TRUE);
369 if (dwRet == MMSYSERR_NOERROR)
370 mld->dwDriverInstance = dwInstance;
374 /**************************************************************************
375 * MMDRV_Close [internal]
377 DWORD MMDRV_Close(LPWINE_MLD mld, UINT wMsg)
379 return MMDRV_Message(mld, wMsg, 0L, 0L, TRUE);
382 /**************************************************************************
383 * MMDRV_GetByID [internal]
385 LPWINE_MLD MMDRV_GetByID(UINT uDevID, UINT type)
387 if (uDevID < llTypes[type].wMaxId)
388 return &llTypes[type].lpMlds[uDevID];
389 if ((uDevID == (UINT16)-1 || uDevID == (UINT)-1) && llTypes[type].nMapper != -1)
390 return &llTypes[type].lpMlds[-1];
394 /**************************************************************************
395 * MMDRV_Get [internal]
397 LPWINE_MLD MMDRV_Get(HANDLE hndl, UINT type, BOOL bCanBeID)
399 LPWINE_MLD mld = NULL;
401 assert(type < MMDRV_MAX);
403 if ((UINT)hndl >= llTypes[type].wMaxId &&
404 hndl != (UINT16)-1 && hndl != (UINT)-1) {
405 if ((UINT)hndl & 0x8000) {
406 hndl = (HANDLE)((UINT)hndl & ~0x8000);
407 if (hndl < sizeof(MM_MLDrvs) / sizeof(MM_MLDrvs[0])) {
408 mld = MM_MLDrvs[(UINT)hndl];
409 if (!mld || !HeapValidate(GetProcessHeap(), 0, mld) || mld->type != type)
412 hndl = (HANDLE)((UINT)hndl | 0x8000);
415 if (mld == NULL && bCanBeID) {
416 mld = MMDRV_GetByID((UINT)hndl, type);
421 /**************************************************************************
422 * MMDRV_GetRelated [internal]
424 LPWINE_MLD MMDRV_GetRelated(HANDLE hndl, UINT srcType,
425 BOOL bSrcCanBeID, UINT dstType)
429 if ((mld = MMDRV_Get(hndl, srcType, bSrcCanBeID)) != NULL) {
430 WINE_MM_DRIVER_PART* part = &MMDrvs[mld->mmdIndex].parts[dstType];
431 if (part->nIDMin < part->nIDMax)
432 return MMDRV_GetByID(part->nIDMin, dstType);
437 /**************************************************************************
438 * MMDRV_PhysicalFeatures [internal]
440 UINT MMDRV_PhysicalFeatures(LPWINE_MLD mld, UINT uMsg, DWORD dwParam1,
443 WINE_MM_DRIVER* lpDrv = &MMDrvs[mld->mmdIndex];
445 TRACE("(%p, %04x, %08lx, %08lx)\n", mld, uMsg, dwParam1, dwParam2);
447 /* all those function calls are undocumented */
449 case DRV_QUERYDRVENTRY:
450 lstrcpynA((LPSTR)dwParam1, lpDrv->drvname, LOWORD(dwParam2));
452 case DRV_QUERYDEVNODE:
453 *(LPDWORD)dwParam1 = 0L; /* should be DevNode */
456 WARN("NIY QueryName\n");
458 case DRV_QUERYDRIVERIDS:
459 WARN("NIY call VxD\n");
460 /* should call VxD MMDEVLDR with (DevNode, dwParam1 and dwParam2) as pmts
461 * dwParam1 is buffer and dwParam2 is sizeof buffer
462 * I don't know where the result is stored though
465 case DRV_QUERYMAPPABLE:
466 return (lpDrv->bIsMapper) ? 2 : 0;
468 case DRV_QUERYDSOUNDIFACE: /* Wine-specific: Retrieve DirectSound interface */
469 return MMDRV_Message(mld, uMsg, dwParam1, dwParam2, TRUE);
472 WARN("Unknown call %04x\n", uMsg);
473 return MMSYSERR_INVALPARAM;
478 /**************************************************************************
479 * MMDRV_InitPerType [internal]
481 static BOOL MMDRV_InitPerType(LPWINE_MM_DRIVER lpDrv, UINT type, UINT wMsg)
483 WINE_MM_DRIVER_PART* part = &lpDrv->parts[type];
488 part->nIDMin = part->nIDMax = 0;
490 /* for DRVM_INIT and DRVM_ENABLE, dwParam2 should be PnP node */
491 /* the DRVM_ENABLE is only required when the PnP node is non zero */
493 if (lpDrv->bIs32 && part->u.fnMessage32) {
494 ret = part->u.fnMessage32(0, DRVM_INIT, 0L, 0L, 0L);
495 TRACE("DRVM_INIT => %08lx\n", ret);
497 ret = part->u.fnMessage32(0, DRVM_ENABLE, 0L, 0L, 0L);
498 TRACE("DRVM_ENABLE => %08lx\n", ret);
500 count = part->u.fnMessage32(0, wMsg, 0L, 0L, 0L);
501 } else if (!lpDrv->bIs32 && part->u.fnMessage16) {
502 ret = MMDRV_CallTo16_word_wwlll((FARPROC16)part->u.fnMessage16,
503 0, DRVM_INIT, 0L, 0L, 0L);
504 TRACE("DRVM_INIT => %08lx\n", ret);
506 ret = MMDRV_CallTo16_word_wwlll((FARPROC16)part->u.fnMessage16,
507 0, DRVM_ENABLE, 0L, 0L, 0L);
508 TRACE("DRVM_ENABLE => %08lx\n", ret);
510 count = MMDRV_CallTo16_word_wwlll((FARPROC16)part->u.fnMessage16,
511 0, wMsg, 0L, 0L, 0L);
516 TRACE("Got %u dev for (%s:%s)\n", count, lpDrv->drvname, llTypes[type].typestr);
518 /* got some drivers */
519 if (lpDrv->bIsMapper) {
520 /* it seems native mappers return 0 devices :-( */
521 if (llTypes[type].nMapper != -1)
522 ERR("Two mappers for type %s (%d, %s)\n",
523 llTypes[type].typestr, llTypes[type].nMapper, lpDrv->drvname);
525 ERR("Strange: mapper with %d > 1 devices\n", count);
526 llTypes[type].nMapper = MMDrvsHi;
530 part->nIDMin = llTypes[type].wMaxId;
531 llTypes[type].wMaxId += count;
532 part->nIDMax = llTypes[type].wMaxId;
534 TRACE("Setting min=%d max=%d (ttop=%d) for (%s:%s)\n",
535 part->nIDMin, part->nIDMax, llTypes[type].wMaxId,
536 lpDrv->drvname, llTypes[type].typestr);
537 /* realloc translation table */
538 llTypes[type].lpMlds = (LPWINE_MLD)
539 HeapReAlloc(GetProcessHeap(), 0, (llTypes[type].lpMlds) ? llTypes[type].lpMlds - 1 : NULL,
540 sizeof(WINE_MLD) * (llTypes[type].wMaxId + 1)) + 1;
541 /* re-build the translation table */
542 if (llTypes[type].nMapper != -1) {
543 TRACE("%s:Trans[%d] -> %s\n", llTypes[type].typestr, -1, MMDrvs[llTypes[type].nMapper].drvname);
544 llTypes[type].lpMlds[-1].uDeviceID = (UINT16)-1;
545 llTypes[type].lpMlds[-1].type = type;
546 llTypes[type].lpMlds[-1].mmdIndex = llTypes[type].nMapper;
547 llTypes[type].lpMlds[-1].dwDriverInstance = 0;
549 for (i = k = 0; i <= MMDrvsHi; i++) {
550 while (MMDrvs[i].parts[type].nIDMin <= k && k < MMDrvs[i].parts[type].nIDMax) {
551 TRACE("%s:Trans[%d] -> %s\n", llTypes[type].typestr, k, MMDrvs[i].drvname);
552 llTypes[type].lpMlds[k].uDeviceID = k;
553 llTypes[type].lpMlds[k].type = type;
554 llTypes[type].lpMlds[k].mmdIndex = i;
555 llTypes[type].lpMlds[k].dwDriverInstance = 0;
562 /**************************************************************************
563 * MMDRV_Install [internal]
565 static BOOL MMDRV_Install(LPCSTR drvRegName, LPCSTR drvFileName, BOOL bIsMapper)
569 LPWINE_MM_DRIVER lpDrv = &MMDrvs[MMDrvsHi];
572 TRACE("('%s', '%s', mapper=%c);\n", drvRegName, drvFileName, bIsMapper ? 'Y' : 'N');
574 /* be sure that size of MMDrvs matches the max number of loadable drivers !!
575 * if not just increase size of MMDrvs */
576 assert(MMDrvsHi <= sizeof(MMDrvs)/sizeof(MMDrvs[0]));
578 for (i = 0; i < MMDrvsHi; i++) {
579 if (!strcmp(drvRegName, MMDrvs[i].drvname)) return FALSE;
582 memset(lpDrv, 0, sizeof(*lpDrv));
584 if (!(lpDrv->hDriver = OpenDriverA(drvFileName, 0, 0))) {
585 WARN("Couldn't open driver '%s'\n", drvFileName);
589 d = DRIVER_FindFromHDrvr(lpDrv->hDriver);
590 lpDrv->bIs32 = (d->dwFlags & WINE_GDF_16BIT) ? FALSE : TRUE;
592 /* Then look for xxxMessage functions */
593 #define AA(_h,_w,_x,_y,_z) \
594 func = (WINEMM_msgFunc##_y) _z ((_h), #_x); \
596 { lpDrv->parts[_w].u.fnMessage##_y = func; count++; \
597 TRACE("Got %d bit func '%s'\n", _y, #_x); }
600 WINEMM_msgFunc32 func;
602 if (d->d.d32.hModule) {
603 #define A(_x,_y) AA(d->d.d32.hModule,_x,_y,32,GetProcAddress)
604 A(MMDRV_AUX, auxMessage);
605 A(MMDRV_MIXER, mixMessage);
606 A(MMDRV_MIDIIN, midMessage);
607 A(MMDRV_MIDIOUT, modMessage);
608 A(MMDRV_WAVEIN, widMessage);
609 A(MMDRV_WAVEOUT, wodMessage);
613 WINEMM_msgFunc16 func;
616 * DESCRIPTION 'wave,aux,mixer:Creative Labs Sound Blaster 16 Driver'
617 * The beginning of the module description indicates the driver supports
618 * waveform, auxiliary, and mixer devices. Use one of the following
619 * device-type names, followed by a colon (:) to indicate the type of
620 * device your driver supports. If the driver supports more than one
621 * type of device, separate each device-type name with a comma (,).
623 * wave for waveform audio devices
624 * wavemapper for wave mappers
625 * midi for MIDI audio devices
626 * midimapper for midi mappers
627 * aux for auxiliary audio devices
628 * mixer for mixer devices
631 if (d->d.d16.hDriver16) {
632 HMODULE16 hMod16 = GetDriverModuleHandle16(d->d.d16.hDriver16);
634 #define A(_x,_y) AA(hMod16,_x,_y,16,GetProcAddress16)
635 A(MMDRV_AUX, auxMessage);
636 A(MMDRV_MIXER, mixMessage);
637 A(MMDRV_MIDIIN, midMessage);
638 A(MMDRV_MIDIOUT, modMessage);
639 A(MMDRV_WAVEIN, widMessage);
640 A(MMDRV_WAVEOUT, wodMessage);
646 if (TRACE_ON(mmsys)) {
647 if ((lpDrv->bIs32) ? MMDRV_GetDescription32(drvFileName, buffer, sizeof(buffer)) :
648 MMDRV_GetDescription16(drvFileName, buffer, sizeof(buffer)))
649 TRACE("%s => %s\n", drvFileName, buffer);
651 TRACE("%s => No description\n", drvFileName);
655 CloseDriver(lpDrv->hDriver, 0, 0);
656 WARN("No message functions found\n");
660 /* FIXME: being a mapper or not should be known by another way */
661 /* it's known for NE drvs (the description is of the form '*mapper: *'
662 * I don't have any clue for PE drvs
664 lpDrv->bIsMapper = bIsMapper;
665 lpDrv->drvname = strcpy(HeapAlloc(GetProcessHeap(), 0, strlen(drvRegName) + 1), drvRegName);
667 /* Finish init and get the count of the devices */
668 MMDRV_InitPerType(lpDrv, MMDRV_AUX, AUXDM_GETNUMDEVS);
669 MMDRV_InitPerType(lpDrv, MMDRV_MIXER, MXDM_GETNUMDEVS);
670 MMDRV_InitPerType(lpDrv, MMDRV_MIDIIN, MIDM_GETNUMDEVS);
671 MMDRV_InitPerType(lpDrv, MMDRV_MIDIOUT, MODM_GETNUMDEVS);
672 MMDRV_InitPerType(lpDrv, MMDRV_WAVEIN, WIDM_GETNUMDEVS);
673 MMDRV_InitPerType(lpDrv, MMDRV_WAVEOUT, WODM_GETNUMDEVS);
674 /* FIXME: if all those func calls return FALSE,
675 * then the driver must be unloaded
683 /**************************************************************************
684 * MMDRV_InitFromRegistry [internal]
686 static BOOL MMDRV_InitFromRegistry(void)
695 if (RegCreateKeyA(HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\WinMM", &hKey)) {
696 TRACE("Cannot open WinMM config key\n");
700 size = sizeof(buffer);
701 if (!RegQueryValueExA(hKey, "Drivers", 0, &type, (LPVOID)buffer, &size)) {
704 p2 = strchr(p1, ';');
705 if (p2) *p2++ = '\0';
706 ret |= MMDRV_Install(p1, p1, FALSE);
711 /* finish with mappers */
712 size = sizeof(buffer);
713 if (!RegQueryValueExA(hKey, "WaveMapper", 0, &type, (LPVOID)buffer, &size))
714 ret |= MMDRV_Install("wavemapper", buffer, TRUE);
715 size = sizeof(buffer);
716 if (!RegQueryValueExA(hKey, "MidiMapper", 0, &type, (LPVOID)buffer, &size))
717 ret |= MMDRV_Install("midimapper", buffer, TRUE);
724 /**************************************************************************
725 * MMDRV_InitHardcoded [internal]
727 static BOOL MMDRV_InitHardcoded(void)
729 /* first load hardware drivers */
730 MMDRV_Install("wineoss.drv", "wineoss.drv", FALSE);
732 /* finish with mappers */
733 MMDRV_Install("wavemapper", "msacm.drv", TRUE);
734 MMDRV_Install("midimapper", "midimap.drv", TRUE);
739 /**************************************************************************
740 * MMDRV_Init [internal]
742 BOOL MMDRV_Init(void)
744 /* FIXME: MMDRV_InitFromRegistry shall be MMDRV_Init in a near future */
745 return MMDRV_InitFromRegistry() || MMDRV_InitHardcoded();