1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
4 * MMSYSTEM 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"
34 #include "wine/debug.h"
35 #include "wine/exception.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(winmm
);
39 LRESULT (*pFnCallMMDrvFunc16
)(DWORD
,WORD
,WORD
,LONG
,LONG
,LONG
) /* = NULL */;
40 unsigned (*pFnLoadMMDrvFunc16
)(LPCSTR
,LPWINE_DRIVER
, LPWINE_MM_DRIVER
) /* = NULL */;
42 /* each known type of driver has an instance of this structure */
43 typedef struct tagWINE_LLTYPE
{
44 /* those attributes depend on the specification of the type */
45 LPCSTR typestr
; /* name (for debugging) */
46 BOOL bSupportMapper
; /* if type is allowed to support mapper */
47 MMDRV_MAPFUNC Map16To32A
; /* those are function pointers to handle */
48 MMDRV_UNMAPFUNC UnMap16To32A
; /* the parameter conversion (16 vs 32 bit) */
49 MMDRV_MAPFUNC Map32ATo16
; /* when hi-func (in mmsystem or winmm) and */
50 MMDRV_UNMAPFUNC UnMap32ATo16
; /* low-func (in .drv) do not match */
51 LPDRVCALLBACK Callback
; /* handles callback for a specified type */
52 /* those attributes reflect the loaded/current situation for the type */
53 UINT wMaxId
; /* number of loaded devices (sum across all loaded drivers) */
54 LPWINE_MLD lpMlds
; /* "static" mlds to access the part though device IDs */
55 int nMapper
; /* index to mapper */
58 static int MMDrvsHi
/* = 0 */;
59 static WINE_MM_DRIVER MMDrvs
[8];
60 static LPWINE_MLD MM_MLDrvs
[40];
61 #define MAX_MM_MLDRVS (sizeof(MM_MLDrvs) / sizeof(MM_MLDrvs[0]))
63 #define A(_x,_y) {#_y, _x, NULL, NULL, NULL, NULL, NULL, 0, NULL, -1}
64 /* Note: the indices of this array must match the definitions
65 * of the MMDRV_???? manifest constants
67 static WINE_LLTYPE llTypes
[MMDRV_MAX
] = {
77 /******************************************************************
82 void MMDRV_InstallMap(unsigned int drv
,
83 MMDRV_MAPFUNC mp1632
, MMDRV_UNMAPFUNC um1632
,
84 MMDRV_MAPFUNC mp3216
, MMDRV_UNMAPFUNC um3216
,
87 assert(drv
< MMDRV_MAX
);
88 llTypes
[drv
].Map16To32A
= mp1632
;
89 llTypes
[drv
].UnMap16To32A
= um1632
;
90 llTypes
[drv
].Map32ATo16
= mp3216
;
91 llTypes
[drv
].UnMap32ATo16
= um3216
;
92 llTypes
[drv
].Callback
= cb
;
95 /******************************************************************
99 BOOL
MMDRV_Is32(unsigned int idx
)
101 TRACE("(%d)\n", idx
);
102 return MMDrvs
[idx
].bIs32
;
105 /**************************************************************************
106 * MMDRV_GetNum [internal]
108 UINT
MMDRV_GetNum(UINT type
)
110 TRACE("(%04x)\n", type
);
111 assert(type
< MMDRV_MAX
);
112 return llTypes
[type
].wMaxId
;
115 /**************************************************************************
116 * MMDRV_Message [internal]
118 DWORD
MMDRV_Message(LPWINE_MLD mld
, UINT wMsg
, DWORD_PTR dwParam1
,
119 DWORD_PTR dwParam2
, BOOL bFrom32
)
121 LPWINE_MM_DRIVER lpDrv
;
123 WINE_MM_DRIVER_PART
* part
;
124 WINE_LLTYPE
* llType
= &llTypes
[mld
->type
];
128 TRACE("(%s %u %u 0x%08lx 0x%08lx 0x%08lx %c)\n",
129 llTypes
[mld
->type
].typestr
, mld
->uDeviceID
, wMsg
,
130 mld
->dwDriverInstance
, dwParam1
, dwParam2
, bFrom32
?'Y':'N');
132 if (mld
->uDeviceID
== (UINT16
)-1) {
133 if (!llType
->bSupportMapper
) {
134 WARN("uDev=-1 requested on non-mappable ll type %s\n",
135 llTypes
[mld
->type
].typestr
);
136 return MMSYSERR_BADDEVICEID
;
140 if (mld
->uDeviceID
>= llType
->wMaxId
) {
141 WARN("uDev(%u) requested >= max (%d)\n", mld
->uDeviceID
, llType
->wMaxId
);
142 return MMSYSERR_BADDEVICEID
;
144 devID
= mld
->uDeviceID
;
147 lpDrv
= &MMDrvs
[mld
->mmdIndex
];
148 part
= &lpDrv
->parts
[mld
->type
];
151 /* some sanity checks */
152 if (!(part
->nIDMin
<= devID
))
153 ERR("!(part->nIDMin(%d) <= devID(%d))\n", part
->nIDMin
, devID
);
154 if (!(devID
< part
->nIDMax
))
155 ERR("!(devID(%d) < part->nIDMax(%d))\n", devID
, part
->nIDMax
);
159 assert(part
->u
.fnMessage32
);
162 TRACE("Calling message(dev=%u msg=%u usr=0x%08lx p1=0x%08lx p2=0x%08lx)\n",
163 mld
->uDeviceID
, wMsg
, mld
->dwDriverInstance
, dwParam1
, dwParam2
);
164 ret
= part
->u
.fnMessage32(mld
->uDeviceID
, wMsg
, mld
->dwDriverInstance
, dwParam1
, dwParam2
);
165 TRACE("=> %s\n", WINMM_ErrorToString(ret
));
167 map
= llType
->Map16To32A(wMsg
, &mld
->dwDriverInstance
, &dwParam1
, &dwParam2
);
169 case WINMM_MAP_NOMEM
:
170 ret
= MMSYSERR_NOMEM
;
172 case WINMM_MAP_MSGERROR
:
173 FIXME("NIY: no conversion yet 16->32 (%u)\n", wMsg
);
174 ret
= MMSYSERR_ERROR
;
177 case WINMM_MAP_OKMEM
:
178 TRACE("Calling message(dev=%u msg=%u usr=0x%08lx p1=0x%08lx p2=0x%08lx)\n",
179 mld
->uDeviceID
, wMsg
, mld
->dwDriverInstance
, dwParam1
, dwParam2
);
180 ret
= part
->u
.fnMessage32(mld
->uDeviceID
, wMsg
, mld
->dwDriverInstance
,
182 TRACE("=> %s\n", WINMM_ErrorToString(ret
));
183 if (map
== WINMM_MAP_OKMEM
)
184 llType
->UnMap16To32A(wMsg
, &mld
->dwDriverInstance
, &dwParam1
, &dwParam2
, ret
);
188 ret
= MMSYSERR_NOTSUPPORTED
;
193 assert(part
->u
.fnMessage16
&& pFnCallMMDrvFunc16
);
196 map
= llType
->Map32ATo16(wMsg
, &mld
->dwDriverInstance
, &dwParam1
, &dwParam2
);
198 case WINMM_MAP_NOMEM
:
199 ret
= MMSYSERR_NOMEM
;
201 case WINMM_MAP_MSGERROR
:
202 FIXME("NIY: no conversion yet 32->16 (%u)\n", wMsg
);
203 ret
= MMSYSERR_ERROR
;
206 case WINMM_MAP_OKMEM
:
207 TRACE("Calling message(dev=%u msg=%u usr=0x%08lx p1=0x%08lx p2=0x%08lx)\n",
208 mld
->uDeviceID
, wMsg
, mld
->dwDriverInstance
, dwParam1
, dwParam2
);
209 ret
= pFnCallMMDrvFunc16((DWORD
)part
->u
.fnMessage16
,
210 mld
->uDeviceID
, wMsg
, mld
->dwDriverInstance
,
212 TRACE("=> %s\n", WINMM_ErrorToString(ret
));
213 if (map
== WINMM_MAP_OKMEM
)
214 llType
->UnMap32ATo16(wMsg
, &mld
->dwDriverInstance
, &dwParam1
, &dwParam2
, ret
);
218 ret
= MMSYSERR_NOTSUPPORTED
;
222 TRACE("Calling message(dev=%u msg=%u usr=0x%08lx p1=0x%08lx p2=0x%08lx)\n",
223 mld
->uDeviceID
, wMsg
, mld
->dwDriverInstance
, dwParam1
, dwParam2
);
224 ret
= pFnCallMMDrvFunc16((DWORD
)part
->u
.fnMessage16
,
225 mld
->uDeviceID
, wMsg
, mld
->dwDriverInstance
,
227 TRACE("=> %s\n", WINMM_ErrorToString(ret
));
233 /**************************************************************************
234 * MMDRV_Alloc [internal]
236 LPWINE_MLD
MMDRV_Alloc(UINT size
, UINT type
, LPHANDLE hndl
, DWORD
* dwFlags
,
237 DWORD_PTR
* dwCallback
, DWORD_PTR
* dwInstance
, BOOL bFrom32
)
241 TRACE("(%d, %04x, %p, %p, %p, %p, %c)\n",
242 size
, type
, hndl
, dwFlags
, dwCallback
, dwInstance
, bFrom32
?'Y':'N');
244 mld
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
245 if (!mld
) return NULL
;
247 /* find an empty slot in MM_MLDrvs table */
248 for (i
= 0; i
< MAX_MM_MLDRVS
; i
++) if (!MM_MLDrvs
[i
]) break;
250 if (i
== MAX_MM_MLDRVS
) {
251 /* the MM_MLDrvs table could be made growable in the future if needed */
252 ERR("Too many open drivers\n");
253 HeapFree(GetProcessHeap(), 0, mld
);
257 *hndl
= (HANDLE
)(i
| 0x8000);
260 if ((UINT_PTR
)*hndl
< MMDRV_GetNum(type
) || ((UINT_PTR
)*hndl
>> 16)) {
261 /* FIXME: those conditions must be fulfilled so that:
262 * - we can distinguish between device IDs and handles
263 * - we can use handles as 16 or 32 bit entities
265 ERR("Shouldn't happen. Bad allocation scheme\n");
268 mld
->bFrom32
= bFrom32
;
269 mld
->dwFlags
= HIWORD(*dwFlags
);
270 mld
->dwCallback
= *dwCallback
;
271 mld
->dwClientInstance
= *dwInstance
;
273 if (llTypes
[type
].Callback
)
275 *dwFlags
= LOWORD(*dwFlags
) | CALLBACK_FUNCTION
;
276 *dwCallback
= (DWORD_PTR
)llTypes
[type
].Callback
;
277 *dwInstance
= (DWORD_PTR
)mld
; /* FIXME: wouldn't some 16 bit drivers only use the loword ? */
283 /**************************************************************************
284 * MMDRV_Free [internal]
286 void MMDRV_Free(HANDLE hndl
, LPWINE_MLD mld
)
288 TRACE("(%p, %p)\n", hndl
, mld
);
290 if ((UINT_PTR
)hndl
& 0x8000) {
291 UINT_PTR idx
= (UINT_PTR
)hndl
& ~0x8000;
292 if (idx
< sizeof(MM_MLDrvs
) / sizeof(MM_MLDrvs
[0])) {
293 MM_MLDrvs
[idx
] = NULL
;
294 HeapFree(GetProcessHeap(), 0, mld
);
298 ERR("Bad Handle %p at %p (not freed)\n", hndl
, mld
);
301 /**************************************************************************
302 * MMDRV_Open [internal]
304 DWORD
MMDRV_Open(LPWINE_MLD mld
, UINT wMsg
, DWORD_PTR dwParam1
, DWORD dwFlags
)
306 DWORD dwRet
= MMSYSERR_BADDEVICEID
;
307 DWORD_PTR dwInstance
;
308 WINE_LLTYPE
* llType
= &llTypes
[mld
->type
];
309 TRACE("(%p, %04x, 0x%08lx, 0x%08x)\n", mld
, wMsg
, dwParam1
, dwFlags
);
311 mld
->dwDriverInstance
= (DWORD_PTR
)&dwInstance
;
313 if (mld
->uDeviceID
== (UINT
)-1 || mld
->uDeviceID
== (UINT16
)-1) {
314 TRACE("MAPPER mode requested !\n");
315 /* check if mapper is supported by type */
316 if (llType
->bSupportMapper
) {
317 if (llType
->nMapper
== -1) {
318 /* no driver for mapper has been loaded, try a dumb implementation */
319 TRACE("No mapper loaded, doing it by hand\n");
320 for (mld
->uDeviceID
= 0; mld
->uDeviceID
< llType
->wMaxId
; mld
->uDeviceID
++) {
321 if ((dwRet
= MMDRV_Open(mld
, wMsg
, dwParam1
, dwFlags
)) == MMSYSERR_NOERROR
) {
322 /* to share this function epilog */
323 dwInstance
= mld
->dwDriverInstance
;
328 mld
->uDeviceID
= (UINT16
)-1;
329 mld
->mmdIndex
= llType
->lpMlds
[-1].mmdIndex
;
330 TRACE("Setting mmdIndex to %u\n", mld
->mmdIndex
);
331 dwRet
= MMDRV_Message(mld
, wMsg
, dwParam1
, dwFlags
, TRUE
);
335 if (mld
->uDeviceID
< llType
->wMaxId
) {
336 mld
->mmdIndex
= llType
->lpMlds
[mld
->uDeviceID
].mmdIndex
;
337 TRACE("Setting mmdIndex to %u\n", mld
->mmdIndex
);
338 dwRet
= MMDRV_Message(mld
, wMsg
, dwParam1
, dwFlags
, TRUE
);
341 if (dwRet
== MMSYSERR_NOERROR
)
342 mld
->dwDriverInstance
= dwInstance
;
346 /**************************************************************************
347 * MMDRV_Close [internal]
349 DWORD
MMDRV_Close(LPWINE_MLD mld
, UINT wMsg
)
351 TRACE("(%p, %04x)\n", mld
, wMsg
);
352 return MMDRV_Message(mld
, wMsg
, 0L, 0L, TRUE
);
355 /**************************************************************************
356 * MMDRV_GetByID [internal]
358 static LPWINE_MLD
MMDRV_GetByID(UINT uDevID
, UINT type
)
360 TRACE("(%04x, %04x)\n", uDevID
, type
);
361 if (uDevID
< llTypes
[type
].wMaxId
)
362 return &llTypes
[type
].lpMlds
[uDevID
];
363 if ((uDevID
== (UINT16
)-1 || uDevID
== (UINT
)-1) && llTypes
[type
].nMapper
!= -1)
364 return &llTypes
[type
].lpMlds
[-1];
368 /**************************************************************************
369 * MMDRV_Get [internal]
371 LPWINE_MLD
MMDRV_Get(HANDLE _hndl
, UINT type
, BOOL bCanBeID
)
373 LPWINE_MLD mld
= NULL
;
374 UINT_PTR hndl
= (UINT_PTR
)_hndl
;
375 TRACE("(%p, %04x, %c)\n", _hndl
, type
, bCanBeID
? 'Y' : 'N');
377 assert(type
< MMDRV_MAX
);
379 if (hndl
>= llTypes
[type
].wMaxId
&&
380 hndl
!= (UINT16
)-1 && hndl
!= (UINT
)-1) {
382 UINT idx
= hndl
& ~0x8000;
383 if (idx
< sizeof(MM_MLDrvs
) / sizeof(MM_MLDrvs
[0])) {
386 mld
= MM_MLDrvs
[idx
];
387 if (mld
&& mld
->type
!= type
) mld
= NULL
;
397 if (mld
== NULL
&& bCanBeID
) {
398 mld
= MMDRV_GetByID(hndl
, type
);
403 /**************************************************************************
404 * MMDRV_GetRelated [internal]
406 LPWINE_MLD
MMDRV_GetRelated(HANDLE hndl
, UINT srcType
,
407 BOOL bSrcCanBeID
, UINT dstType
)
410 TRACE("(%p, %04x, %c, %04x)\n",
411 hndl
, srcType
, bSrcCanBeID
? 'Y' : 'N', dstType
);
413 if ((mld
= MMDRV_Get(hndl
, srcType
, bSrcCanBeID
)) != NULL
) {
414 WINE_MM_DRIVER_PART
* part
= &MMDrvs
[mld
->mmdIndex
].parts
[dstType
];
415 if (part
->nIDMin
< part
->nIDMax
)
416 return MMDRV_GetByID(part
->nIDMin
, dstType
);
421 /**************************************************************************
422 * MMDRV_PhysicalFeatures [internal]
424 UINT
MMDRV_PhysicalFeatures(LPWINE_MLD mld
, UINT uMsg
,
425 DWORD_PTR dwParam1
, DWORD_PTR dwParam2
)
427 WINE_MM_DRIVER
* lpDrv
= &MMDrvs
[mld
->mmdIndex
];
429 TRACE("(%p, %04x, %08lx, %08lx)\n", mld
, uMsg
, dwParam1
, dwParam2
);
431 /* all those function calls are undocumented */
433 case DRV_QUERYDRVENTRY
:
434 lstrcpynA((LPSTR
)dwParam1
, lpDrv
->drvname
, LOWORD(dwParam2
));
436 case DRV_QUERYDEVNODE
:
437 *(LPDWORD
)dwParam1
= 0L; /* should be DevNode */
440 WARN("NIY QueryName\n");
442 case DRV_QUERYDRIVERIDS
:
443 WARN("NIY call VxD\n");
444 /* should call VxD MMDEVLDR with (DevNode, dwParam1 and dwParam2) as pmts
445 * dwParam1 is buffer and dwParam2 is sizeof(buffer)
446 * I don't know where the result is stored though
449 case DRV_QUERYMAPPABLE
:
450 return (lpDrv
->bIsMapper
) ? 2 : 0;
452 case DRVM_MAPPER_PREFERRED_GET
:
453 /* FIXME: get from registry someday */
454 *((LPDWORD
)dwParam1
) = -1; /* No preferred device */
455 *((LPDWORD
)dwParam2
) = 0;
458 case DRV_QUERYDEVICEINTERFACE
:
459 case DRV_QUERYDEVICEINTERFACESIZE
:
460 return MMDRV_Message(mld
, uMsg
, dwParam1
, dwParam2
, TRUE
);
462 case DRV_QUERYDSOUNDIFACE
: /* Wine-specific: Retrieve DirectSound interface */
463 case DRV_QUERYDSOUNDDESC
: /* Wine-specific: Retrieve DirectSound driver description*/
464 return MMDRV_Message(mld
, uMsg
, dwParam1
, dwParam2
, TRUE
);
467 WARN("Unknown call %04x\n", uMsg
);
468 return MMSYSERR_INVALPARAM
;
473 /**************************************************************************
474 * MMDRV_InitPerType [internal]
476 static BOOL
MMDRV_InitPerType(LPWINE_MM_DRIVER lpDrv
, UINT type
, UINT wMsg
)
478 WINE_MM_DRIVER_PART
* part
= &lpDrv
->parts
[type
];
482 TRACE("(%p, %04x, %04x)\n", lpDrv
, type
, wMsg
);
484 part
->nIDMin
= part
->nIDMax
= 0;
486 /* for DRVM_INIT and DRVM_ENABLE, dwParam2 should be PnP node */
487 /* the DRVM_ENABLE is only required when the PnP node is non zero */
489 if (lpDrv
->bIs32
&& part
->u
.fnMessage32
) {
490 ret
= part
->u
.fnMessage32(0, DRVM_INIT
, 0L, 0L, 0L);
491 TRACE("DRVM_INIT => %s\n", WINMM_ErrorToString(ret
));
493 ret
= part
->u
.fnMessage32(0, DRVM_ENABLE
, 0L, 0L, 0L);
494 TRACE("DRVM_ENABLE => %08lx\n", ret
);
496 count
= part
->u
.fnMessage32(0, wMsg
, 0L, 0L, 0L);
497 } else if (!lpDrv
->bIs32
&& part
->u
.fnMessage16
&& pFnCallMMDrvFunc16
) {
498 ret
= pFnCallMMDrvFunc16((DWORD
)part
->u
.fnMessage16
,
499 0, DRVM_INIT
, 0L, 0L, 0L);
500 TRACE("DRVM_INIT => %s\n", WINMM_ErrorToString(ret
));
502 ret
= pFnCallMMDrvFunc16((DWORD
)part
->u
.fnMessage16
,
503 0, DRVM_ENABLE
, 0L, 0L, 0L);
504 TRACE("DRVM_ENABLE => %08lx\n", ret
);
506 count
= pFnCallMMDrvFunc16((DWORD
)part
->u
.fnMessage16
,
507 0, wMsg
, 0L, 0L, 0L);
512 TRACE("Got %u dev for (%s:%s)\n", count
, lpDrv
->drvname
, llTypes
[type
].typestr
);
517 /* got some drivers */
518 if (lpDrv
->bIsMapper
) {
519 /* it seems native mappers return 0 devices :-( */
520 if (llTypes
[type
].nMapper
!= -1)
521 ERR("Two mappers for type %s (%d, %s)\n",
522 llTypes
[type
].typestr
, llTypes
[type
].nMapper
, lpDrv
->drvname
);
524 ERR("Strange: mapper with %d > 1 devices\n", count
);
525 llTypes
[type
].nMapper
= MMDrvsHi
;
529 part
->nIDMin
= llTypes
[type
].wMaxId
;
530 llTypes
[type
].wMaxId
+= count
;
531 part
->nIDMax
= llTypes
[type
].wMaxId
;
533 TRACE("Setting min=%d max=%d (ttop=%d) for (%s:%s)\n",
534 part
->nIDMin
, part
->nIDMax
, llTypes
[type
].wMaxId
,
535 lpDrv
->drvname
, llTypes
[type
].typestr
);
536 /* realloc translation table */
537 if (llTypes
[type
].lpMlds
)
538 llTypes
[type
].lpMlds
= (LPWINE_MLD
)
539 HeapReAlloc(GetProcessHeap(), 0, llTypes
[type
].lpMlds
- 1,
540 sizeof(WINE_MLD
) * (llTypes
[type
].wMaxId
+ 1)) + 1;
542 llTypes
[type
].lpMlds
= (LPWINE_MLD
)
543 HeapAlloc(GetProcessHeap(), 0,
544 sizeof(WINE_MLD
) * (llTypes
[type
].wMaxId
+ 1)) + 1;
546 /* re-build the translation table */
547 if (llTypes
[type
].nMapper
!= -1) {
548 TRACE("%s:Trans[%d] -> %s\n", llTypes
[type
].typestr
, -1, MMDrvs
[llTypes
[type
].nMapper
].drvname
);
549 llTypes
[type
].lpMlds
[-1].uDeviceID
= (UINT16
)-1;
550 llTypes
[type
].lpMlds
[-1].type
= type
;
551 llTypes
[type
].lpMlds
[-1].mmdIndex
= llTypes
[type
].nMapper
;
552 llTypes
[type
].lpMlds
[-1].dwDriverInstance
= 0;
554 for (i
= k
= 0; i
<= MMDrvsHi
; i
++) {
555 while (MMDrvs
[i
].parts
[type
].nIDMin
<= k
&& k
< MMDrvs
[i
].parts
[type
].nIDMax
) {
556 TRACE("%s:Trans[%d] -> %s\n", llTypes
[type
].typestr
, k
, MMDrvs
[i
].drvname
);
557 llTypes
[type
].lpMlds
[k
].uDeviceID
= k
;
558 llTypes
[type
].lpMlds
[k
].type
= type
;
559 llTypes
[type
].lpMlds
[k
].mmdIndex
= i
;
560 llTypes
[type
].lpMlds
[k
].dwDriverInstance
= 0;
567 /**************************************************************************
568 * MMDRV_Install [internal]
570 static BOOL
MMDRV_Install(LPCSTR drvRegName
, LPCSTR drvFileName
, BOOL bIsMapper
)
573 LPWINE_MM_DRIVER lpDrv
= &MMDrvs
[MMDrvsHi
];
576 TRACE("('%s', '%s', mapper=%c);\n", drvRegName
, drvFileName
, bIsMapper
? 'Y' : 'N');
578 for (i
= 0; i
< MMDrvsHi
; i
++) {
579 if (!strcmp(drvRegName
, MMDrvs
[i
].drvname
)) return FALSE
;
582 /* Be sure that size of MMDrvs matches the max number of loadable
584 * If not just increase size of MMDrvs
586 assert(MMDrvsHi
<= sizeof(MMDrvs
)/sizeof(MMDrvs
[0]));
588 memset(lpDrv
, 0, sizeof(*lpDrv
));
590 if (!(lpDrv
->hDriver
= OpenDriverA(drvFileName
, 0, 0))) {
591 WARN("Couldn't open driver '%s'\n", drvFileName
);
595 d
= DRIVER_FindFromHDrvr(lpDrv
->hDriver
);
596 lpDrv
->bIs32
= (d
->dwFlags
& WINE_GDF_16BIT
) ? FALSE
: TRUE
;
598 /* Then look for xxxMessage functions */
599 #define AA(_h,_w,_x,_y,_z) \
600 func = (WINEMM_msgFunc##_y) _z ((_h), #_x); \
602 { lpDrv->parts[_w].u.fnMessage##_y = func; count++; \
603 TRACE("Got %d bit func '%s'\n", _y, #_x); }
606 WINEMM_msgFunc32 func
;
608 if (d
->d
.d32
.hModule
) {
609 #define A(_x,_y) AA(d->d.d32.hModule,_x,_y,32,GetProcAddress)
610 A(MMDRV_AUX
, auxMessage
);
611 A(MMDRV_MIXER
, mxdMessage
);
612 A(MMDRV_MIDIIN
, midMessage
);
613 A(MMDRV_MIDIOUT
, modMessage
);
614 A(MMDRV_WAVEIN
, widMessage
);
615 A(MMDRV_WAVEOUT
, wodMessage
);
618 } else if (WINMM_CheckForMMSystem() && pFnLoadMMDrvFunc16
) {
619 count
+= pFnLoadMMDrvFunc16(drvFileName
, d
, lpDrv
);
624 CloseDriver(lpDrv
->hDriver
, 0, 0);
625 WARN("No message functions found\n");
629 /* FIXME: being a mapper or not should be known by another way */
630 /* it's known for NE drvs (the description is of the form '*mapper: *'
631 * I don't have any clue for PE drvs
633 lpDrv
->bIsMapper
= bIsMapper
;
634 lpDrv
->drvname
= strcpy(HeapAlloc(GetProcessHeap(), 0, strlen(drvRegName
) + 1), drvRegName
);
636 /* Finish init and get the count of the devices */
638 if (MMDRV_InitPerType(lpDrv
, MMDRV_AUX
, AUXDM_GETNUMDEVS
)) i
= 1;
639 if (MMDRV_InitPerType(lpDrv
, MMDRV_MIXER
, MXDM_GETNUMDEVS
)) i
= 1;
640 if (MMDRV_InitPerType(lpDrv
, MMDRV_MIDIIN
, MIDM_GETNUMDEVS
)) i
= 1;
641 if (MMDRV_InitPerType(lpDrv
, MMDRV_MIDIOUT
, MODM_GETNUMDEVS
)) i
= 1;
642 if (MMDRV_InitPerType(lpDrv
, MMDRV_WAVEIN
, WIDM_GETNUMDEVS
)) i
= 1;
643 if (MMDRV_InitPerType(lpDrv
, MMDRV_WAVEOUT
, WODM_GETNUMDEVS
)) i
= 1;
644 /* if all those func calls return FALSE, then the driver must be unloaded */
646 CloseDriver(lpDrv
->hDriver
, 0, 0);
647 HeapFree(GetProcessHeap(), 0, lpDrv
->drvname
);
648 WARN("Driver initialization failed\n");
657 /**************************************************************************
660 BOOL
MMDRV_Init(void)
663 char driver_buffer
[256];
664 char mapper_buffer
[256];
665 char midi_buffer
[256];
671 strcpy(driver_buffer
, WINE_DEFAULT_WINMM_DRIVER
);
672 strcpy(mapper_buffer
, WINE_DEFAULT_WINMM_MAPPER
);
673 strcpy(midi_buffer
, WINE_DEFAULT_WINMM_MIDI
);
675 /* @@ Wine registry key: HKCU\Software\Wine\Drivers */
676 if (!RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Drivers", &hKey
))
678 size
= sizeof(driver_buffer
);
679 if (RegQueryValueExA(hKey
, "Audio", 0, &type
, (LPVOID
)driver_buffer
, &size
))
680 strcpy(driver_buffer
, WINE_DEFAULT_WINMM_DRIVER
);
686 char filename
[sizeof(driver_buffer
)+10];
687 char *next
= strchr(p
, ',');
688 if (next
) *next
++ = 0;
689 sprintf( filename
, "wine%s.drv", p
);
690 if ((ret
= MMDRV_Install( filename
, filename
, FALSE
))) break;
694 ret
|= MMDRV_Install("wavemapper", WINE_DEFAULT_WINMM_MAPPER
, TRUE
);
695 ret
|= MMDRV_Install("midimapper", WINE_DEFAULT_WINMM_MIDI
, TRUE
);
699 /******************************************************************
704 static BOOL
MMDRV_ExitPerType(LPWINE_MM_DRIVER lpDrv
, UINT type
)
706 WINE_MM_DRIVER_PART
* part
= &lpDrv
->parts
[type
];
708 TRACE("(%p, %04x)\n", lpDrv
, type
);
710 if (lpDrv
->bIs32
&& part
->u
.fnMessage32
) {
712 ret
= part
->u
.fnMessage32(0, DRVM_DISABLE
, 0L, 0L, 0L);
713 TRACE("DRVM_DISABLE => %08lx\n", ret
);
715 ret
= part
->u
.fnMessage32(0, DRVM_EXIT
, 0L, 0L, 0L);
716 TRACE("DRVM_EXIT => %s\n", WINMM_ErrorToString(ret
));
717 } else if (!lpDrv
->bIs32
&& part
->u
.fnMessage16
&& pFnCallMMDrvFunc16
) {
719 ret
= pFnCallMMDrvFunc16((DWORD
)part
->u
.fnMessage16
,
720 0, DRVM_DISABLE
, 0L, 0L, 0L);
721 TRACE("DRVM_DISABLE => %08lx\n", ret
);
723 ret
= pFnCallMMDrvFunc16((DWORD
)part
->u
.fnMessage16
,
724 0, DRVM_EXIT
, 0L, 0L, 0L);
725 TRACE("DRVM_EXIT => %s\n", WINMM_ErrorToString(ret
));
733 /******************************************************************
738 void MMDRV_Exit(void)
743 for (i
= 0; i
< sizeof(MM_MLDrvs
) / sizeof(MM_MLDrvs
[0]); i
++)
745 if (MM_MLDrvs
[i
] != NULL
)
747 FIXME("Closing while ll-driver open\n");
749 /* FIXME: should generate a message depending on type */
750 MMDRV_Free((HANDLE
)(i
| 0x8000), MM_MLDrvs
[i
]);
755 /* unload driver, in reverse order of loading */
756 i
= sizeof(MMDrvs
) / sizeof(MMDrvs
[0]);
759 MMDRV_ExitPerType(&MMDrvs
[i
], MMDRV_AUX
);
760 MMDRV_ExitPerType(&MMDrvs
[i
], MMDRV_MIXER
);
761 MMDRV_ExitPerType(&MMDrvs
[i
], MMDRV_MIDIIN
);
762 MMDRV_ExitPerType(&MMDrvs
[i
], MMDRV_MIDIOUT
);
763 MMDRV_ExitPerType(&MMDrvs
[i
], MMDRV_WAVEIN
);
764 MMDRV_ExitPerType(&MMDrvs
[i
], MMDRV_WAVEOUT
);
765 CloseDriver(MMDrvs
[i
].hDriver
, 0, 0);
767 if (llTypes
[MMDRV_AUX
].lpMlds
)
768 HeapFree(GetProcessHeap(), 0, llTypes
[MMDRV_AUX
].lpMlds
- 1);
769 if (llTypes
[MMDRV_MIXER
].lpMlds
)
770 HeapFree(GetProcessHeap(), 0, llTypes
[MMDRV_MIXER
].lpMlds
- 1);
771 if (llTypes
[MMDRV_MIDIIN
].lpMlds
)
772 HeapFree(GetProcessHeap(), 0, llTypes
[MMDRV_MIDIIN
].lpMlds
- 1);
773 if (llTypes
[MMDRV_MIDIOUT
].lpMlds
)
774 HeapFree(GetProcessHeap(), 0, llTypes
[MMDRV_MIDIOUT
].lpMlds
- 1);
775 if (llTypes
[MMDRV_WAVEIN
].lpMlds
)
776 HeapFree(GetProcessHeap(), 0, llTypes
[MMDRV_WAVEIN
].lpMlds
- 1);
777 if (llTypes
[MMDRV_WAVEOUT
].lpMlds
)
778 HeapFree(GetProcessHeap(), 0, llTypes
[MMDRV_WAVEOUT
].lpMlds
- 1);