netstat: Initial implementation.
[wine] / dlls / winmm / lolvldrv.c
1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
2
3 /*
4  * MMSYSTEM low level drivers handling functions
5  *
6  * Copyright 1999 Eric Pouech
7  *
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.
12  *
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.
17  *
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
21  */
22
23 #include "config.h"
24 #include "wine/port.h"
25
26 #define NONAMELESSUNION
27 #define NONAMELESSSTRUCT
28 #define COBJMACROS
29 #include <string.h>
30 #include <stdarg.h>
31 #include <stdio.h>
32 #include <assert.h>
33 #include "windef.h"
34 #include "winbase.h"
35 #include "winreg.h"
36 #include "winnls.h"
37 #include "winemm.h"
38 #include "wine/debug.h"
39 #include "wine/exception.h"
40
41 #include "wingdi.h"
42 #include "ole2.h"
43 #include "devpkey.h"
44 #include "mmdeviceapi.h"
45
46 WINE_DEFAULT_DEBUG_CHANNEL(winmm);
47
48 /* each known type of driver has an instance of this structure */
49 typedef struct tagWINE_LLTYPE {
50     /* those attributes depend on the specification of the type */
51     LPCSTR              typestr;        /* name (for debugging) */
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 */
56 } WINE_LLTYPE;
57
58 static WINE_LLTYPE llTypes[MMDRV_MAX] = {
59     { "Aux", 0, 0, -1 },
60     { "Mixer", 0, 0, -1 },
61     { "MidiIn", 0, 0, -1 },
62     { "MidiOut", 0, 0, -1 },
63     { "WaveIn", 0, 0, -1 },
64     { "WaveOut", 0, 0, -1 }
65 };
66
67 static int drivers_loaded, MMDrvsHi;
68 static WINE_MM_DRIVER   MMDrvs[8];
69 static LPWINE_MLD       MM_MLDrvs[40];
70 #define MAX_MM_MLDRVS   (sizeof(MM_MLDrvs) / sizeof(MM_MLDrvs[0]))
71
72 static void MMDRV_Init(void);
73
74 static void MMDRV_InitSingleType(UINT type) {
75     if (!drivers_loaded) {
76         drivers_loaded = 1;
77         MMDRV_Init();
78     }
79 }
80
81 /**************************************************************************
82  *                      MMDRV_GetNum                            [internal]
83  */
84 UINT    MMDRV_GetNum(UINT type)
85 {
86     TRACE("(%04x)\n", type);
87     assert(type < MMDRV_MAX);
88     MMDRV_InitSingleType(type);
89     return llTypes[type].wMaxId;
90 }
91
92 /**************************************************************************
93  *                              MMDRV_Message                   [internal]
94  */
95 DWORD  MMDRV_Message(LPWINE_MLD mld, UINT wMsg, DWORD_PTR dwParam1,
96                      DWORD_PTR dwParam2)
97 {
98     LPWINE_MM_DRIVER            lpDrv;
99     DWORD                       ret;
100     WINE_MM_DRIVER_PART*        part;
101     WINE_LLTYPE*                llType = &llTypes[mld->type];
102
103     TRACE("(%s %d %u 0x%08lx 0x%08lx 0x%08lx)\n",
104           llTypes[mld->type].typestr, mld->uDeviceID, wMsg,
105           mld->dwDriverInstance, dwParam1, dwParam2);
106
107     if ((UINT16)mld->uDeviceID == (UINT16)-1) {
108         if (llType->nMapper == -1) {
109             WARN("uDev=-1 requested on non-mapped ll type %s\n",
110                  llTypes[mld->type].typestr);
111             return MMSYSERR_BADDEVICEID;
112         }
113     } else {
114         if (mld->uDeviceID >= llType->wMaxId) {
115             WARN("uDev(%u) requested >= max (%d)\n", mld->uDeviceID, llType->wMaxId);
116             return MMSYSERR_BADDEVICEID;
117         }
118     }
119
120     lpDrv = &MMDrvs[mld->mmdIndex];
121     part = &lpDrv->parts[mld->type];
122
123     assert(part->fnMessage32);
124
125     TRACE("Calling message(dev=%d msg=%u usr=0x%08lx p1=0x%08lx p2=0x%08lx)\n",
126           mld->uDeviceID, wMsg, mld->dwDriverInstance, dwParam1, dwParam2);
127     ret = part->fnMessage32(mld->uDeviceID, wMsg, mld->dwDriverInstance, dwParam1, dwParam2);
128     TRACE("=> %s\n", WINMM_ErrorToString(ret));
129
130     return ret;
131 }
132
133 /**************************************************************************
134  *                              MMDRV_Alloc                     [internal]
135  */
136 LPWINE_MLD      MMDRV_Alloc(UINT size, UINT type, LPHANDLE hndl, DWORD* dwFlags,
137                             DWORD_PTR* dwCallback, DWORD_PTR* dwInstance)
138 {
139     LPWINE_MLD  mld;
140     UINT_PTR i;
141     TRACE("(%d, %04x, %p, %p, %p, %p)\n",
142           size, type, hndl, dwFlags, dwCallback, dwInstance);
143
144     mld = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
145     if (!mld)   return NULL;
146
147     /* find an empty slot in MM_MLDrvs table */
148     for (i = 0; i < MAX_MM_MLDRVS; i++) if (!MM_MLDrvs[i]) break;
149
150     if (i == MAX_MM_MLDRVS) {
151         /* the MM_MLDrvs table could be made growable in the future if needed */
152         ERR("Too many open drivers\n");
153         HeapFree(GetProcessHeap(), 0, mld);
154         return NULL;
155     }
156     MM_MLDrvs[i] = mld;
157     *hndl = (HANDLE)(i | 0x8000);
158
159     mld->type = type;
160     if ((UINT_PTR)*hndl < MMDRV_GetNum(type) || ((UINT_PTR)*hndl >> 16)) {
161         /* FIXME: those conditions must be fulfilled so that:
162          * - we can distinguish between device IDs and handles
163          * - we can use handles as 16 or 32 bit entities
164          */
165         ERR("Shouldn't happen. Bad allocation scheme\n");
166     }
167
168     mld->dwFlags = HIWORD(*dwFlags);
169     mld->dwCallback = *dwCallback;
170     mld->dwClientInstance = *dwInstance;
171
172     return mld;
173 }
174
175 /**************************************************************************
176  *                              MMDRV_Free                      [internal]
177  */
178 void    MMDRV_Free(HANDLE hndl, LPWINE_MLD mld)
179 {
180     TRACE("(%p, %p)\n", hndl, mld);
181
182     if ((UINT_PTR)hndl & 0x8000) {
183         UINT_PTR idx = (UINT_PTR)hndl & ~0x8000;
184         if (idx < sizeof(MM_MLDrvs) / sizeof(MM_MLDrvs[0])) {
185             MM_MLDrvs[idx] = NULL;
186             HeapFree(GetProcessHeap(), 0, mld);
187             return;
188         }
189     }
190     ERR("Bad Handle %p at %p (not freed)\n", hndl, mld);
191 }
192
193 /**************************************************************************
194  *                              MMDRV_Open                      [internal]
195  */
196 DWORD MMDRV_Open(LPWINE_MLD mld, UINT wMsg, DWORD_PTR dwParam1, DWORD dwFlags)
197 {
198     DWORD               dwRet = MMSYSERR_BADDEVICEID;
199     DWORD_PTR           dwInstance;
200     WINE_LLTYPE*        llType = &llTypes[mld->type];
201     TRACE("(%p, %04x, 0x%08lx, 0x%08x)\n", mld, wMsg, dwParam1, dwFlags);
202
203     mld->dwDriverInstance = (DWORD_PTR)&dwInstance;
204
205     if (mld->uDeviceID == (UINT)-1 || mld->uDeviceID == (UINT16)-1) {
206         TRACE("MAPPER mode requested !\n");
207         if (llType->nMapper == -1) {
208             WARN("Mapper not supported for type %s\n", llTypes[mld->type].typestr);
209             return MMSYSERR_BADDEVICEID;
210         }
211         mld->mmdIndex = llType->lpMlds[-1].mmdIndex;
212         TRACE("Setting mmdIndex to %u\n", mld->mmdIndex);
213         dwRet = MMDRV_Message(mld, wMsg, dwParam1, dwFlags);
214     } else {
215         if (mld->uDeviceID < llType->wMaxId) {
216             mld->mmdIndex = llType->lpMlds[mld->uDeviceID].mmdIndex;
217             TRACE("Setting mmdIndex to %u\n", mld->mmdIndex);
218             dwRet = MMDRV_Message(mld, wMsg, dwParam1, dwFlags);
219         }
220     }
221     if (dwRet == MMSYSERR_NOERROR)
222         mld->dwDriverInstance = dwInstance;
223     return dwRet;
224 }
225
226 /**************************************************************************
227  *                              MMDRV_Close                     [internal]
228  */
229 DWORD   MMDRV_Close(LPWINE_MLD mld, UINT wMsg)
230 {
231     TRACE("(%p, %04x)\n", mld, wMsg);
232     return MMDRV_Message(mld, wMsg, 0L, 0L);
233 }
234
235 /**************************************************************************
236  *                              MMDRV_GetByID                   [internal]
237  */
238 static LPWINE_MLD MMDRV_GetByID(UINT uDevID, UINT type)
239 {
240     TRACE("(%04x, %04x)\n", uDevID, type);
241     if (uDevID < llTypes[type].wMaxId)
242         return &llTypes[type].lpMlds[uDevID];
243     if ((uDevID == (UINT16)-1 || uDevID == (UINT)-1) && llTypes[type].nMapper != -1)
244         return &llTypes[type].lpMlds[-1];
245     return NULL;
246 }
247
248 /**************************************************************************
249  *                              MMDRV_Get                       [internal]
250  */
251 LPWINE_MLD      MMDRV_Get(HANDLE _hndl, UINT type, BOOL bCanBeID)
252 {
253     LPWINE_MLD  mld = NULL;
254     UINT_PTR    hndl = (UINT_PTR)_hndl;
255     TRACE("(%p, %04x, %c)\n", _hndl, type, bCanBeID ? 'Y' : 'N');
256
257     assert(type < MMDRV_MAX);
258     MMDRV_InitSingleType(type);
259
260     if (hndl >= llTypes[type].wMaxId &&
261         hndl != (UINT16)-1 && hndl != (UINT)-1) {
262         if (hndl & 0x8000) {
263             UINT idx = hndl & ~0x8000;
264             if (idx < sizeof(MM_MLDrvs) / sizeof(MM_MLDrvs[0])) {
265                 __TRY
266                 {
267                     mld = MM_MLDrvs[idx];
268                     if (mld && mld->type != type) mld = NULL;
269                 }
270                 __EXCEPT_PAGE_FAULT
271                 {
272                     mld = NULL;
273                 }
274                 __ENDTRY;
275             }
276         }
277     }
278     if (mld == NULL && bCanBeID) {
279         mld = MMDRV_GetByID(hndl, type);
280     }
281     return mld;
282 }
283
284 /**************************************************************************
285  *                              MMDRV_PhysicalFeatures          [internal]
286  */
287 UINT    MMDRV_PhysicalFeatures(LPWINE_MLD mld, UINT uMsg,
288                                DWORD_PTR dwParam1, DWORD_PTR dwParam2)
289 {
290     WINE_MM_DRIVER*     lpDrv = &MMDrvs[mld->mmdIndex];
291
292     TRACE("(%p, %04x, %08lx, %08lx)\n", mld, uMsg, dwParam1, dwParam2);
293
294     /* all those function calls are undocumented */
295     switch (uMsg) {
296     case DRV_QUERYDRVENTRY:
297         lstrcpynA((LPSTR)dwParam1, lpDrv->drvname, LOWORD(dwParam2));
298         break;
299     case DRV_QUERYDEVNODE:
300         *(LPDWORD)dwParam1 = 0L; /* should be DevNode */
301         break;
302     case DRV_QUERYNAME:
303         WARN("NIY QueryName\n");
304         break;
305     case DRV_QUERYDRIVERIDS:
306         WARN("NIY call VxD\n");
307         /* should call VxD MMDEVLDR with (DevNode, dwParam1 and dwParam2) as pmts
308          * dwParam1 is buffer and dwParam2 is sizeof(buffer)
309          * I don't know where the result is stored though
310          */
311         break;
312     case DRV_QUERYMAPPABLE:
313         return (lpDrv->bIsMapper) ? 2 : 0;
314
315     case DRVM_MAPPER_PREFERRED_GET:
316         /* FIXME: get from registry someday */
317         *((LPDWORD)dwParam1) = -1;      /* No preferred device */
318         *((LPDWORD)dwParam2) = 0;
319         break;
320
321     case DRV_QUERYDEVICEINTERFACE:
322     case DRV_QUERYDEVICEINTERFACESIZE:
323         return MMDRV_Message(mld, uMsg, dwParam1, dwParam2);
324
325     default:
326         WARN("Unknown call %04x\n", uMsg);
327         return MMSYSERR_INVALPARAM;
328     }
329     return 0L;
330 }
331
332 /**************************************************************************
333  *                              MMDRV_InitPerType               [internal]
334  */
335 static  BOOL    MMDRV_InitPerType(LPWINE_MM_DRIVER lpDrv, UINT type, UINT wMsg)
336 {
337     WINE_MM_DRIVER_PART*        part = &lpDrv->parts[type];
338     DWORD                       ret;
339     UINT                        count = 0;
340     int                         i, k;
341     TRACE("(%p, %04x, %04x)\n", lpDrv, type, wMsg);
342
343     part->nIDMin = part->nIDMax = 0;
344
345     /* for DRVM_INIT and DRVM_ENABLE, dwParam2 should be PnP node */
346     /* the DRVM_ENABLE is only required when the PnP node is non zero */
347     if (part->fnMessage32) {
348         ret = part->fnMessage32(0, DRVM_INIT, 0L, 0L, 0L);
349         TRACE("DRVM_INIT => %s\n", WINMM_ErrorToString(ret));
350 #if 0
351         ret = part->fnMessage32(0, DRVM_ENABLE, 0L, 0L, 0L);
352         TRACE("DRVM_ENABLE => %08lx\n", ret);
353 #endif
354         count = part->fnMessage32(0, wMsg, 0L, 0L, 0L);
355     }
356     else return FALSE;
357
358     TRACE("Got %u dev for (%s:%s)\n", count, lpDrv->drvname, llTypes[type].typestr);
359     
360     if (HIWORD(count))
361         return FALSE;
362
363     /* got some drivers */
364     if (lpDrv->bIsMapper) {
365         llTypes[type].nMapper = MMDrvsHi;
366     } else {
367         if (count == 0)
368             return FALSE;
369         part->nIDMin = llTypes[type].wMaxId;
370         llTypes[type].wMaxId += count;
371         part->nIDMax = llTypes[type].wMaxId;
372     }
373     TRACE("Setting min=%d max=%d (ttop=%d) for (%s:%s)\n",
374           part->nIDMin, part->nIDMax, llTypes[type].wMaxId,
375           lpDrv->drvname, llTypes[type].typestr);
376     /* realloc translation table */
377     if (llTypes[type].lpMlds)
378         llTypes[type].lpMlds = (LPWINE_MLD)
379         HeapReAlloc(GetProcessHeap(), 0, llTypes[type].lpMlds - 1,
380                     sizeof(WINE_MLD) * (llTypes[type].wMaxId + 1)) + 1;
381     else
382         llTypes[type].lpMlds = (LPWINE_MLD)
383         HeapAlloc(GetProcessHeap(), 0,
384                     sizeof(WINE_MLD) * (llTypes[type].wMaxId + 1)) + 1;
385
386     /* re-build the translation table */
387     if (lpDrv->bIsMapper) {
388         TRACE("%s:Trans[%d] -> %s\n", llTypes[type].typestr, -1, MMDrvs[llTypes[type].nMapper].drvname);
389         llTypes[type].lpMlds[-1].uDeviceID = (UINT)-1;
390         llTypes[type].lpMlds[-1].type = type;
391         llTypes[type].lpMlds[-1].mmdIndex = llTypes[type].nMapper;
392         llTypes[type].lpMlds[-1].dwDriverInstance = 0;
393     }
394     for (i = k = 0; i <= MMDrvsHi; i++) {
395         while (MMDrvs[i].parts[type].nIDMin <= k && k < MMDrvs[i].parts[type].nIDMax) {
396             TRACE("%s:Trans[%d] -> %s\n", llTypes[type].typestr, k, MMDrvs[i].drvname);
397             llTypes[type].lpMlds[k].uDeviceID = k;
398             llTypes[type].lpMlds[k].type = type;
399             llTypes[type].lpMlds[k].mmdIndex = i;
400             llTypes[type].lpMlds[k].dwDriverInstance = 0;
401             k++;
402         }
403     }
404     return TRUE;
405 }
406
407 /**************************************************************************
408  *                              MMDRV_Install                   [internal]
409  */
410 static  BOOL    MMDRV_Install(LPCSTR drvRegName, LPCSTR drvFileName, BOOL bIsMapper)
411 {
412     int                 i, count = 0;
413     LPWINE_MM_DRIVER    lpDrv = &MMDrvs[MMDrvsHi];
414     LPWINE_DRIVER       d;
415     WINEMM_msgFunc32    func;
416
417     TRACE("('%s', '%s', mapper=%c);\n", drvRegName, drvFileName, bIsMapper ? 'Y' : 'N');
418
419     for (i = 0; i < MMDrvsHi; i++) {
420         if (!strcmp(drvRegName, MMDrvs[i].drvname)) return FALSE;
421     }
422
423     /* Be sure that size of MMDrvs matches the max number of loadable
424      * drivers !!
425      * If not just increase size of MMDrvs
426      */
427     assert(MMDrvsHi <= sizeof(MMDrvs)/sizeof(MMDrvs[0]));
428
429     memset(lpDrv, 0, sizeof(*lpDrv));
430
431     if (!(lpDrv->hDriver = OpenDriverA(drvFileName, 0, 0))) {
432         WARN("Couldn't open driver '%s'\n", drvFileName);
433         return FALSE;
434     }
435
436     d = DRIVER_FindFromHDrvr(lpDrv->hDriver);
437
438     /* Then look for xxxMessage functions */
439 #define AA(_h,_w,_x,_y,_z)                                      \
440     func = (WINEMM_msgFunc##_y) _z ((_h), #_x);                 \
441     if (func != NULL)                                           \
442         { lpDrv->parts[_w].fnMessage##_y = func; count++;       \
443           TRACE("Got %d bit func '%s'\n", _y, #_x);         }
444
445     if (d->hModule) {
446 #define A(_x,_y)        AA(d->hModule,_x,_y,32,GetProcAddress)
447             A(MMDRV_AUX,        auxMessage);
448             A(MMDRV_MIXER,      mxdMessage);
449             A(MMDRV_MIDIIN,     midMessage);
450             A(MMDRV_MIDIOUT,    modMessage);
451             A(MMDRV_WAVEIN,     widMessage);
452             A(MMDRV_WAVEOUT,    wodMessage);
453 #undef A
454     }
455 #undef AA
456
457     if (!count) {
458         CloseDriver(lpDrv->hDriver, 0, 0);
459         WARN("No message functions found\n");
460         return FALSE;
461     }
462
463     /* FIXME: being a mapper or not should be known by another way */
464     /* it's known for NE drvs (the description is of the form '*mapper: *'
465      * I don't have any clue for PE drvs
466      */
467     lpDrv->bIsMapper = bIsMapper;
468     lpDrv->drvname = strcpy(HeapAlloc(GetProcessHeap(), 0, strlen(drvRegName) + 1), drvRegName);
469
470     /* Finish init and get the count of the devices */
471     i = 0;
472     if (MMDRV_InitPerType(lpDrv, MMDRV_AUX,     AUXDM_GETNUMDEVS))      i = 1;
473     if (MMDRV_InitPerType(lpDrv, MMDRV_MIXER,   MXDM_GETNUMDEVS))       i = 1;
474     if (MMDRV_InitPerType(lpDrv, MMDRV_MIDIIN,  MIDM_GETNUMDEVS))       i = 1;
475     if (MMDRV_InitPerType(lpDrv, MMDRV_MIDIOUT, MODM_GETNUMDEVS))       i = 1;
476     if (MMDRV_InitPerType(lpDrv, MMDRV_WAVEIN,  WIDM_GETNUMDEVS))       i = 1;
477     if (MMDRV_InitPerType(lpDrv, MMDRV_WAVEOUT, WODM_GETNUMDEVS))       i = 1;
478     /* if all those func calls return FALSE, then the driver must be unloaded */
479     if (!i) {
480         CloseDriver(lpDrv->hDriver, 0, 0);
481         HeapFree(GetProcessHeap(), 0, lpDrv->drvname);
482         WARN("Driver initialization failed\n");
483         return FALSE;
484     }
485
486     MMDrvsHi++;
487
488     return TRUE;
489 }
490
491 /**************************************************************************
492  *                              MMDRV_Init
493  */
494 static void MMDRV_Init(void)
495 {
496     IMMDeviceEnumerator *devenum;
497     IMMDevice *device;
498     IPropertyStore *ps;
499     PROPVARIANT pv;
500     DWORD size;
501     char *drvA;
502     HRESULT init_hr, hr;
503
504     static const WCHAR wine_info_deviceW[] = {'W','i','n','e',' ',
505         'i','n','f','o',' ','d','e','v','i','c','e',0};
506
507     TRACE("()\n");
508
509     init_hr = CoInitialize(NULL);
510
511     hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL,
512             CLSCTX_INPROC_SERVER, &IID_IMMDeviceEnumerator, (void**)&devenum);
513     if(FAILED(hr)){
514         ERR("CoCreateInstance failed: %08x\n", hr);
515         goto exit;
516     }
517
518     hr = IMMDeviceEnumerator_GetDevice(devenum, wine_info_deviceW, &device);
519     IMMDeviceEnumerator_Release(devenum);
520     if(FAILED(hr)){
521         ERR("GetDevice failed: %08x\n", hr);
522         goto exit;
523     }
524
525     hr = IMMDevice_OpenPropertyStore(device, STGM_READ, &ps);
526     if(FAILED(hr)){
527         ERR("OpenPropertyStore failed: %08x\n", hr);
528         IMMDevice_Release(device);
529         goto exit;
530     }
531
532     hr = IPropertyStore_GetValue(ps,
533             (const PROPERTYKEY *)&DEVPKEY_Device_Driver, &pv);
534     IPropertyStore_Release(ps);
535     IMMDevice_Release(device);
536     if(FAILED(hr)){
537         ERR("GetValue failed: %08x\n", hr);
538         goto exit;
539     }
540
541     size = WideCharToMultiByte(CP_ACP, 0, pv.u.pwszVal, -1,
542             NULL, 0, NULL, NULL);
543     drvA = HeapAlloc(GetProcessHeap(), 0, size);
544     WideCharToMultiByte(CP_ACP, 0, pv.u.pwszVal, -1, drvA, size, NULL, NULL);
545
546     MMDRV_Install(drvA, drvA, FALSE);
547
548     HeapFree(GetProcessHeap(), 0, drvA);
549     PropVariantClear(&pv);
550
551     MMDRV_Install("wavemapper", "msacm32.drv", TRUE);
552     MMDRV_Install("midimapper", "midimap.dll", TRUE);
553
554 exit:
555     if(SUCCEEDED(init_hr))
556         CoUninitialize();
557 }
558
559 /******************************************************************
560  *              ExitPerType
561  *
562  *
563  */
564 static  BOOL    MMDRV_ExitPerType(LPWINE_MM_DRIVER lpDrv, UINT type)
565 {
566     WINE_MM_DRIVER_PART*        part = &lpDrv->parts[type];
567     DWORD                       ret;
568     TRACE("(%p, %04x)\n", lpDrv, type);
569
570     if (part->fnMessage32) {
571 #if 0
572         ret = part->fnMessage32(0, DRVM_DISABLE, 0L, 0L, 0L);
573         TRACE("DRVM_DISABLE => %08lx\n", ret);
574 #endif
575         ret = part->fnMessage32(0, DRVM_EXIT, 0L, 0L, 0L);
576         TRACE("DRVM_EXIT => %s\n", WINMM_ErrorToString(ret));
577     }
578
579     return TRUE;
580 }
581
582 /******************************************************************
583  *              Exit
584  *
585  *
586  */
587 void MMDRV_Exit(void)
588 {
589     unsigned int i;
590     TRACE("()\n");
591
592     for (i = 0; i < sizeof(MM_MLDrvs) / sizeof(MM_MLDrvs[0]); i++)
593     {
594         if (MM_MLDrvs[i] != NULL)
595         {
596             FIXME("Closing while ll-driver open\n");
597 #if 0
598             /* FIXME: should generate a message depending on type */
599             MMDRV_Free((HANDLE)(i | 0x8000), MM_MLDrvs[i]);
600 #endif
601         }
602     }
603
604     /* unload driver, in reverse order of loading */
605     i = sizeof(MMDrvs) / sizeof(MMDrvs[0]);
606     while (i-- > 0)
607     {
608         MMDRV_ExitPerType(&MMDrvs[i], MMDRV_AUX);
609         MMDRV_ExitPerType(&MMDrvs[i], MMDRV_MIXER);
610         MMDRV_ExitPerType(&MMDrvs[i], MMDRV_MIDIIN);
611         MMDRV_ExitPerType(&MMDrvs[i], MMDRV_MIDIOUT);
612         MMDRV_ExitPerType(&MMDrvs[i], MMDRV_WAVEIN);
613         MMDRV_ExitPerType(&MMDrvs[i], MMDRV_WAVEOUT);
614         CloseDriver(MMDrvs[i].hDriver, 0, 0);
615     }
616     if (llTypes[MMDRV_AUX].lpMlds)
617         HeapFree(GetProcessHeap(), 0, llTypes[MMDRV_AUX].lpMlds - 1);
618     if (llTypes[MMDRV_MIXER].lpMlds)
619         HeapFree(GetProcessHeap(), 0, llTypes[MMDRV_MIXER].lpMlds - 1);
620     if (llTypes[MMDRV_MIDIIN].lpMlds)
621         HeapFree(GetProcessHeap(), 0, llTypes[MMDRV_MIDIIN].lpMlds - 1);
622     if (llTypes[MMDRV_MIDIOUT].lpMlds)
623         HeapFree(GetProcessHeap(), 0, llTypes[MMDRV_MIDIOUT].lpMlds - 1);
624     if (llTypes[MMDRV_WAVEIN].lpMlds)
625         HeapFree(GetProcessHeap(), 0, llTypes[MMDRV_WAVEIN].lpMlds - 1);
626     if (llTypes[MMDRV_WAVEOUT].lpMlds)
627         HeapFree(GetProcessHeap(), 0, llTypes[MMDRV_WAVEOUT].lpMlds - 1);
628 }