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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/port.h"
35 #include "wine/debug.h"
36 #include "wine/exception.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(winmm);
41 LRESULT (*pFnCallMMDrvFunc16)(DWORD,WORD,WORD,LONG,LONG,LONG) /* = NULL */;
42 unsigned (*pFnLoadMMDrvFunc16)(LPCSTR,LPWINE_DRIVER, LPWINE_MM_DRIVER) /* = NULL */;
44 /* each known type of driver has an instance of this structure */
45 typedef struct tagWINE_LLTYPE {
46 /* those attributes depend on the specification of the type */
47 LPCSTR typestr; /* name (for debugging) */
48 BOOL bSupportMapper; /* if type is allowed to support mapper */
49 MMDRV_MAPFUNC Map16To32A; /* those are function pointers to handle */
50 MMDRV_UNMAPFUNC UnMap16To32A; /* the parameter conversion (16 vs 32 bit) */
51 MMDRV_MAPFUNC Map32ATo16; /* when hi-func (in mmsystem or winmm) and */
52 MMDRV_UNMAPFUNC UnMap32ATo16; /* low-func (in .drv) do not match */
53 LPDRVCALLBACK Callback; /* handles callback for a specified type */
54 /* those attributes reflect the loaded/current situation for the type */
55 UINT wMaxId; /* number of loaded devices (sum across all loaded drivers) */
56 LPWINE_MLD lpMlds; /* "static" mlds to access the part though device IDs */
57 int nMapper; /* index to mapper */
60 static int MMDrvsHi /* = 0 */;
61 static WINE_MM_DRIVER MMDrvs[8];
62 static LPWINE_MLD MM_MLDrvs[40];
63 #define MAX_MM_MLDRVS (sizeof(MM_MLDrvs) / sizeof(MM_MLDrvs[0]))
65 #define A(_x,_y) {#_y, _x, NULL, NULL, NULL, NULL, NULL, 0, NULL, -1}
66 /* Note: the indices of this array must match the definitions
67 * of the MMDRV_???? manifest constants
69 static WINE_LLTYPE llTypes[MMDRV_MAX] = {
79 /******************************************************************
84 void MMDRV_InstallMap(unsigned int drv,
85 MMDRV_MAPFUNC mp1632, MMDRV_UNMAPFUNC um1632,
86 MMDRV_MAPFUNC mp3216, MMDRV_UNMAPFUNC um3216,
89 assert(drv < MMDRV_MAX);
90 llTypes[drv].Map16To32A = mp1632;
91 llTypes[drv].UnMap16To32A = um1632;
92 llTypes[drv].Map32ATo16 = mp3216;
93 llTypes[drv].UnMap32ATo16 = um3216;
94 llTypes[drv].Callback = cb;
97 /******************************************************************
101 BOOL MMDRV_Is32(unsigned int idx)
103 TRACE("(%d)\n", idx);
104 return MMDrvs[idx].bIs32;
107 /**************************************************************************
108 * MMDRV_GetDescription32 [internal]
110 static BOOL MMDRV_GetDescription32(const char* fname, char* buf, int buflen)
119 FARPROC pGetFileVersionInfoSizeA;
120 FARPROC pGetFileVersionInfoA;
121 FARPROC pVerQueryValueA;
123 TRACE("(%p, %p, %d)\n", fname, buf, buflen);
125 #define E(_x) do {TRACE _x;goto theEnd;} while(0)
127 if (OpenFile(fname, &ofs, OF_EXIST)==HFILE_ERROR) E(("Can't find file %s\n", fname));
129 if (!(hmodule = LoadLibraryA( "version.dll" ))) goto theEnd;
130 if (!(pGetFileVersionInfoSizeA = GetProcAddress( hmodule, "GetFileVersionInfoSizeA" )))
132 if (!(pGetFileVersionInfoA = GetProcAddress( hmodule, "GetFileVersionInfoA" )))
134 if (!(pVerQueryValueA = GetProcAddress( hmodule, "VerQueryValueA" )))
137 if (!(dw = pGetFileVersionInfoSizeA(ofs.szPathName, &h))) E(("Can't get FVIS\n"));
138 if (!(ptr = HeapAlloc(GetProcessHeap(), 0, dw))) E(("OOM\n"));
139 if (!pGetFileVersionInfoA(ofs.szPathName, h, dw, ptr)) E(("Can't get FVI\n"));
141 #define A(_x) if (pVerQueryValueA(ptr, "\\StringFileInfo\\040904B0\\" #_x, &val, &u)) \
142 TRACE(#_x " => %s\n", (LPSTR)val); else TRACE(#_x " @\n")
158 if (!pVerQueryValueA(ptr, "\\StringFileInfo\\040904B0\\ProductName", &val, &u)) E(("Can't get product name\n"));
159 lstrcpynA(buf, val, buflen);
164 HeapFree(GetProcessHeap(), 0, ptr);
165 if (hmodule) FreeLibrary( hmodule );
169 /**************************************************************************
170 * MMDRV_GetNum [internal]
172 UINT MMDRV_GetNum(UINT type)
174 TRACE("(%04x)\n", type);
175 assert(type < MMDRV_MAX);
176 return llTypes[type].wMaxId;
179 /**************************************************************************
180 * MMDRV_Message [internal]
182 DWORD MMDRV_Message(LPWINE_MLD mld, UINT wMsg, DWORD_PTR dwParam1,
183 DWORD_PTR dwParam2, BOOL bFrom32)
185 LPWINE_MM_DRIVER lpDrv;
187 WINE_MM_DRIVER_PART* part;
188 WINE_LLTYPE* llType = &llTypes[mld->type];
192 TRACE("(%s %u %u 0x%08x 0x%08lx 0x%08lx %c)\n",
193 llTypes[mld->type].typestr, mld->uDeviceID, wMsg,
194 mld->dwDriverInstance, dwParam1, dwParam2, bFrom32?'Y':'N');
196 if (mld->uDeviceID == (UINT16)-1) {
197 if (!llType->bSupportMapper) {
198 WARN("uDev=-1 requested on non-mappable ll type %s\n",
199 llTypes[mld->type].typestr);
200 return MMSYSERR_BADDEVICEID;
204 if (mld->uDeviceID >= llType->wMaxId) {
205 WARN("uDev(%u) requested >= max (%d)\n", mld->uDeviceID, llType->wMaxId);
206 return MMSYSERR_BADDEVICEID;
208 devID = mld->uDeviceID;
211 lpDrv = &MMDrvs[mld->mmdIndex];
212 part = &lpDrv->parts[mld->type];
215 /* some sanity checks */
216 if (!(part->nIDMin <= devID))
217 ERR("!(part->nIDMin(%d) <= devID(%d))\n", part->nIDMin, devID);
218 if (!(devID < part->nIDMax))
219 ERR("!(devID(%d) < part->nIDMax(%d))\n", devID, part->nIDMax);
223 assert(part->u.fnMessage32);
226 TRACE("Calling message(dev=%u msg=%u usr=0x%08x p1=0x%08lx p2=0x%08lx)\n",
227 mld->uDeviceID, wMsg, mld->dwDriverInstance, dwParam1, dwParam2);
228 ret = part->u.fnMessage32(mld->uDeviceID, wMsg, mld->dwDriverInstance, dwParam1, dwParam2);
229 TRACE("=> %s\n", WINMM_ErrorToString(ret));
231 map = llType->Map16To32A(wMsg, &mld->dwDriverInstance, &dwParam1, &dwParam2);
233 case WINMM_MAP_NOMEM:
234 ret = MMSYSERR_NOMEM;
236 case WINMM_MAP_MSGERROR:
237 FIXME("NIY: no conversion yet 16->32 (%u)\n", wMsg);
238 ret = MMSYSERR_ERROR;
241 case WINMM_MAP_OKMEM:
242 TRACE("Calling message(dev=%u msg=%u usr=0x%08x p1=0x%08lx p2=0x%08lx)\n",
243 mld->uDeviceID, wMsg, mld->dwDriverInstance, dwParam1, dwParam2);
244 ret = part->u.fnMessage32(mld->uDeviceID, wMsg, mld->dwDriverInstance,
246 TRACE("=> %s\n", WINMM_ErrorToString(ret));
247 if (map == WINMM_MAP_OKMEM)
248 llType->UnMap16To32A(wMsg, &mld->dwDriverInstance, &dwParam1, &dwParam2, ret);
252 ret = MMSYSERR_NOTSUPPORTED;
257 assert(part->u.fnMessage16 && pFnCallMMDrvFunc16);
260 map = llType->Map32ATo16(wMsg, &mld->dwDriverInstance, &dwParam1, &dwParam2);
262 case WINMM_MAP_NOMEM:
263 ret = MMSYSERR_NOMEM;
265 case WINMM_MAP_MSGERROR:
266 FIXME("NIY: no conversion yet 32->16 (%u)\n", wMsg);
267 ret = MMSYSERR_ERROR;
270 case WINMM_MAP_OKMEM:
271 TRACE("Calling message(dev=%u msg=%u usr=0x%08x p1=0x%08lx p2=0x%08lx)\n",
272 mld->uDeviceID, wMsg, mld->dwDriverInstance, dwParam1, dwParam2);
273 ret = pFnCallMMDrvFunc16((DWORD)part->u.fnMessage16,
274 mld->uDeviceID, wMsg, mld->dwDriverInstance,
276 TRACE("=> %s\n", WINMM_ErrorToString(ret));
277 if (map == WINMM_MAP_OKMEM)
278 llType->UnMap32ATo16(wMsg, &mld->dwDriverInstance, &dwParam1, &dwParam2, ret);
282 ret = MMSYSERR_NOTSUPPORTED;
286 TRACE("Calling message(dev=%u msg=%u usr=0x%08x p1=0x%08lx p2=0x%08lx)\n",
287 mld->uDeviceID, wMsg, mld->dwDriverInstance, dwParam1, dwParam2);
288 ret = pFnCallMMDrvFunc16((DWORD)part->u.fnMessage16,
289 mld->uDeviceID, wMsg, mld->dwDriverInstance,
291 TRACE("=> %s\n", WINMM_ErrorToString(ret));
297 /**************************************************************************
298 * MMDRV_Alloc [internal]
300 LPWINE_MLD MMDRV_Alloc(UINT size, UINT type, LPHANDLE hndl, DWORD* dwFlags,
301 DWORD_PTR* dwCallback, DWORD_PTR* dwInstance, BOOL bFrom32)
305 TRACE("(%d, %04x, %p, %p, %p, %p, %c)\n",
306 size, type, hndl, dwFlags, dwCallback, dwInstance, bFrom32?'Y':'N');
308 mld = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
309 if (!mld) return NULL;
311 /* find an empty slot in MM_MLDrvs table */
312 for (i = 0; i < MAX_MM_MLDRVS; i++) if (!MM_MLDrvs[i]) break;
314 if (i == MAX_MM_MLDRVS) {
315 /* the MM_MLDrvs table could be made growable in the future if needed */
316 ERR("Too many open drivers\n");
317 HeapFree(GetProcessHeap(), 0, mld);
321 *hndl = (HANDLE)(i | 0x8000);
324 if ((UINT)*hndl < MMDRV_GetNum(type) || HIWORD(*hndl) != 0) {
325 /* FIXME: those conditions must be fulfilled so that:
326 * - we can distinguish between device IDs and handles
327 * - we can use handles as 16 or 32 bit entities
329 ERR("Shouldn't happen. Bad allocation scheme\n");
332 mld->bFrom32 = bFrom32;
333 mld->dwFlags = HIWORD(*dwFlags);
334 mld->dwCallback = *dwCallback;
335 mld->dwClientInstance = *dwInstance;
337 if (llTypes[type].Callback)
339 *dwFlags = LOWORD(*dwFlags) | CALLBACK_FUNCTION;
340 *dwCallback = (DWORD)llTypes[type].Callback;
341 *dwInstance = (DWORD)mld; /* FIXME: wouldn't some 16 bit drivers only use the loword ? */
347 /**************************************************************************
348 * MMDRV_Free [internal]
350 void MMDRV_Free(HANDLE hndl, LPWINE_MLD mld)
352 TRACE("(%p, %p)\n", hndl, mld);
354 if ((UINT)hndl & 0x8000) {
355 unsigned idx = (UINT)hndl & ~0x8000;
356 if (idx < sizeof(MM_MLDrvs) / sizeof(MM_MLDrvs[0])) {
357 MM_MLDrvs[idx] = NULL;
358 HeapFree(GetProcessHeap(), 0, mld);
362 ERR("Bad Handle %p at %p (not freed)\n", hndl, mld);
365 /**************************************************************************
366 * MMDRV_Open [internal]
368 DWORD MMDRV_Open(LPWINE_MLD mld, UINT wMsg, DWORD dwParam1, DWORD dwFlags)
370 DWORD dwRet = MMSYSERR_BADDEVICEID;
372 WINE_LLTYPE* llType = &llTypes[mld->type];
373 TRACE("(%p, %04x, 0x%08x, 0x%08x)\n", mld, wMsg, dwParam1, dwFlags);
375 mld->dwDriverInstance = (DWORD)&dwInstance;
377 if (mld->uDeviceID == (UINT)-1 || mld->uDeviceID == (UINT16)-1) {
378 TRACE("MAPPER mode requested !\n");
379 /* check if mapper is supported by type */
380 if (llType->bSupportMapper) {
381 if (llType->nMapper == -1) {
382 /* no driver for mapper has been loaded, try a dumb implementation */
383 TRACE("No mapper loaded, doing it by hand\n");
384 for (mld->uDeviceID = 0; mld->uDeviceID < llType->wMaxId; mld->uDeviceID++) {
385 if ((dwRet = MMDRV_Open(mld, wMsg, dwParam1, dwFlags)) == MMSYSERR_NOERROR) {
386 /* to share this function epilog */
387 dwInstance = mld->dwDriverInstance;
392 mld->uDeviceID = (UINT16)-1;
393 mld->mmdIndex = llType->lpMlds[-1].mmdIndex;
394 TRACE("Setting mmdIndex to %u\n", mld->mmdIndex);
395 dwRet = MMDRV_Message(mld, wMsg, dwParam1, dwFlags, TRUE);
399 if (mld->uDeviceID < llType->wMaxId) {
400 mld->mmdIndex = llType->lpMlds[mld->uDeviceID].mmdIndex;
401 TRACE("Setting mmdIndex to %u\n", mld->mmdIndex);
402 dwRet = MMDRV_Message(mld, wMsg, dwParam1, dwFlags, TRUE);
405 if (dwRet == MMSYSERR_NOERROR)
406 mld->dwDriverInstance = dwInstance;
410 /**************************************************************************
411 * MMDRV_Close [internal]
413 DWORD MMDRV_Close(LPWINE_MLD mld, UINT wMsg)
415 TRACE("(%p, %04x)\n", mld, wMsg);
416 return MMDRV_Message(mld, wMsg, 0L, 0L, TRUE);
419 /**************************************************************************
420 * MMDRV_GetByID [internal]
422 static LPWINE_MLD MMDRV_GetByID(UINT uDevID, UINT type)
424 TRACE("(%04x, %04x)\n", uDevID, type);
425 if (uDevID < llTypes[type].wMaxId)
426 return &llTypes[type].lpMlds[uDevID];
427 if ((uDevID == (UINT16)-1 || uDevID == (UINT)-1) && llTypes[type].nMapper != -1)
428 return &llTypes[type].lpMlds[-1];
432 /**************************************************************************
433 * MMDRV_Get [internal]
435 LPWINE_MLD MMDRV_Get(HANDLE _hndl, UINT type, BOOL bCanBeID)
437 LPWINE_MLD mld = NULL;
438 UINT hndl = (UINT)_hndl;
439 TRACE("(%p, %04x, %c)\n", _hndl, type, bCanBeID ? 'Y' : 'N');
441 assert(type < MMDRV_MAX);
443 if (hndl >= llTypes[type].wMaxId &&
444 hndl != (UINT16)-1 && hndl != (UINT)-1) {
446 UINT idx = hndl & ~0x8000;
447 if (idx < sizeof(MM_MLDrvs) / sizeof(MM_MLDrvs[0])) {
450 mld = MM_MLDrvs[idx];
451 if (mld && mld->type != type) mld = NULL;
461 if (mld == NULL && bCanBeID) {
462 mld = MMDRV_GetByID(hndl, type);
467 /**************************************************************************
468 * MMDRV_GetRelated [internal]
470 LPWINE_MLD MMDRV_GetRelated(HANDLE hndl, UINT srcType,
471 BOOL bSrcCanBeID, UINT dstType)
474 TRACE("(%p, %04x, %c, %04x)\n",
475 hndl, srcType, bSrcCanBeID ? 'Y' : 'N', dstType);
477 if ((mld = MMDRV_Get(hndl, srcType, bSrcCanBeID)) != NULL) {
478 WINE_MM_DRIVER_PART* part = &MMDrvs[mld->mmdIndex].parts[dstType];
479 if (part->nIDMin < part->nIDMax)
480 return MMDRV_GetByID(part->nIDMin, dstType);
485 /**************************************************************************
486 * MMDRV_PhysicalFeatures [internal]
488 UINT MMDRV_PhysicalFeatures(LPWINE_MLD mld, UINT uMsg, DWORD dwParam1,
491 WINE_MM_DRIVER* lpDrv = &MMDrvs[mld->mmdIndex];
493 TRACE("(%p, %04x, %08x, %08x)\n", mld, uMsg, dwParam1, dwParam2);
495 /* all those function calls are undocumented */
497 case DRV_QUERYDRVENTRY:
498 lstrcpynA((LPSTR)dwParam1, lpDrv->drvname, LOWORD(dwParam2));
500 case DRV_QUERYDEVNODE:
501 *(LPDWORD)dwParam1 = 0L; /* should be DevNode */
504 WARN("NIY QueryName\n");
506 case DRV_QUERYDRIVERIDS:
507 WARN("NIY call VxD\n");
508 /* should call VxD MMDEVLDR with (DevNode, dwParam1 and dwParam2) as pmts
509 * dwParam1 is buffer and dwParam2 is sizeof(buffer)
510 * I don't know where the result is stored though
513 case DRV_QUERYMAPPABLE:
514 return (lpDrv->bIsMapper) ? 2 : 0;
516 case DRVM_MAPPER_PREFERRED_GET:
517 /* FIXME: get from registry someday */
518 *((LPDWORD)dwParam1) = -1; /* No preferred device */
519 *((LPDWORD)dwParam2) = 0;
522 case DRV_QUERYDEVICEINTERFACE:
523 case DRV_QUERYDEVICEINTERFACESIZE:
524 return MMDRV_Message(mld, uMsg, dwParam1, dwParam2, TRUE);
526 case DRV_QUERYDSOUNDIFACE: /* Wine-specific: Retrieve DirectSound interface */
527 case DRV_QUERYDSOUNDDESC: /* Wine-specific: Retrieve DirectSound driver description*/
528 return MMDRV_Message(mld, uMsg, dwParam1, dwParam2, TRUE);
531 WARN("Unknown call %04x\n", uMsg);
532 return MMSYSERR_INVALPARAM;
537 /**************************************************************************
538 * MMDRV_InitPerType [internal]
540 static BOOL MMDRV_InitPerType(LPWINE_MM_DRIVER lpDrv, UINT type, UINT wMsg)
542 WINE_MM_DRIVER_PART* part = &lpDrv->parts[type];
546 TRACE("(%p, %04x, %04x)\n", lpDrv, type, wMsg);
548 part->nIDMin = part->nIDMax = 0;
550 /* for DRVM_INIT and DRVM_ENABLE, dwParam2 should be PnP node */
551 /* the DRVM_ENABLE is only required when the PnP node is non zero */
553 if (lpDrv->bIs32 && part->u.fnMessage32) {
554 ret = part->u.fnMessage32(0, DRVM_INIT, 0L, 0L, 0L);
555 TRACE("DRVM_INIT => %s\n", WINMM_ErrorToString(ret));
557 ret = part->u.fnMessage32(0, DRVM_ENABLE, 0L, 0L, 0L);
558 TRACE("DRVM_ENABLE => %08lx\n", ret);
560 count = part->u.fnMessage32(0, wMsg, 0L, 0L, 0L);
561 } else if (!lpDrv->bIs32 && part->u.fnMessage16 && pFnCallMMDrvFunc16) {
562 ret = pFnCallMMDrvFunc16((DWORD)part->u.fnMessage16,
563 0, DRVM_INIT, 0L, 0L, 0L);
564 TRACE("DRVM_INIT => %s\n", WINMM_ErrorToString(ret));
566 ret = pFnCallMMDrvFunc16((DWORD)part->u.fnMessage16,
567 0, DRVM_ENABLE, 0L, 0L, 0L);
568 TRACE("DRVM_ENABLE => %08lx\n", ret);
570 count = pFnCallMMDrvFunc16((DWORD)part->u.fnMessage16,
571 0, wMsg, 0L, 0L, 0L);
576 TRACE("Got %u dev for (%s:%s)\n", count, lpDrv->drvname, llTypes[type].typestr);
581 /* got some drivers */
582 if (lpDrv->bIsMapper) {
583 /* it seems native mappers return 0 devices :-( */
584 if (llTypes[type].nMapper != -1)
585 ERR("Two mappers for type %s (%d, %s)\n",
586 llTypes[type].typestr, llTypes[type].nMapper, lpDrv->drvname);
588 ERR("Strange: mapper with %d > 1 devices\n", count);
589 llTypes[type].nMapper = MMDrvsHi;
593 part->nIDMin = llTypes[type].wMaxId;
594 llTypes[type].wMaxId += count;
595 part->nIDMax = llTypes[type].wMaxId;
597 TRACE("Setting min=%d max=%d (ttop=%d) for (%s:%s)\n",
598 part->nIDMin, part->nIDMax, llTypes[type].wMaxId,
599 lpDrv->drvname, llTypes[type].typestr);
600 /* realloc translation table */
601 if (llTypes[type].lpMlds)
602 llTypes[type].lpMlds = (LPWINE_MLD)
603 HeapReAlloc(GetProcessHeap(), 0, llTypes[type].lpMlds - 1,
604 sizeof(WINE_MLD) * (llTypes[type].wMaxId + 1)) + 1;
606 llTypes[type].lpMlds = (LPWINE_MLD)
607 HeapAlloc(GetProcessHeap(), 0,
608 sizeof(WINE_MLD) * (llTypes[type].wMaxId + 1)) + 1;
610 /* re-build the translation table */
611 if (llTypes[type].nMapper != -1) {
612 TRACE("%s:Trans[%d] -> %s\n", llTypes[type].typestr, -1, MMDrvs[llTypes[type].nMapper].drvname);
613 llTypes[type].lpMlds[-1].uDeviceID = (UINT16)-1;
614 llTypes[type].lpMlds[-1].type = type;
615 llTypes[type].lpMlds[-1].mmdIndex = llTypes[type].nMapper;
616 llTypes[type].lpMlds[-1].dwDriverInstance = 0;
618 for (i = k = 0; i <= MMDrvsHi; i++) {
619 while (MMDrvs[i].parts[type].nIDMin <= k && k < MMDrvs[i].parts[type].nIDMax) {
620 TRACE("%s:Trans[%d] -> %s\n", llTypes[type].typestr, k, MMDrvs[i].drvname);
621 llTypes[type].lpMlds[k].uDeviceID = k;
622 llTypes[type].lpMlds[k].type = type;
623 llTypes[type].lpMlds[k].mmdIndex = i;
624 llTypes[type].lpMlds[k].dwDriverInstance = 0;
631 /**************************************************************************
632 * MMDRV_Install [internal]
634 static BOOL MMDRV_Install(LPCSTR drvRegName, LPCSTR drvFileName, BOOL bIsMapper)
637 LPWINE_MM_DRIVER lpDrv = &MMDrvs[MMDrvsHi];
640 TRACE("('%s', '%s', mapper=%c);\n", drvRegName, drvFileName, bIsMapper ? 'Y' : 'N');
642 for (i = 0; i < MMDrvsHi; i++) {
643 if (!strcmp(drvRegName, MMDrvs[i].drvname)) return FALSE;
646 /* Be sure that size of MMDrvs matches the max number of loadable
648 * If not just increase size of MMDrvs
650 assert(MMDrvsHi <= sizeof(MMDrvs)/sizeof(MMDrvs[0]));
652 memset(lpDrv, 0, sizeof(*lpDrv));
654 if (!(lpDrv->hDriver = OpenDriverA(drvFileName, 0, 0))) {
655 WARN("Couldn't open driver '%s'\n", drvFileName);
659 d = DRIVER_FindFromHDrvr(lpDrv->hDriver);
660 lpDrv->bIs32 = (d->dwFlags & WINE_GDF_16BIT) ? FALSE : TRUE;
662 /* Then look for xxxMessage functions */
663 #define AA(_h,_w,_x,_y,_z) \
664 func = (WINEMM_msgFunc##_y) _z ((_h), #_x); \
666 { lpDrv->parts[_w].u.fnMessage##_y = func; count++; \
667 TRACE("Got %d bit func '%s'\n", _y, #_x); }
670 WINEMM_msgFunc32 func;
673 if (d->d.d32.hModule) {
674 #define A(_x,_y) AA(d->d.d32.hModule,_x,_y,32,GetProcAddress)
675 A(MMDRV_AUX, auxMessage);
676 A(MMDRV_MIXER, mxdMessage);
677 A(MMDRV_MIDIIN, midMessage);
678 A(MMDRV_MIDIOUT, modMessage);
679 A(MMDRV_WAVEIN, widMessage);
680 A(MMDRV_WAVEOUT, wodMessage);
683 if (TRACE_ON(winmm)) {
684 if (MMDRV_GetDescription32(drvFileName, buffer, sizeof(buffer)))
685 TRACE("%s => %s\n", drvFileName, buffer);
687 TRACE("%s => No description\n", drvFileName);
689 } else if (WINMM_CheckForMMSystem() && pFnLoadMMDrvFunc16) {
690 count += pFnLoadMMDrvFunc16(drvFileName, d, lpDrv);
695 CloseDriver(lpDrv->hDriver, 0, 0);
696 WARN("No message functions found\n");
700 /* FIXME: being a mapper or not should be known by another way */
701 /* it's known for NE drvs (the description is of the form '*mapper: *'
702 * I don't have any clue for PE drvs
704 lpDrv->bIsMapper = bIsMapper;
705 lpDrv->drvname = strcpy(HeapAlloc(GetProcessHeap(), 0, strlen(drvRegName) + 1), drvRegName);
707 /* Finish init and get the count of the devices */
709 if (MMDRV_InitPerType(lpDrv, MMDRV_AUX, AUXDM_GETNUMDEVS)) i = 1;
710 if (MMDRV_InitPerType(lpDrv, MMDRV_MIXER, MXDM_GETNUMDEVS)) i = 1;
711 if (MMDRV_InitPerType(lpDrv, MMDRV_MIDIIN, MIDM_GETNUMDEVS)) i = 1;
712 if (MMDRV_InitPerType(lpDrv, MMDRV_MIDIOUT, MODM_GETNUMDEVS)) i = 1;
713 if (MMDRV_InitPerType(lpDrv, MMDRV_WAVEIN, WIDM_GETNUMDEVS)) i = 1;
714 if (MMDRV_InitPerType(lpDrv, MMDRV_WAVEOUT, WODM_GETNUMDEVS)) i = 1;
715 /* if all those func calls return FALSE, then the driver must be unloaded */
717 CloseDriver(lpDrv->hDriver, 0, 0);
718 HeapFree(GetProcessHeap(), 0, lpDrv->drvname);
719 WARN("Driver initialization failed\n");
728 /**************************************************************************
731 BOOL MMDRV_Init(void)
734 char driver_buffer[256];
735 char mapper_buffer[256];
736 char midi_buffer[256];
742 strcpy(driver_buffer, WINE_DEFAULT_WINMM_DRIVER);
743 strcpy(mapper_buffer, WINE_DEFAULT_WINMM_MAPPER);
744 strcpy(midi_buffer, WINE_DEFAULT_WINMM_MIDI);
746 /* @@ Wine registry key: HKCU\Software\Wine\Drivers */
747 if (!RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Drivers", &hKey))
749 size = sizeof(driver_buffer);
750 if (RegQueryValueExA(hKey, "Audio", 0, &type, (LPVOID)driver_buffer, &size))
751 strcpy(driver_buffer, WINE_DEFAULT_WINMM_DRIVER);
757 char filename[sizeof(driver_buffer)+10];
758 char *next = strchr(p, ',');
759 if (next) *next++ = 0;
760 sprintf( filename, "wine%s.drv", p );
761 ret |= MMDRV_Install( filename, filename, FALSE );
765 ret |= MMDRV_Install("wavemapper", WINE_DEFAULT_WINMM_MAPPER, TRUE);
766 ret |= MMDRV_Install("midimapper", WINE_DEFAULT_WINMM_MIDI, TRUE);
770 /******************************************************************
775 static BOOL MMDRV_ExitPerType(LPWINE_MM_DRIVER lpDrv, UINT type)
777 WINE_MM_DRIVER_PART* part = &lpDrv->parts[type];
779 TRACE("(%p, %04x)\n", lpDrv, type);
781 if (lpDrv->bIs32 && part->u.fnMessage32) {
783 ret = part->u.fnMessage32(0, DRVM_DISABLE, 0L, 0L, 0L);
784 TRACE("DRVM_DISABLE => %08lx\n", ret);
786 ret = part->u.fnMessage32(0, DRVM_EXIT, 0L, 0L, 0L);
787 TRACE("DRVM_EXIT => %s\n", WINMM_ErrorToString(ret));
788 } else if (!lpDrv->bIs32 && part->u.fnMessage16 && pFnCallMMDrvFunc16) {
790 ret = pFnCallMMDrvFunc16((DWORD)part->u.fnMessage16,
791 0, DRVM_DISABLE, 0L, 0L, 0L);
792 TRACE("DRVM_DISABLE => %08lx\n", ret);
794 ret = pFnCallMMDrvFunc16((DWORD)part->u.fnMessage16,
795 0, DRVM_EXIT, 0L, 0L, 0L);
796 TRACE("DRVM_EXIT => %s\n", WINMM_ErrorToString(ret));
804 /******************************************************************
809 void MMDRV_Exit(void)
814 for (i = 0; i < sizeof(MM_MLDrvs) / sizeof(MM_MLDrvs[0]); i++)
816 if (MM_MLDrvs[i] != NULL)
818 FIXME("Closing while ll-driver open\n");
820 /* FIXME: should generate a message depending on type */
821 MMDRV_Free((HANDLE)(i | 0x8000), MM_MLDrvs[i]);
826 /* unload driver, in reverse order of loading */
827 for (i = sizeof(MMDrvs) / sizeof(MMDrvs[0]) - 1; i >= 0; i--)
829 MMDRV_ExitPerType(&MMDrvs[i], MMDRV_AUX);
830 MMDRV_ExitPerType(&MMDrvs[i], MMDRV_MIXER);
831 MMDRV_ExitPerType(&MMDrvs[i], MMDRV_MIDIIN);
832 MMDRV_ExitPerType(&MMDrvs[i], MMDRV_MIDIOUT);
833 MMDRV_ExitPerType(&MMDrvs[i], MMDRV_WAVEIN);
834 MMDRV_ExitPerType(&MMDrvs[i], MMDRV_WAVEOUT);
835 CloseDriver(MMDrvs[i].hDriver, 0, 0);
837 HeapFree(GetProcessHeap(), 0, llTypes[MMDRV_AUX].lpMlds - 1);
838 HeapFree(GetProcessHeap(), 0, llTypes[MMDRV_MIXER].lpMlds - 1);
839 HeapFree(GetProcessHeap(), 0, llTypes[MMDRV_MIDIIN].lpMlds - 1);
840 HeapFree(GetProcessHeap(), 0, llTypes[MMDRV_MIDIOUT].lpMlds - 1);
841 HeapFree(GetProcessHeap(), 0, llTypes[MMDRV_WAVEIN].lpMlds - 1);
842 HeapFree(GetProcessHeap(), 0, llTypes[MMDRV_WAVEOUT].lpMlds - 1);