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
32 #include "wine/debug.h"
33 #include "wine/exception.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(winmm
);
38 LRESULT (*pFnCallMMDrvFunc16
)(DWORD
,WORD
,WORD
,LONG
,LONG
,LONG
) /* = NULL */;
39 unsigned (*pFnLoadMMDrvFunc16
)(LPCSTR
,LPWINE_DRIVER
, LPWINE_MM_DRIVER
) /* = NULL */;
41 /* each known type of driver has an instance of this structure */
42 typedef struct tagWINE_LLTYPE
{
43 /* those attributes depend on the specification of the type */
44 LPCSTR typestr
; /* name (for debugging) */
45 BOOL bSupportMapper
; /* if type is allowed to support mapper */
46 MMDRV_MAPFUNC Map16To32A
; /* those are function pointers to handle */
47 MMDRV_UNMAPFUNC UnMap16To32A
; /* the parameter conversion (16 vs 32 bit) */
48 MMDRV_MAPFUNC Map32ATo16
; /* when hi-func (in mmsystem or winmm) and */
49 MMDRV_UNMAPFUNC UnMap32ATo16
; /* low-func (in .drv) do not match */
50 LPDRVCALLBACK Callback
; /* handles callback for a specified type */
51 /* those attributes reflect the loaded/current situation for the type */
52 UINT wMaxId
; /* number of loaded devices (sum across all loaded drivers) */
53 LPWINE_MLD lpMlds
; /* "static" mlds to access the part though device IDs */
54 int nMapper
; /* index to mapper */
57 static int MMDrvsHi
/* = 0 */;
58 static WINE_MM_DRIVER MMDrvs
[8];
59 static LPWINE_MLD MM_MLDrvs
[40];
60 #define MAX_MM_MLDRVS (sizeof(MM_MLDrvs) / sizeof(MM_MLDrvs[0]))
62 #define A(_x,_y) {#_y, _x, NULL, NULL, NULL, NULL, NULL, 0, NULL, -1}
63 /* Note: the indices of this array must match the definitions
64 * of the MMDRV_???? manifest constants
66 static WINE_LLTYPE llTypes
[MMDRV_MAX
] = {
76 /******************************************************************
81 void MMDRV_InstallMap(unsigned int drv
,
82 MMDRV_MAPFUNC mp1632
, MMDRV_UNMAPFUNC um1632
,
83 MMDRV_MAPFUNC mp3216
, MMDRV_UNMAPFUNC um3216
,
86 assert(drv
< MMDRV_MAX
);
87 llTypes
[drv
].Map16To32A
= mp1632
;
88 llTypes
[drv
].UnMap16To32A
= um1632
;
89 llTypes
[drv
].Map32ATo16
= mp3216
;
90 llTypes
[drv
].UnMap32ATo16
= um3216
;
91 llTypes
[drv
].Callback
= cb
;
94 /******************************************************************
98 BOOL
MMDRV_Is32(unsigned int idx
)
100 TRACE("(%d)\n", idx
);
101 return MMDrvs
[idx
].bIs32
;
104 /**************************************************************************
105 * MMDRV_GetDescription32 [internal]
107 static BOOL
MMDRV_GetDescription32(const char* fname
, char* buf
, int buflen
)
116 FARPROC pGetFileVersionInfoSizeA
;
117 FARPROC pGetFileVersionInfoA
;
118 FARPROC pVerQueryValueA
;
120 TRACE("(%p, %p, %d)\n", fname
, buf
, buflen
);
122 #define E(_x) do {TRACE _x;goto theEnd;} while(0)
124 if (OpenFile(fname
, &ofs
, OF_EXIST
)==HFILE_ERROR
) E(("Can't find file %s\n", fname
));
126 if (!(hmodule
= LoadLibraryA( "version.dll" ))) goto theEnd
;
127 if (!(pGetFileVersionInfoSizeA
= GetProcAddress( hmodule
, "GetFileVersionInfoSizeA" )))
129 if (!(pGetFileVersionInfoA
= GetProcAddress( hmodule
, "GetFileVersionInfoA" )))
131 if (!(pVerQueryValueA
= GetProcAddress( hmodule
, "VerQueryValueA" )))
134 if (!(dw
= pGetFileVersionInfoSizeA(ofs
.szPathName
, &h
))) E(("Can't get FVIS\n"));
135 if (!(ptr
= HeapAlloc(GetProcessHeap(), 0, dw
))) E(("OOM\n"));
136 if (!pGetFileVersionInfoA(ofs
.szPathName
, h
, dw
, ptr
)) E(("Can't get FVI\n"));
138 #define A(_x) if (pVerQueryValueA(ptr, "\\StringFileInfo\\040904B0\\" #_x, &val, &u)) \
139 TRACE(#_x " => %s\n", (LPSTR)val); else TRACE(#_x " @\n")
155 if (!pVerQueryValueA(ptr
, "\\StringFileInfo\\040904B0\\ProductName", &val
, &u
)) E(("Can't get product name\n"));
156 lstrcpynA(buf
, val
, buflen
);
161 HeapFree(GetProcessHeap(), 0, ptr
);
162 if (hmodule
) FreeLibrary( hmodule
);
166 /**************************************************************************
167 * MMDRV_GetNum [internal]
169 UINT
MMDRV_GetNum(UINT type
)
171 TRACE("(%04x)\n", type
);
172 assert(type
< MMDRV_MAX
);
173 return llTypes
[type
].wMaxId
;
176 /**************************************************************************
177 * MMDRV_Message [internal]
179 DWORD
MMDRV_Message(LPWINE_MLD mld
, UINT wMsg
, DWORD_PTR dwParam1
,
180 DWORD_PTR dwParam2
, BOOL bFrom32
)
182 LPWINE_MM_DRIVER lpDrv
;
184 WINE_MM_DRIVER_PART
* part
;
185 WINE_LLTYPE
* llType
= &llTypes
[mld
->type
];
189 TRACE("(%s %u %u 0x%08lx 0x%08lx 0x%08lx %c)\n",
190 llTypes
[mld
->type
].typestr
, mld
->uDeviceID
, wMsg
,
191 mld
->dwDriverInstance
, dwParam1
, dwParam2
, bFrom32
?'Y':'N');
193 if (mld
->uDeviceID
== (UINT16
)-1) {
194 if (!llType
->bSupportMapper
) {
195 WARN("uDev=-1 requested on non-mappable ll type %s\n",
196 llTypes
[mld
->type
].typestr
);
197 return MMSYSERR_BADDEVICEID
;
201 if (mld
->uDeviceID
>= llType
->wMaxId
) {
202 WARN("uDev(%u) requested >= max (%d)\n", mld
->uDeviceID
, llType
->wMaxId
);
203 return MMSYSERR_BADDEVICEID
;
205 devID
= mld
->uDeviceID
;
208 lpDrv
= &MMDrvs
[mld
->mmdIndex
];
209 part
= &lpDrv
->parts
[mld
->type
];
212 /* some sanity checks */
213 if (!(part
->nIDMin
<= devID
))
214 ERR("!(part->nIDMin(%d) <= devID(%d))\n", part
->nIDMin
, devID
);
215 if (!(devID
< part
->nIDMax
))
216 ERR("!(devID(%d) < part->nIDMax(%d))\n", devID
, part
->nIDMax
);
220 assert(part
->u
.fnMessage32
);
223 TRACE("Calling message(dev=%u msg=%u usr=0x%08lx p1=0x%08lx p2=0x%08lx)\n",
224 mld
->uDeviceID
, wMsg
, mld
->dwDriverInstance
, dwParam1
, dwParam2
);
225 ret
= part
->u
.fnMessage32(mld
->uDeviceID
, wMsg
, mld
->dwDriverInstance
, dwParam1
, dwParam2
);
226 TRACE("=> %s\n", WINMM_ErrorToString(ret
));
228 map
= llType
->Map16To32A(wMsg
, &mld
->dwDriverInstance
, &dwParam1
, &dwParam2
);
230 case WINMM_MAP_NOMEM
:
231 ret
= MMSYSERR_NOMEM
;
233 case WINMM_MAP_MSGERROR
:
234 FIXME("NIY: no conversion yet 16->32 (%u)\n", wMsg
);
235 ret
= MMSYSERR_ERROR
;
238 case WINMM_MAP_OKMEM
:
239 TRACE("Calling message(dev=%u msg=%u usr=0x%08lx p1=0x%08lx p2=0x%08lx)\n",
240 mld
->uDeviceID
, wMsg
, mld
->dwDriverInstance
, dwParam1
, dwParam2
);
241 ret
= part
->u
.fnMessage32(mld
->uDeviceID
, wMsg
, mld
->dwDriverInstance
,
243 TRACE("=> %s\n", WINMM_ErrorToString(ret
));
244 if (map
== WINMM_MAP_OKMEM
)
245 llType
->UnMap16To32A(wMsg
, &mld
->dwDriverInstance
, &dwParam1
, &dwParam2
, ret
);
249 ret
= MMSYSERR_NOTSUPPORTED
;
254 assert(part
->u
.fnMessage16
&& pFnCallMMDrvFunc16
);
257 map
= llType
->Map32ATo16(wMsg
, &mld
->dwDriverInstance
, &dwParam1
, &dwParam2
);
259 case WINMM_MAP_NOMEM
:
260 ret
= MMSYSERR_NOMEM
;
262 case WINMM_MAP_MSGERROR
:
263 FIXME("NIY: no conversion yet 32->16 (%u)\n", wMsg
);
264 ret
= MMSYSERR_ERROR
;
267 case WINMM_MAP_OKMEM
:
268 TRACE("Calling message(dev=%u msg=%u usr=0x%08lx p1=0x%08lx p2=0x%08lx)\n",
269 mld
->uDeviceID
, wMsg
, mld
->dwDriverInstance
, dwParam1
, dwParam2
);
270 ret
= pFnCallMMDrvFunc16((DWORD
)part
->u
.fnMessage16
,
271 mld
->uDeviceID
, wMsg
, mld
->dwDriverInstance
,
273 TRACE("=> %s\n", WINMM_ErrorToString(ret
));
274 if (map
== WINMM_MAP_OKMEM
)
275 llType
->UnMap32ATo16(wMsg
, &mld
->dwDriverInstance
, &dwParam1
, &dwParam2
, ret
);
279 ret
= MMSYSERR_NOTSUPPORTED
;
283 TRACE("Calling message(dev=%u msg=%u usr=0x%08lx p1=0x%08lx p2=0x%08lx)\n",
284 mld
->uDeviceID
, wMsg
, mld
->dwDriverInstance
, dwParam1
, dwParam2
);
285 ret
= pFnCallMMDrvFunc16((DWORD
)part
->u
.fnMessage16
,
286 mld
->uDeviceID
, wMsg
, mld
->dwDriverInstance
,
288 TRACE("=> %s\n", WINMM_ErrorToString(ret
));
294 /**************************************************************************
295 * MMDRV_Alloc [internal]
297 LPWINE_MLD
MMDRV_Alloc(UINT size
, UINT type
, LPHANDLE hndl
, DWORD
* dwFlags
,
298 DWORD
* dwCallback
, DWORD
* dwInstance
, BOOL bFrom32
)
302 TRACE("(%d, %04x, %p, %p, %p, %p, %c)\n",
303 size
, type
, hndl
, dwFlags
, dwCallback
, dwInstance
, bFrom32
?'Y':'N');
305 mld
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
306 if (!mld
) return NULL
;
308 /* find an empty slot in MM_MLDrvs table */
309 for (i
= 0; i
< MAX_MM_MLDRVS
; i
++) if (!MM_MLDrvs
[i
]) break;
311 if (i
== MAX_MM_MLDRVS
) {
312 /* the MM_MLDrvs table could be made growable in the future if needed */
313 ERR("Too many open drivers\n");
314 HeapFree(GetProcessHeap(), 0, mld
);
318 *hndl
= (HANDLE
)(i
| 0x8000);
321 if ((UINT
)*hndl
< MMDRV_GetNum(type
) || HIWORD(*hndl
) != 0) {
322 /* FIXME: those conditions must be fulfilled so that:
323 * - we can distinguish between device IDs and handles
324 * - we can use handles as 16 or 32 bit entities
326 ERR("Shouldn't happen. Bad allocation scheme\n");
329 mld
->bFrom32
= bFrom32
;
330 mld
->dwFlags
= HIWORD(*dwFlags
);
331 mld
->dwCallback
= *dwCallback
;
332 mld
->dwClientInstance
= *dwInstance
;
334 if (llTypes
[type
].Callback
)
336 *dwFlags
= LOWORD(*dwFlags
) | CALLBACK_FUNCTION
;
337 *dwCallback
= (DWORD
)llTypes
[type
].Callback
;
338 *dwInstance
= (DWORD
)mld
; /* FIXME: wouldn't some 16 bit drivers only use the loword ? */
344 /**************************************************************************
345 * MMDRV_Free [internal]
347 void MMDRV_Free(HANDLE hndl
, LPWINE_MLD mld
)
349 TRACE("(%p, %p)\n", hndl
, mld
);
351 if ((UINT
)hndl
& 0x8000) {
352 unsigned idx
= (UINT
)hndl
& ~0x8000;
353 if (idx
< sizeof(MM_MLDrvs
) / sizeof(MM_MLDrvs
[0])) {
354 MM_MLDrvs
[idx
] = NULL
;
355 HeapFree(GetProcessHeap(), 0, mld
);
359 ERR("Bad Handle %p at %p (not freed)\n", hndl
, mld
);
362 /**************************************************************************
363 * MMDRV_Open [internal]
365 DWORD
MMDRV_Open(LPWINE_MLD mld
, UINT wMsg
, DWORD dwParam1
, DWORD dwFlags
)
367 DWORD dwRet
= MMSYSERR_BADDEVICEID
;
369 WINE_LLTYPE
* llType
= &llTypes
[mld
->type
];
370 TRACE("(%p, %04x, 0x%08lx, 0x%08lx)\n", mld
, wMsg
, dwParam1
, dwFlags
);
372 mld
->dwDriverInstance
= (DWORD
)&dwInstance
;
374 if (mld
->uDeviceID
== (UINT
)-1 || mld
->uDeviceID
== (UINT16
)-1) {
375 TRACE("MAPPER mode requested !\n");
376 /* check if mapper is supported by type */
377 if (llType
->bSupportMapper
) {
378 if (llType
->nMapper
== -1) {
379 /* no driver for mapper has been loaded, try a dumb implementation */
380 TRACE("No mapper loaded, doing it by hand\n");
381 for (mld
->uDeviceID
= 0; mld
->uDeviceID
< llType
->wMaxId
; mld
->uDeviceID
++) {
382 if ((dwRet
= MMDRV_Open(mld
, wMsg
, dwParam1
, dwFlags
)) == MMSYSERR_NOERROR
) {
383 /* to share this function epilog */
384 dwInstance
= mld
->dwDriverInstance
;
389 mld
->uDeviceID
= (UINT16
)-1;
390 mld
->mmdIndex
= llType
->lpMlds
[-1].mmdIndex
;
391 TRACE("Setting mmdIndex to %u\n", mld
->mmdIndex
);
392 dwRet
= MMDRV_Message(mld
, wMsg
, dwParam1
, dwFlags
, TRUE
);
396 if (mld
->uDeviceID
< llType
->wMaxId
) {
397 mld
->mmdIndex
= llType
->lpMlds
[mld
->uDeviceID
].mmdIndex
;
398 TRACE("Setting mmdIndex to %u\n", mld
->mmdIndex
);
399 dwRet
= MMDRV_Message(mld
, wMsg
, dwParam1
, dwFlags
, TRUE
);
402 if (dwRet
== MMSYSERR_NOERROR
)
403 mld
->dwDriverInstance
= dwInstance
;
407 /**************************************************************************
408 * MMDRV_Close [internal]
410 DWORD
MMDRV_Close(LPWINE_MLD mld
, UINT wMsg
)
412 TRACE("(%p, %04x)\n", mld
, wMsg
);
413 return MMDRV_Message(mld
, wMsg
, 0L, 0L, TRUE
);
416 /**************************************************************************
417 * MMDRV_GetByID [internal]
419 static LPWINE_MLD
MMDRV_GetByID(UINT uDevID
, UINT type
)
421 TRACE("(%04x, %04x)\n", uDevID
, type
);
422 if (uDevID
< llTypes
[type
].wMaxId
)
423 return &llTypes
[type
].lpMlds
[uDevID
];
424 if ((uDevID
== (UINT16
)-1 || uDevID
== (UINT
)-1) && llTypes
[type
].nMapper
!= -1)
425 return &llTypes
[type
].lpMlds
[-1];
429 /**************************************************************************
430 * MMDRV_Get [internal]
432 LPWINE_MLD
MMDRV_Get(HANDLE _hndl
, UINT type
, BOOL bCanBeID
)
434 LPWINE_MLD mld
= NULL
;
435 UINT hndl
= (UINT
)_hndl
;
436 TRACE("(%p, %04x, %c)\n", _hndl
, type
, bCanBeID
? 'Y' : 'N');
438 assert(type
< MMDRV_MAX
);
440 if (hndl
>= llTypes
[type
].wMaxId
&&
441 hndl
!= (UINT16
)-1 && hndl
!= (UINT
)-1) {
443 UINT idx
= hndl
& ~0x8000;
444 if (idx
< sizeof(MM_MLDrvs
) / sizeof(MM_MLDrvs
[0])) {
447 mld
= MM_MLDrvs
[idx
];
448 if (mld
&& mld
->type
!= type
) mld
= NULL
;
458 if (mld
== NULL
&& bCanBeID
) {
459 mld
= MMDRV_GetByID(hndl
, type
);
464 /**************************************************************************
465 * MMDRV_GetRelated [internal]
467 LPWINE_MLD
MMDRV_GetRelated(HANDLE hndl
, UINT srcType
,
468 BOOL bSrcCanBeID
, UINT dstType
)
471 TRACE("(%p, %04x, %c, %04x)\n",
472 hndl
, srcType
, bSrcCanBeID
? 'Y' : 'N', dstType
);
474 if ((mld
= MMDRV_Get(hndl
, srcType
, bSrcCanBeID
)) != NULL
) {
475 WINE_MM_DRIVER_PART
* part
= &MMDrvs
[mld
->mmdIndex
].parts
[dstType
];
476 if (part
->nIDMin
< part
->nIDMax
)
477 return MMDRV_GetByID(part
->nIDMin
, dstType
);
482 /**************************************************************************
483 * MMDRV_PhysicalFeatures [internal]
485 UINT
MMDRV_PhysicalFeatures(LPWINE_MLD mld
, UINT uMsg
, DWORD dwParam1
,
488 WINE_MM_DRIVER
* lpDrv
= &MMDrvs
[mld
->mmdIndex
];
490 TRACE("(%p, %04x, %08lx, %08lx)\n", mld
, uMsg
, dwParam1
, dwParam2
);
492 /* all those function calls are undocumented */
494 case DRV_QUERYDRVENTRY
:
495 lstrcpynA((LPSTR
)dwParam1
, lpDrv
->drvname
, LOWORD(dwParam2
));
497 case DRV_QUERYDEVNODE
:
498 *(LPDWORD
)dwParam1
= 0L; /* should be DevNode */
501 WARN("NIY QueryName\n");
503 case DRV_QUERYDRIVERIDS
:
504 WARN("NIY call VxD\n");
505 /* should call VxD MMDEVLDR with (DevNode, dwParam1 and dwParam2) as pmts
506 * dwParam1 is buffer and dwParam2 is sizeof(buffer)
507 * I don't know where the result is stored though
510 case DRV_QUERYMAPPABLE
:
511 return (lpDrv
->bIsMapper
) ? 2 : 0;
513 case DRVM_MAPPER_PREFERRED_GET
:
514 /* FIXME: get from registry someday */
515 *((LPDWORD
)dwParam1
) = -1; /* No preferred device */
516 *((LPDWORD
)dwParam2
) = 0;
519 case DRV_QUERYDEVICEINTERFACE
:
520 case DRV_QUERYDEVICEINTERFACESIZE
:
521 return MMDRV_Message(mld
, uMsg
, dwParam1
, dwParam2
, TRUE
);
523 case DRV_QUERYDSOUNDIFACE
: /* Wine-specific: Retrieve DirectSound interface */
524 case DRV_QUERYDSOUNDDESC
: /* Wine-specific: Retrieve DirectSound driver description*/
525 return MMDRV_Message(mld
, uMsg
, dwParam1
, dwParam2
, TRUE
);
528 WARN("Unknown call %04x\n", uMsg
);
529 return MMSYSERR_INVALPARAM
;
534 /**************************************************************************
535 * MMDRV_InitPerType [internal]
537 static BOOL
MMDRV_InitPerType(LPWINE_MM_DRIVER lpDrv
, UINT type
, UINT wMsg
)
539 WINE_MM_DRIVER_PART
* part
= &lpDrv
->parts
[type
];
543 TRACE("(%p, %04x, %04x)\n", lpDrv
, type
, wMsg
);
545 part
->nIDMin
= part
->nIDMax
= 0;
547 /* for DRVM_INIT and DRVM_ENABLE, dwParam2 should be PnP node */
548 /* the DRVM_ENABLE is only required when the PnP node is non zero */
550 if (lpDrv
->bIs32
&& part
->u
.fnMessage32
) {
551 ret
= part
->u
.fnMessage32(0, DRVM_INIT
, 0L, 0L, 0L);
552 TRACE("DRVM_INIT => %s\n", WINMM_ErrorToString(ret
));
554 ret
= part
->u
.fnMessage32(0, DRVM_ENABLE
, 0L, 0L, 0L);
555 TRACE("DRVM_ENABLE => %08lx\n", ret
);
557 count
= part
->u
.fnMessage32(0, wMsg
, 0L, 0L, 0L);
558 } else if (!lpDrv
->bIs32
&& part
->u
.fnMessage16
&& pFnCallMMDrvFunc16
) {
559 ret
= pFnCallMMDrvFunc16((DWORD
)part
->u
.fnMessage16
,
560 0, DRVM_INIT
, 0L, 0L, 0L);
561 TRACE("DRVM_INIT => %s\n", WINMM_ErrorToString(ret
));
563 ret
= pFnCallMMDrvFunc16((DWORD
)part
->u
.fnMessage16
,
564 0, DRVM_ENABLE
, 0L, 0L, 0L);
565 TRACE("DRVM_ENABLE => %08lx\n", ret
);
567 count
= pFnCallMMDrvFunc16((DWORD
)part
->u
.fnMessage16
,
568 0, wMsg
, 0L, 0L, 0L);
573 TRACE("Got %u dev for (%s:%s)\n", count
, lpDrv
->drvname
, llTypes
[type
].typestr
);
578 /* got some drivers */
579 if (lpDrv
->bIsMapper
) {
580 /* it seems native mappers return 0 devices :-( */
581 if (llTypes
[type
].nMapper
!= -1)
582 ERR("Two mappers for type %s (%d, %s)\n",
583 llTypes
[type
].typestr
, llTypes
[type
].nMapper
, lpDrv
->drvname
);
585 ERR("Strange: mapper with %d > 1 devices\n", count
);
586 llTypes
[type
].nMapper
= MMDrvsHi
;
590 part
->nIDMin
= llTypes
[type
].wMaxId
;
591 llTypes
[type
].wMaxId
+= count
;
592 part
->nIDMax
= llTypes
[type
].wMaxId
;
594 TRACE("Setting min=%d max=%d (ttop=%d) for (%s:%s)\n",
595 part
->nIDMin
, part
->nIDMax
, llTypes
[type
].wMaxId
,
596 lpDrv
->drvname
, llTypes
[type
].typestr
);
597 /* realloc translation table */
598 if (llTypes
[type
].lpMlds
)
599 llTypes
[type
].lpMlds
= (LPWINE_MLD
)
600 HeapReAlloc(GetProcessHeap(), 0, llTypes
[type
].lpMlds
- 1,
601 sizeof(WINE_MLD
) * (llTypes
[type
].wMaxId
+ 1)) + 1;
603 llTypes
[type
].lpMlds
= (LPWINE_MLD
)
604 HeapAlloc(GetProcessHeap(), 0,
605 sizeof(WINE_MLD
) * (llTypes
[type
].wMaxId
+ 1)) + 1;
607 /* re-build the translation table */
608 if (llTypes
[type
].nMapper
!= -1) {
609 TRACE("%s:Trans[%d] -> %s\n", llTypes
[type
].typestr
, -1, MMDrvs
[llTypes
[type
].nMapper
].drvname
);
610 llTypes
[type
].lpMlds
[-1].uDeviceID
= (UINT16
)-1;
611 llTypes
[type
].lpMlds
[-1].type
= type
;
612 llTypes
[type
].lpMlds
[-1].mmdIndex
= llTypes
[type
].nMapper
;
613 llTypes
[type
].lpMlds
[-1].dwDriverInstance
= 0;
615 for (i
= k
= 0; i
<= MMDrvsHi
; i
++) {
616 while (MMDrvs
[i
].parts
[type
].nIDMin
<= k
&& k
< MMDrvs
[i
].parts
[type
].nIDMax
) {
617 TRACE("%s:Trans[%d] -> %s\n", llTypes
[type
].typestr
, k
, MMDrvs
[i
].drvname
);
618 llTypes
[type
].lpMlds
[k
].uDeviceID
= k
;
619 llTypes
[type
].lpMlds
[k
].type
= type
;
620 llTypes
[type
].lpMlds
[k
].mmdIndex
= i
;
621 llTypes
[type
].lpMlds
[k
].dwDriverInstance
= 0;
628 /**************************************************************************
629 * MMDRV_Install [internal]
631 static BOOL
MMDRV_Install(LPCSTR drvRegName
, LPCSTR drvFileName
, BOOL bIsMapper
)
634 LPWINE_MM_DRIVER lpDrv
= &MMDrvs
[MMDrvsHi
];
637 TRACE("('%s', '%s', mapper=%c);\n", drvRegName
, drvFileName
, bIsMapper
? 'Y' : 'N');
639 for (i
= 0; i
< MMDrvsHi
; i
++) {
640 if (!strcmp(drvRegName
, MMDrvs
[i
].drvname
)) return FALSE
;
643 /* Be sure that size of MMDrvs matches the max number of loadable
645 * If not just increase size of MMDrvs
647 assert(MMDrvsHi
<= sizeof(MMDrvs
)/sizeof(MMDrvs
[0]));
649 memset(lpDrv
, 0, sizeof(*lpDrv
));
651 if (!(lpDrv
->hDriver
= OpenDriverA(drvFileName
, 0, 0))) {
652 WARN("Couldn't open driver '%s'\n", drvFileName
);
656 d
= DRIVER_FindFromHDrvr(lpDrv
->hDriver
);
657 lpDrv
->bIs32
= (d
->dwFlags
& WINE_GDF_16BIT
) ? FALSE
: TRUE
;
659 /* Then look for xxxMessage functions */
660 #define AA(_h,_w,_x,_y,_z) \
661 func = (WINEMM_msgFunc##_y) _z ((_h), #_x); \
663 { lpDrv->parts[_w].u.fnMessage##_y = func; count++; \
664 TRACE("Got %d bit func '%s'\n", _y, #_x); }
667 WINEMM_msgFunc32 func
;
670 if (d
->d
.d32
.hModule
) {
671 #define A(_x,_y) AA(d->d.d32.hModule,_x,_y,32,GetProcAddress)
672 A(MMDRV_AUX
, auxMessage
);
673 A(MMDRV_MIXER
, mxdMessage
);
674 A(MMDRV_MIDIIN
, midMessage
);
675 A(MMDRV_MIDIOUT
, modMessage
);
676 A(MMDRV_WAVEIN
, widMessage
);
677 A(MMDRV_WAVEOUT
, wodMessage
);
680 if (TRACE_ON(winmm
)) {
681 if (MMDRV_GetDescription32(drvFileName
, buffer
, sizeof(buffer
)))
682 TRACE("%s => %s\n", drvFileName
, buffer
);
684 TRACE("%s => No description\n", drvFileName
);
686 } else if (WINMM_CheckForMMSystem() && pFnLoadMMDrvFunc16
) {
687 count
+= pFnLoadMMDrvFunc16(drvFileName
, d
, lpDrv
);
692 CloseDriver(lpDrv
->hDriver
, 0, 0);
693 WARN("No message functions found\n");
697 /* FIXME: being a mapper or not should be known by another way */
698 /* it's known for NE drvs (the description is of the form '*mapper: *'
699 * I don't have any clue for PE drvs
701 lpDrv
->bIsMapper
= bIsMapper
;
702 lpDrv
->drvname
= strcpy(HeapAlloc(GetProcessHeap(), 0, strlen(drvRegName
) + 1), drvRegName
);
704 /* Finish init and get the count of the devices */
706 if (MMDRV_InitPerType(lpDrv
, MMDRV_AUX
, AUXDM_GETNUMDEVS
)) i
= 1;
707 if (MMDRV_InitPerType(lpDrv
, MMDRV_MIXER
, MXDM_GETNUMDEVS
)) i
= 1;
708 if (MMDRV_InitPerType(lpDrv
, MMDRV_MIDIIN
, MIDM_GETNUMDEVS
)) i
= 1;
709 if (MMDRV_InitPerType(lpDrv
, MMDRV_MIDIOUT
, MODM_GETNUMDEVS
)) i
= 1;
710 if (MMDRV_InitPerType(lpDrv
, MMDRV_WAVEIN
, WIDM_GETNUMDEVS
)) i
= 1;
711 if (MMDRV_InitPerType(lpDrv
, MMDRV_WAVEOUT
, WODM_GETNUMDEVS
)) i
= 1;
712 /* if all those func calls return FALSE, then the driver must be unloaded */
714 CloseDriver(lpDrv
->hDriver
, 0, 0);
715 HeapFree(GetProcessHeap(), 0, lpDrv
->drvname
);
716 WARN("Driver initialization failed\n");
725 /**************************************************************************
728 BOOL
MMDRV_Init(void)
731 char driver_buffer
[256];
732 char mapper_buffer
[256];
733 char midi_buffer
[256];
739 strcpy(driver_buffer
, WINE_DEFAULT_WINMM_DRIVER
);
740 strcpy(mapper_buffer
, WINE_DEFAULT_WINMM_MAPPER
);
741 strcpy(midi_buffer
, WINE_DEFAULT_WINMM_MIDI
);
743 /* @@ Wine registry key: HKCU\Software\Wine\Drivers */
744 if (!RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Drivers", &hKey
))
746 size
= sizeof(driver_buffer
);
747 if (RegQueryValueExA(hKey
, "Audio", 0, &type
, (LPVOID
)driver_buffer
, &size
))
748 strcpy(driver_buffer
, WINE_DEFAULT_WINMM_DRIVER
);
754 char filename
[sizeof(driver_buffer
)+10];
755 char *next
= strchr(p
, ',');
756 if (next
) *next
++ = 0;
757 sprintf( filename
, "wine%s.drv", p
);
758 ret
|= MMDRV_Install( filename
, filename
, FALSE
);
762 ret
|= MMDRV_Install("wavemapper", WINE_DEFAULT_WINMM_MAPPER
, TRUE
);
763 ret
|= MMDRV_Install("midimapper", WINE_DEFAULT_WINMM_MIDI
, TRUE
);
767 /******************************************************************
772 static BOOL
MMDRV_ExitPerType(LPWINE_MM_DRIVER lpDrv
, UINT type
)
774 WINE_MM_DRIVER_PART
* part
= &lpDrv
->parts
[type
];
776 TRACE("(%p, %04x)\n", lpDrv
, type
);
778 if (lpDrv
->bIs32
&& part
->u
.fnMessage32
) {
780 ret
= part
->u
.fnMessage32(0, DRVM_DISABLE
, 0L, 0L, 0L);
781 TRACE("DRVM_DISABLE => %08lx\n", ret
);
783 ret
= part
->u
.fnMessage32(0, DRVM_EXIT
, 0L, 0L, 0L);
784 TRACE("DRVM_EXIT => %s\n", WINMM_ErrorToString(ret
));
785 } else if (!lpDrv
->bIs32
&& part
->u
.fnMessage16
&& pFnCallMMDrvFunc16
) {
787 ret
= pFnCallMMDrvFunc16((DWORD
)part
->u
.fnMessage16
,
788 0, DRVM_DISABLE
, 0L, 0L, 0L);
789 TRACE("DRVM_DISABLE => %08lx\n", ret
);
791 ret
= pFnCallMMDrvFunc16((DWORD
)part
->u
.fnMessage16
,
792 0, DRVM_EXIT
, 0L, 0L, 0L);
793 TRACE("DRVM_EXIT => %s\n", WINMM_ErrorToString(ret
));
801 /******************************************************************
806 void MMDRV_Exit(void)
811 for (i
= 0; i
< sizeof(MM_MLDrvs
) / sizeof(MM_MLDrvs
[0]); i
++)
813 if (MM_MLDrvs
[i
] != NULL
)
815 FIXME("Closing while ll-driver open\n");
817 /* FIXME: should generate a message depending on type */
818 MMDRV_Free((HANDLE
)(i
| 0x8000), MM_MLDrvs
[i
]);
823 /* unload driver, in reverse order of loading */
824 for (i
= sizeof(MMDrvs
) / sizeof(MMDrvs
[0]) - 1; i
>= 0; i
--)
826 MMDRV_ExitPerType(&MMDrvs
[i
], MMDRV_AUX
);
827 MMDRV_ExitPerType(&MMDrvs
[i
], MMDRV_MIXER
);
828 MMDRV_ExitPerType(&MMDrvs
[i
], MMDRV_MIDIIN
);
829 MMDRV_ExitPerType(&MMDrvs
[i
], MMDRV_MIDIOUT
);
830 MMDRV_ExitPerType(&MMDrvs
[i
], MMDRV_WAVEIN
);
831 MMDRV_ExitPerType(&MMDrvs
[i
], MMDRV_WAVEOUT
);
832 CloseDriver(MMDrvs
[i
].hDriver
, 0, 0);