Sync with trunk r58687.
[reactos.git] / dll / win32 / msacm32 / internal.c
1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
2
3 /*
4 * MSACM32 library
5 *
6 * Copyright 1998 Patrik Stridvall
7 * 1999 Eric Pouech
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24 #define WIN32_NO_STATUS
25
26 #include <stdarg.h>
27 //#include <string.h>
28
29 #include <windef.h>
30 //#include "winbase.h"
31 #include <wingdi.h>
32 #include <winuser.h>
33 //#include "winerror.h"
34 #include <winreg.h>
35 //#include "mmsystem.h"
36 //#include "mmreg.h"
37 //#include "msacm.h"
38 #include <msacmdrv.h>
39 #include "wineacm.h"
40 #include <wine/debug.h>
41 #include <wine/unicode.h>
42
43 WINE_DEFAULT_DEBUG_CHANNEL(msacm);
44
45 /**********************************************************************/
46
47 HANDLE MSACM_hHeap = NULL;
48 PWINE_ACMDRIVERID MSACM_pFirstACMDriverID = NULL;
49 static PWINE_ACMDRIVERID MSACM_pLastACMDriverID;
50
51 static DWORD MSACM_suspendBroadcastCount = 0;
52 static BOOL MSACM_pendingBroadcast = FALSE;
53 static PWINE_ACMNOTIFYWND MSACM_pFirstACMNotifyWnd = NULL;
54 static PWINE_ACMNOTIFYWND MSACM_pLastACMNotifyWnd = NULL;
55
56 static void MSACM_ReorderDriversByPriority(void);
57
58 /***********************************************************************
59 * MSACM_RegisterDriverFromRegistry()
60 */
61 PWINE_ACMDRIVERID MSACM_RegisterDriverFromRegistry(LPCWSTR pszRegEntry)
62 {
63 static const WCHAR msacmW[] = {'M','S','A','C','M','.'};
64 static const WCHAR drvkey[] = {'S','o','f','t','w','a','r','e','\\',
65 'M','i','c','r','o','s','o','f','t','\\',
66 'W','i','n','d','o','w','s',' ','N','T','\\',
67 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
68 'D','r','i','v','e','r','s','3','2','\0'};
69 WCHAR buf[2048];
70 DWORD bufLen, lRet;
71 HKEY hKey;
72 PWINE_ACMDRIVERID padid = NULL;
73
74 /* The requested registry entry must have the format msacm.XXXXX in order to
75 be recognized in any future sessions of msacm
76 */
77 if (0 == strncmpiW(pszRegEntry, msacmW, sizeof(msacmW)/sizeof(WCHAR))) {
78 lRet = RegOpenKeyExW(HKEY_LOCAL_MACHINE, drvkey, 0, KEY_QUERY_VALUE, &hKey);
79 if (lRet != ERROR_SUCCESS) {
80 WARN("unable to open registry key - 0x%08x\n", lRet);
81 } else {
82 bufLen = sizeof(buf);
83 lRet = RegQueryValueExW(hKey, pszRegEntry, NULL, NULL, (LPBYTE)buf, &bufLen);
84 if (lRet != ERROR_SUCCESS) {
85 WARN("unable to query requested subkey %s - 0x%08x\n", debugstr_w(pszRegEntry), lRet);
86 } else {
87 MSACM_RegisterDriver(pszRegEntry, buf, 0);
88 }
89 RegCloseKey( hKey );
90 }
91 }
92 return padid;
93 }
94
95 #if 0
96 /***********************************************************************
97 * MSACM_DumpCache
98 */
99 static void MSACM_DumpCache(PWINE_ACMDRIVERID padid)
100 {
101 unsigned i;
102
103 TRACE("cFilterTags=%lu cFormatTags=%lu fdwSupport=%08lx\n",
104 padid->cFilterTags, padid->cFormatTags, padid->fdwSupport);
105 for (i = 0; i < padid->cache->cFormatTags; i++) {
106 TRACE("\tdwFormatTag=%lu cbwfx=%lu\n",
107 padid->aFormatTag[i].dwFormatTag, padid->aFormatTag[i].cbwfx);
108 }
109 }
110 #endif
111
112 /***********************************************************************
113 * MSACM_FindFormatTagInCache [internal]
114 *
115 * Returns TRUE is the format tag fmtTag is present in the cache.
116 * If so, idx is set to its index.
117 */
118 BOOL MSACM_FindFormatTagInCache(const WINE_ACMDRIVERID* padid, DWORD fmtTag, LPDWORD idx)
119 {
120 unsigned i;
121
122 for (i = 0; i < padid->cFormatTags; i++) {
123 if (padid->aFormatTag[i].dwFormatTag == fmtTag) {
124 if (idx) *idx = i;
125 return TRUE;
126 }
127 }
128 return FALSE;
129 }
130
131 /***********************************************************************
132 * MSACM_FillCache
133 */
134 static BOOL MSACM_FillCache(PWINE_ACMDRIVERID padid)
135 {
136 HACMDRIVER had = 0;
137 unsigned int ntag;
138 ACMDRIVERDETAILSW add;
139 ACMFORMATTAGDETAILSW aftd;
140
141 if (acmDriverOpen(&had, (HACMDRIVERID)padid, 0) != 0)
142 return FALSE;
143
144 padid->aFormatTag = NULL;
145 add.cbStruct = sizeof(add);
146 if (MSACM_Message(had, ACMDM_DRIVER_DETAILS, (LPARAM)&add, 0))
147 goto errCleanUp;
148
149 if (add.cFormatTags > 0) {
150 padid->aFormatTag = HeapAlloc(MSACM_hHeap, HEAP_ZERO_MEMORY,
151 add.cFormatTags * sizeof(padid->aFormatTag[0]));
152 if (!padid->aFormatTag) goto errCleanUp;
153 }
154
155 padid->cFormatTags = add.cFormatTags;
156 padid->cFilterTags = add.cFilterTags;
157 padid->fdwSupport = add.fdwSupport;
158
159 aftd.cbStruct = sizeof(aftd);
160
161 for (ntag = 0; ntag < add.cFormatTags; ntag++) {
162 aftd.dwFormatTagIndex = ntag;
163 if (MSACM_Message(had, ACMDM_FORMATTAG_DETAILS, (LPARAM)&aftd, ACM_FORMATTAGDETAILSF_INDEX)) {
164 TRACE("IIOs (%s)\n", debugstr_w(padid->pszDriverAlias));
165 goto errCleanUp;
166 }
167 padid->aFormatTag[ntag].dwFormatTag = aftd.dwFormatTag;
168 padid->aFormatTag[ntag].cbwfx = aftd.cbFormatSize;
169 }
170
171 acmDriverClose(had, 0);
172
173 return TRUE;
174
175 errCleanUp:
176 if (had) acmDriverClose(had, 0);
177 HeapFree(MSACM_hHeap, 0, padid->aFormatTag);
178 padid->aFormatTag = NULL;
179 return FALSE;
180 }
181
182 /***********************************************************************
183 * MSACM_GetRegistryKey
184 */
185 static LPWSTR MSACM_GetRegistryKey(const WINE_ACMDRIVERID* padid)
186 {
187 static const WCHAR baseKey[] = {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
188 'A','u','d','i','o','C','o','m','p','r','e','s','s','i','o','n','M','a','n','a','g','e','r','\\',
189 'D','r','i','v','e','r','C','a','c','h','e','\\','\0'};
190 LPWSTR ret;
191 int len;
192
193 if (!padid->pszDriverAlias) {
194 ERR("No alias needed for registry entry\n");
195 return NULL;
196 }
197 len = strlenW(baseKey);
198 ret = HeapAlloc(MSACM_hHeap, 0, (len + strlenW(padid->pszDriverAlias) + 1) * sizeof(WCHAR));
199 if (!ret) return NULL;
200
201 strcpyW(ret, baseKey);
202 strcpyW(ret + len, padid->pszDriverAlias);
203 CharLowerW(ret + len);
204 return ret;
205 }
206
207 /***********************************************************************
208 * MSACM_ReadCache
209 */
210 static BOOL MSACM_ReadCache(PWINE_ACMDRIVERID padid)
211 {
212 LPWSTR key = MSACM_GetRegistryKey(padid);
213 HKEY hKey;
214 DWORD type, size;
215
216 if (!key) return FALSE;
217
218 padid->aFormatTag = NULL;
219
220 if (RegCreateKeyW(HKEY_LOCAL_MACHINE, key, &hKey))
221 goto errCleanUp;
222
223 size = sizeof(padid->cFormatTags);
224 if (RegQueryValueExA(hKey, "cFormatTags", 0, &type, (void*)&padid->cFormatTags, &size))
225 goto errCleanUp;
226 size = sizeof(padid->cFilterTags);
227 if (RegQueryValueExA(hKey, "cFilterTags", 0, &type, (void*)&padid->cFilterTags, &size))
228 goto errCleanUp;
229 size = sizeof(padid->fdwSupport);
230 if (RegQueryValueExA(hKey, "fdwSupport", 0, &type, (void*)&padid->fdwSupport, &size))
231 goto errCleanUp;
232
233 if (padid->cFormatTags > 0) {
234 size = padid->cFormatTags * sizeof(padid->aFormatTag[0]);
235 padid->aFormatTag = HeapAlloc(MSACM_hHeap, HEAP_ZERO_MEMORY, size);
236 if (!padid->aFormatTag) goto errCleanUp;
237 if (RegQueryValueExA(hKey, "aFormatTagCache", 0, &type, (void*)padid->aFormatTag, &size))
238 goto errCleanUp;
239 }
240 HeapFree(MSACM_hHeap, 0, key);
241 return TRUE;
242
243 errCleanUp:
244 HeapFree(MSACM_hHeap, 0, key);
245 HeapFree(MSACM_hHeap, 0, padid->aFormatTag);
246 padid->aFormatTag = NULL;
247 RegCloseKey(hKey);
248 return FALSE;
249 }
250
251 /***********************************************************************
252 * MSACM_WriteCache
253 */
254 static BOOL MSACM_WriteCache(const WINE_ACMDRIVERID *padid)
255 {
256 LPWSTR key = MSACM_GetRegistryKey(padid);
257 HKEY hKey;
258
259 if (!key) return FALSE;
260
261 if (RegCreateKeyW(HKEY_LOCAL_MACHINE, key, &hKey))
262 goto errCleanUp;
263
264 if (RegSetValueExA(hKey, "cFormatTags", 0, REG_DWORD, (const void*)&padid->cFormatTags, sizeof(DWORD)))
265 goto errCleanUp;
266 if (RegSetValueExA(hKey, "cFilterTags", 0, REG_DWORD, (const void*)&padid->cFilterTags, sizeof(DWORD)))
267 goto errCleanUp;
268 if (RegSetValueExA(hKey, "fdwSupport", 0, REG_DWORD, (const void*)&padid->fdwSupport, sizeof(DWORD)))
269 goto errCleanUp;
270 if (RegSetValueExA(hKey, "aFormatTagCache", 0, REG_BINARY,
271 (void*)padid->aFormatTag,
272 padid->cFormatTags * sizeof(padid->aFormatTag[0])))
273 goto errCleanUp;
274 HeapFree(MSACM_hHeap, 0, key);
275 return TRUE;
276
277 errCleanUp:
278 HeapFree(MSACM_hHeap, 0, key);
279 return FALSE;
280 }
281
282 /***********************************************************************
283 * MSACM_RegisterDriver()
284 */
285 PWINE_ACMDRIVERID MSACM_RegisterDriver(LPCWSTR pszDriverAlias, LPCWSTR pszFileName,
286 PWINE_ACMLOCALDRIVER pLocalDriver)
287 {
288 PWINE_ACMDRIVERID padid;
289
290 TRACE("(%s, %s, %p)\n",
291 debugstr_w(pszDriverAlias), debugstr_w(pszFileName), pLocalDriver);
292
293 padid = HeapAlloc(MSACM_hHeap, 0, sizeof(WINE_ACMDRIVERID));
294 if (!padid)
295 return NULL;
296 padid->obj.dwType = WINE_ACMOBJ_DRIVERID;
297 padid->obj.pACMDriverID = padid;
298 padid->pszDriverAlias = NULL;
299 if (pszDriverAlias)
300 {
301 padid->pszDriverAlias = HeapAlloc( MSACM_hHeap, 0, (strlenW(pszDriverAlias)+1) * sizeof(WCHAR) );
302 if (!padid->pszDriverAlias) {
303 HeapFree(MSACM_hHeap, 0, padid);
304 return NULL;
305 }
306 strcpyW( padid->pszDriverAlias, pszDriverAlias );
307 }
308 padid->pszFileName = NULL;
309 if (pszFileName)
310 {
311 padid->pszFileName = HeapAlloc( MSACM_hHeap, 0, (strlenW(pszFileName)+1) * sizeof(WCHAR) );
312 if (!padid->pszFileName) {
313 HeapFree(MSACM_hHeap, 0, padid->pszDriverAlias);
314 HeapFree(MSACM_hHeap, 0, padid);
315 return NULL;
316 }
317 strcpyW( padid->pszFileName, pszFileName );
318 }
319 padid->pLocalDriver = pLocalDriver;
320
321 padid->pACMDriverList = NULL;
322
323 if (pLocalDriver) {
324 padid->pPrevACMDriverID = NULL;
325 padid->pNextACMDriverID = MSACM_pFirstACMDriverID;
326 if (MSACM_pFirstACMDriverID)
327 MSACM_pFirstACMDriverID->pPrevACMDriverID = padid;
328 MSACM_pFirstACMDriverID = padid;
329 if (!MSACM_pLastACMDriverID)
330 MSACM_pLastACMDriverID = padid;
331 } else {
332 padid->pNextACMDriverID = NULL;
333 padid->pPrevACMDriverID = MSACM_pLastACMDriverID;
334 if (MSACM_pLastACMDriverID)
335 MSACM_pLastACMDriverID->pNextACMDriverID = padid;
336 MSACM_pLastACMDriverID = padid;
337 if (!MSACM_pFirstACMDriverID)
338 MSACM_pFirstACMDriverID = padid;
339 }
340 /* disable the driver if we cannot load the cache */
341 if ((!padid->pszDriverAlias || !MSACM_ReadCache(padid)) && !MSACM_FillCache(padid)) {
342 WARN("Couldn't load cache for ACM driver (%s)\n", debugstr_w(pszFileName));
343 MSACM_UnregisterDriver(padid);
344 return NULL;
345 }
346
347 if (pLocalDriver) padid->fdwSupport |= ACMDRIVERDETAILS_SUPPORTF_LOCAL;
348 return padid;
349 }
350
351 /***********************************************************************
352 * MSACM_RegisterAllDrivers()
353 */
354 void MSACM_RegisterAllDrivers(void)
355 {
356 static const WCHAR msacm32[] = {'m','s','a','c','m','3','2','.','d','l','l','\0'};
357 static const WCHAR msacmW[] = {'M','S','A','C','M','.'};
358 static const WCHAR drv32[] = {'d','r','i','v','e','r','s','3','2','\0'};
359 static const WCHAR sys[] = {'s','y','s','t','e','m','.','i','n','i','\0'};
360 static const WCHAR drvkey[] = {'S','o','f','t','w','a','r','e','\\',
361 'M','i','c','r','o','s','o','f','t','\\',
362 'W','i','n','d','o','w','s',' ','N','T','\\',
363 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
364 'D','r','i','v','e','r','s','3','2','\0'};
365 DWORD i, cnt = 0, bufLen, lRet;
366 WCHAR buf[2048], *name, *s;
367 FILETIME lastWrite;
368 HKEY hKey;
369
370 /* FIXME: What if the user edits system.ini while the program is running?
371 * Does Windows handle that? */
372 if (MSACM_pFirstACMDriverID) return;
373
374 lRet = RegOpenKeyExW(HKEY_LOCAL_MACHINE, drvkey, 0, KEY_QUERY_VALUE, &hKey);
375 if (lRet == ERROR_SUCCESS) {
376 RegQueryInfoKeyW( hKey, 0, 0, 0, &cnt, 0, 0, 0, 0, 0, 0, 0);
377 for (i = 0; i < cnt; i++) {
378 bufLen = sizeof(buf) / sizeof(buf[0]);
379 lRet = RegEnumKeyExW(hKey, i, buf, &bufLen, 0, 0, 0, &lastWrite);
380 if (lRet != ERROR_SUCCESS) continue;
381 if (strncmpiW(buf, msacmW, sizeof(msacmW)/sizeof(msacmW[0]))) continue;
382 if (!(name = strchrW(buf, '='))) continue;
383 *name = 0;
384 MSACM_RegisterDriver(buf, name + 1, 0);
385 }
386 RegCloseKey( hKey );
387 }
388
389 if (GetPrivateProfileSectionW(drv32, buf, sizeof(buf)/sizeof(buf[0]), sys))
390 {
391 for(s = buf; *s; s += strlenW(s) + 1)
392 {
393 if (strncmpiW(s, msacmW, sizeof(msacmW)/sizeof(msacmW[0]))) continue;
394 if (!(name = strchrW(s, '='))) continue;
395 *name = 0;
396 MSACM_RegisterDriver(s, name + 1, 0);
397 *name = '=';
398 }
399 }
400 MSACM_ReorderDriversByPriority();
401 MSACM_RegisterDriver(msacm32, msacm32, 0);
402 }
403
404 /***********************************************************************
405 * MSACM_RegisterNotificationWindow()
406 */
407 PWINE_ACMNOTIFYWND MSACM_RegisterNotificationWindow(HWND hNotifyWnd, DWORD dwNotifyMsg)
408 {
409 PWINE_ACMNOTIFYWND panwnd;
410
411 TRACE("(%p,0x%08x)\n", hNotifyWnd, dwNotifyMsg);
412
413 panwnd = HeapAlloc(MSACM_hHeap, 0, sizeof(WINE_ACMNOTIFYWND));
414 panwnd->obj.dwType = WINE_ACMOBJ_NOTIFYWND;
415 panwnd->obj.pACMDriverID = 0;
416 panwnd->hNotifyWnd = hNotifyWnd;
417 panwnd->dwNotifyMsg = dwNotifyMsg;
418 panwnd->fdwSupport = 0;
419
420 panwnd->pNextACMNotifyWnd = NULL;
421 panwnd->pPrevACMNotifyWnd = MSACM_pLastACMNotifyWnd;
422 if (MSACM_pLastACMNotifyWnd)
423 MSACM_pLastACMNotifyWnd->pNextACMNotifyWnd = panwnd;
424 MSACM_pLastACMNotifyWnd = panwnd;
425 if (!MSACM_pFirstACMNotifyWnd)
426 MSACM_pFirstACMNotifyWnd = panwnd;
427
428 return panwnd;
429 }
430
431 /***********************************************************************
432 * MSACM_BroadcastNotification()
433 */
434 void MSACM_BroadcastNotification(void)
435 {
436 if (MSACM_suspendBroadcastCount <= 0) {
437 PWINE_ACMNOTIFYWND panwnd;
438
439 for (panwnd = MSACM_pFirstACMNotifyWnd; panwnd; panwnd = panwnd->pNextACMNotifyWnd)
440 if (!(panwnd->fdwSupport & ACMDRIVERDETAILS_SUPPORTF_DISABLED))
441 SendMessageW(panwnd->hNotifyWnd, panwnd->dwNotifyMsg, 0, 0);
442 } else {
443 MSACM_pendingBroadcast = TRUE;
444 }
445 }
446
447 /***********************************************************************
448 * MSACM_DisableNotifications()
449 */
450 void MSACM_DisableNotifications(void)
451 {
452 MSACM_suspendBroadcastCount++;
453 }
454
455 /***********************************************************************
456 * MSACM_EnableNotifications()
457 */
458 void MSACM_EnableNotifications(void)
459 {
460 if (MSACM_suspendBroadcastCount > 0) {
461 MSACM_suspendBroadcastCount--;
462 if (MSACM_suspendBroadcastCount == 0 && MSACM_pendingBroadcast) {
463 MSACM_pendingBroadcast = FALSE;
464 MSACM_BroadcastNotification();
465 }
466 }
467 }
468
469 /***********************************************************************
470 * MSACM_UnRegisterNotificationWindow()
471 */
472 PWINE_ACMNOTIFYWND MSACM_UnRegisterNotificationWindow(const WINE_ACMNOTIFYWND *panwnd)
473 {
474 PWINE_ACMNOTIFYWND p;
475
476 for (p = MSACM_pFirstACMNotifyWnd; p; p = p->pNextACMNotifyWnd) {
477 if (p == panwnd) {
478 PWINE_ACMNOTIFYWND pNext = p->pNextACMNotifyWnd;
479
480 if (p->pPrevACMNotifyWnd) p->pPrevACMNotifyWnd->pNextACMNotifyWnd = p->pNextACMNotifyWnd;
481 if (p->pNextACMNotifyWnd) p->pNextACMNotifyWnd->pPrevACMNotifyWnd = p->pPrevACMNotifyWnd;
482 if (MSACM_pFirstACMNotifyWnd == p) MSACM_pFirstACMNotifyWnd = p->pNextACMNotifyWnd;
483 if (MSACM_pLastACMNotifyWnd == p) MSACM_pLastACMNotifyWnd = p->pPrevACMNotifyWnd;
484 HeapFree(MSACM_hHeap, 0, p);
485
486 return pNext;
487 }
488 }
489 return NULL;
490 }
491
492 /***********************************************************************
493 * MSACM_RePositionDriver()
494 */
495 void MSACM_RePositionDriver(PWINE_ACMDRIVERID padid, DWORD dwPriority)
496 {
497 PWINE_ACMDRIVERID pTargetPosition = NULL;
498
499 /* Remove selected driver from linked list */
500 if (MSACM_pFirstACMDriverID == padid) {
501 MSACM_pFirstACMDriverID = padid->pNextACMDriverID;
502 }
503 if (MSACM_pLastACMDriverID == padid) {
504 MSACM_pLastACMDriverID = padid->pPrevACMDriverID;
505 }
506 if (padid->pPrevACMDriverID != NULL) {
507 padid->pPrevACMDriverID->pNextACMDriverID = padid->pNextACMDriverID;
508 }
509 if (padid->pNextACMDriverID != NULL) {
510 padid->pNextACMDriverID->pPrevACMDriverID = padid->pPrevACMDriverID;
511 }
512
513 /* Look up position where selected driver should be */
514 if (dwPriority == 1) {
515 pTargetPosition = padid->pPrevACMDriverID;
516 while (pTargetPosition->pPrevACMDriverID != NULL &&
517 !(pTargetPosition->pPrevACMDriverID->fdwSupport & ACMDRIVERDETAILS_SUPPORTF_LOCAL)) {
518 pTargetPosition = pTargetPosition->pPrevACMDriverID;
519 }
520 } else if (dwPriority == -1) {
521 pTargetPosition = padid->pNextACMDriverID;
522 while (pTargetPosition->pNextACMDriverID != NULL) {
523 pTargetPosition = pTargetPosition->pNextACMDriverID;
524 }
525 }
526
527 /* Place selected driver in selected position */
528 padid->pPrevACMDriverID = pTargetPosition->pPrevACMDriverID;
529 padid->pNextACMDriverID = pTargetPosition;
530 if (padid->pPrevACMDriverID != NULL) {
531 padid->pPrevACMDriverID->pNextACMDriverID = padid;
532 } else {
533 MSACM_pFirstACMDriverID = padid;
534 }
535 if (padid->pNextACMDriverID != NULL) {
536 padid->pNextACMDriverID->pPrevACMDriverID = padid;
537 } else {
538 MSACM_pLastACMDriverID = padid;
539 }
540 }
541
542 /***********************************************************************
543 * MSACM_ReorderDriversByPriority()
544 * Reorders all drivers based on the priority list indicated by the registry key:
545 * HKCU\\Software\\Microsoft\\Multimedia\\Audio Compression Manager\\Priority v4.00
546 */
547 static void MSACM_ReorderDriversByPriority(void)
548 {
549 PWINE_ACMDRIVERID padid;
550 unsigned int iNumDrivers;
551 PWINE_ACMDRIVERID * driverList = NULL;
552 HKEY hPriorityKey = NULL;
553
554 TRACE("\n");
555
556 /* Count drivers && alloc corresponding memory for list */
557 iNumDrivers = 0;
558 for (padid = MSACM_pFirstACMDriverID; padid; padid = padid->pNextACMDriverID) iNumDrivers++;
559 if (iNumDrivers > 1)
560 {
561 LONG lError;
562 static const WCHAR basePriorityKey[] = {
563 'S','o','f','t','w','a','r','e','\\',
564 'M','i','c','r','o','s','o','f','t','\\',
565 'M','u','l','t','i','m','e','d','i','a','\\',
566 'A','u','d','i','o',' ','C','o','m','p','r','e','s','s','i','o','n',' ','M','a','n','a','g','e','r','\\',
567 'P','r','i','o','r','i','t','y',' ','v','4','.','0','0','\0'
568 };
569 unsigned int i;
570 LONG lBufferLength;
571 WCHAR szBuffer[256];
572
573 driverList = HeapAlloc(MSACM_hHeap, 0, iNumDrivers * sizeof(PWINE_ACMDRIVERID));
574 if (!driverList)
575 {
576 ERR("out of memory\n");
577 goto errCleanUp;
578 }
579
580 lError = RegOpenKeyW(HKEY_CURRENT_USER, basePriorityKey, &hPriorityKey);
581 if (lError != ERROR_SUCCESS) {
582 TRACE("RegOpenKeyW failed, possibly key does not exist yet\n");
583 hPriorityKey = NULL;
584 goto errCleanUp;
585 }
586
587 /* Copy drivers into list to simplify linked list modification */
588 for (i = 0, padid = MSACM_pFirstACMDriverID; padid; padid = padid->pNextACMDriverID, i++)
589 {
590 driverList[i] = padid;
591 }
592
593 /* Query each of the priorities in turn. Alias key is in lowercase.
594 The general form of the priority record is the following:
595 "PriorityN" --> "1, msacm.driveralias"
596 where N is an integer, and the value is a string of the driver
597 alias, prefixed by "1, " for an enabled driver, or "0, " for a
598 disabled driver.
599 */
600 for (i = 0; i < iNumDrivers; i++)
601 {
602 static const WCHAR priorityTmpl[] = {'P','r','i','o','r','i','t','y','%','l','d','\0'};
603 WCHAR szSubKey[17];
604 unsigned int iTargetPosition;
605 unsigned int iCurrentPosition;
606 WCHAR * pAlias;
607 static const WCHAR sPrefix[] = {'m','s','a','c','m','.','\0'};
608
609 /* Build expected entry name */
610 snprintfW(szSubKey, 17, priorityTmpl, i + 1);
611 lBufferLength = sizeof(szBuffer);
612 lError = RegQueryValueExW(hPriorityKey, szSubKey, NULL, NULL, (LPBYTE)szBuffer, (LPDWORD)&lBufferLength);
613 if (lError != ERROR_SUCCESS) continue;
614
615 /* Recovered driver alias should be at this position */
616 iTargetPosition = i;
617
618 /* Locate driver alias in driver list */
619 pAlias = strstrW(szBuffer, sPrefix);
620 if (pAlias == NULL) continue;
621
622 for (iCurrentPosition = 0; iCurrentPosition < iNumDrivers; iCurrentPosition++) {
623 if (strcmpiW(driverList[iCurrentPosition]->pszDriverAlias, pAlias) == 0)
624 break;
625 }
626 if (iCurrentPosition < iNumDrivers && iTargetPosition != iCurrentPosition) {
627 padid = driverList[iTargetPosition];
628 driverList[iTargetPosition] = driverList[iCurrentPosition];
629 driverList[iCurrentPosition] = padid;
630
631 /* Locate enabled status */
632 if (szBuffer[0] == '1') {
633 driverList[iTargetPosition]->fdwSupport &= ~ACMDRIVERDETAILS_SUPPORTF_DISABLED;
634 } else if (szBuffer[0] == '0') {
635 driverList[iTargetPosition]->fdwSupport |= ACMDRIVERDETAILS_SUPPORTF_DISABLED;
636 }
637 }
638 }
639
640 /* Re-assign pointers so that linked list traverses the ordered array */
641 for (i = 0; i < iNumDrivers; i++) {
642 driverList[i]->pPrevACMDriverID = (i > 0) ? driverList[i - 1] : NULL;
643 driverList[i]->pNextACMDriverID = (i < iNumDrivers - 1) ? driverList[i + 1] : NULL;
644 }
645 MSACM_pFirstACMDriverID = driverList[0];
646 MSACM_pLastACMDriverID = driverList[iNumDrivers - 1];
647 }
648
649 errCleanUp:
650 if (hPriorityKey != NULL) RegCloseKey(hPriorityKey);
651 HeapFree(MSACM_hHeap, 0, driverList);
652 }
653
654 /***********************************************************************
655 * MSACM_WriteCurrentPriorities()
656 * Writes out current order of driver priorities to registry key:
657 * HKCU\\Software\\Microsoft\\Multimedia\\Audio Compression Manager\\Priority v4.00
658 */
659 void MSACM_WriteCurrentPriorities(void)
660 {
661 LONG lError;
662 HKEY hPriorityKey;
663 static const WCHAR basePriorityKey[] = {
664 'S','o','f','t','w','a','r','e','\\',
665 'M','i','c','r','o','s','o','f','t','\\',
666 'M','u','l','t','i','m','e','d','i','a','\\',
667 'A','u','d','i','o',' ','C','o','m','p','r','e','s','s','i','o','n',' ','M','a','n','a','g','e','r','\\',
668 'P','r','i','o','r','i','t','y',' ','v','4','.','0','0','\0'
669 };
670 PWINE_ACMDRIVERID padid;
671 DWORD dwPriorityCounter;
672 static const WCHAR priorityTmpl[] = {'P','r','i','o','r','i','t','y','%','l','d','\0'};
673 static const WCHAR valueTmpl[] = {'%','c',',',' ','%','s','\0'};
674 static const WCHAR converterAlias[] = {'I','n','t','e','r','n','a','l',' ','P','C','M',' ','C','o','n','v','e','r','t','e','r','\0'};
675 WCHAR szSubKey[17];
676 WCHAR szBuffer[256];
677
678 /* Delete ACM priority key and create it anew */
679 lError = RegDeleteKeyW(HKEY_CURRENT_USER, basePriorityKey);
680 if (lError != ERROR_SUCCESS && lError != ERROR_FILE_NOT_FOUND) {
681 ERR("unable to remove current key %s (0x%08x) - priority changes won't persist past application end.\n",
682 debugstr_w(basePriorityKey), lError);
683 return;
684 }
685 lError = RegCreateKeyW(HKEY_CURRENT_USER, basePriorityKey, &hPriorityKey);
686 if (lError != ERROR_SUCCESS) {
687 ERR("unable to create key %s (0x%08x) - priority changes won't persist past application end.\n",
688 debugstr_w(basePriorityKey), lError);
689 return;
690 }
691
692 /* Write current list of priorities */
693 for (dwPriorityCounter = 0, padid = MSACM_pFirstACMDriverID; padid; padid = padid->pNextACMDriverID) {
694 if (padid->fdwSupport & ACMDRIVERDETAILS_SUPPORTF_LOCAL) continue;
695 if (padid->pszDriverAlias == NULL) continue; /* internal PCM converter is last */
696
697 /* Build required value name */
698 dwPriorityCounter++;
699 snprintfW(szSubKey, 17, priorityTmpl, dwPriorityCounter);
700
701 /* Value has a 1 in front for enabled drivers and 0 for disabled drivers */
702 snprintfW(szBuffer, 256, valueTmpl, (padid->fdwSupport & ACMDRIVERDETAILS_SUPPORTF_DISABLED) ? '0' : '1', padid->pszDriverAlias);
703 strlwrW(szBuffer);
704
705 lError = RegSetValueExW(hPriorityKey, szSubKey, 0, REG_SZ, (BYTE *)szBuffer, (strlenW(szBuffer) + 1) * sizeof(WCHAR));
706 if (lError != ERROR_SUCCESS) {
707 ERR("unable to write value for %s under key %s (0x%08x)\n",
708 debugstr_w(padid->pszDriverAlias), debugstr_w(basePriorityKey), lError);
709 }
710 }
711
712 /* Build required value name */
713 dwPriorityCounter++;
714 snprintfW(szSubKey, 17, priorityTmpl, dwPriorityCounter);
715
716 /* Value has a 1 in front for enabled drivers and 0 for disabled drivers */
717 snprintfW(szBuffer, 256, valueTmpl, '1', converterAlias);
718
719 lError = RegSetValueExW(hPriorityKey, szSubKey, 0, REG_SZ, (BYTE *)szBuffer, (strlenW(szBuffer) + 1) * sizeof(WCHAR));
720 if (lError != ERROR_SUCCESS) {
721 ERR("unable to write value for %s under key %s (0x%08x)\n",
722 debugstr_w(converterAlias), debugstr_w(basePriorityKey), lError);
723 }
724 RegCloseKey(hPriorityKey);
725 }
726
727 static PWINE_ACMLOCALDRIVER MSACM_pFirstACMLocalDriver;
728 static PWINE_ACMLOCALDRIVER MSACM_pLastACMLocalDriver;
729
730 static PWINE_ACMLOCALDRIVER MSACM_UnregisterLocalDriver(PWINE_ACMLOCALDRIVER paldrv)
731 {
732 PWINE_ACMLOCALDRIVER pNextACMLocalDriver;
733
734 if (paldrv->pACMInstList) {
735 ERR("local driver instances still present after closing all drivers - memory leak\n");
736 return NULL;
737 }
738
739 if (paldrv == MSACM_pFirstACMLocalDriver)
740 MSACM_pFirstACMLocalDriver = paldrv->pNextACMLocalDrv;
741 if (paldrv == MSACM_pLastACMLocalDriver)
742 MSACM_pLastACMLocalDriver = paldrv->pPrevACMLocalDrv;
743
744 if (paldrv->pPrevACMLocalDrv)
745 paldrv->pPrevACMLocalDrv->pNextACMLocalDrv = paldrv->pNextACMLocalDrv;
746 if (paldrv->pNextACMLocalDrv)
747 paldrv->pNextACMLocalDrv->pPrevACMLocalDrv = paldrv->pPrevACMLocalDrv;
748
749 pNextACMLocalDriver = paldrv->pNextACMLocalDrv;
750
751 HeapFree(MSACM_hHeap, 0, paldrv);
752
753 return pNextACMLocalDriver;
754 }
755
756 /***********************************************************************
757 * MSACM_UnregisterDriver()
758 */
759 PWINE_ACMDRIVERID MSACM_UnregisterDriver(PWINE_ACMDRIVERID p)
760 {
761 PWINE_ACMDRIVERID pNextACMDriverID;
762
763 while (p->pACMDriverList)
764 acmDriverClose((HACMDRIVER) p->pACMDriverList, 0);
765
766 HeapFree(MSACM_hHeap, 0, p->pszDriverAlias);
767 HeapFree(MSACM_hHeap, 0, p->pszFileName);
768 HeapFree(MSACM_hHeap, 0, p->aFormatTag);
769
770 if (p == MSACM_pFirstACMDriverID)
771 MSACM_pFirstACMDriverID = p->pNextACMDriverID;
772 if (p == MSACM_pLastACMDriverID)
773 MSACM_pLastACMDriverID = p->pPrevACMDriverID;
774
775 if (p->pPrevACMDriverID)
776 p->pPrevACMDriverID->pNextACMDriverID = p->pNextACMDriverID;
777 if (p->pNextACMDriverID)
778 p->pNextACMDriverID->pPrevACMDriverID = p->pPrevACMDriverID;
779
780 pNextACMDriverID = p->pNextACMDriverID;
781
782 if (p->pLocalDriver) MSACM_UnregisterLocalDriver(p->pLocalDriver);
783 HeapFree(MSACM_hHeap, 0, p);
784
785 return pNextACMDriverID;
786 }
787
788 /***********************************************************************
789 * MSACM_UnregisterAllDrivers()
790 */
791 void MSACM_UnregisterAllDrivers(void)
792 {
793 PWINE_ACMNOTIFYWND panwnd = MSACM_pFirstACMNotifyWnd;
794 PWINE_ACMDRIVERID p = MSACM_pFirstACMDriverID;
795
796 while (p) {
797 MSACM_WriteCache(p);
798 p = MSACM_UnregisterDriver(p);
799 }
800
801 while (panwnd) {
802 panwnd = MSACM_UnRegisterNotificationWindow(panwnd);
803 }
804 }
805
806 /***********************************************************************
807 * MSACM_GetObj()
808 */
809 PWINE_ACMOBJ MSACM_GetObj(HACMOBJ hObj, DWORD type)
810 {
811 PWINE_ACMOBJ pao = (PWINE_ACMOBJ)hObj;
812
813 if (pao == NULL || IsBadReadPtr(pao, sizeof(WINE_ACMOBJ)) ||
814 ((type != WINE_ACMOBJ_DONTCARE) && (type != pao->dwType)))
815 return NULL;
816 return pao;
817 }
818
819 /***********************************************************************
820 * MSACM_GetDriverID()
821 */
822 PWINE_ACMDRIVERID MSACM_GetDriverID(HACMDRIVERID hDriverID)
823 {
824 return (PWINE_ACMDRIVERID)MSACM_GetObj((HACMOBJ)hDriverID, WINE_ACMOBJ_DRIVERID);
825 }
826
827 /***********************************************************************
828 * MSACM_GetDriver()
829 */
830 PWINE_ACMDRIVER MSACM_GetDriver(HACMDRIVER hDriver)
831 {
832 return (PWINE_ACMDRIVER)MSACM_GetObj((HACMOBJ)hDriver, WINE_ACMOBJ_DRIVER);
833 }
834
835 /***********************************************************************
836 * MSACM_GetNotifyWnd()
837 */
838 PWINE_ACMNOTIFYWND MSACM_GetNotifyWnd(HACMDRIVERID hDriver)
839 {
840 return (PWINE_ACMNOTIFYWND)MSACM_GetObj((HACMOBJ)hDriver, WINE_ACMOBJ_NOTIFYWND);
841 }
842
843 /***********************************************************************
844 * MSACM_GetLocalDriver()
845 */
846 /*
847 PWINE_ACMLOCALDRIVER MSACM_GetLocalDriver(HACMDRIVER hDriver)
848 {
849 return (PWINE_ACMLOCALDRIVER)MSACM_GetObj((HACMOBJ)hDriver, WINE_ACMOBJ_LOCALDRIVER);
850 }
851 */
852 #define MSACM_DRIVER_SendMessage(PDRVRINST, msg, lParam1, lParam2) \
853 (PDRVRINST)->pLocalDriver->lpDrvProc((PDRVRINST)->dwDriverID, (HDRVR)(PDRVRINST), msg, lParam1, lParam2)
854
855 /***********************************************************************
856 * MSACM_Message()
857 */
858 MMRESULT MSACM_Message(HACMDRIVER had, UINT uMsg, LPARAM lParam1, LPARAM lParam2)
859 {
860 PWINE_ACMDRIVER pad = MSACM_GetDriver(had);
861
862 if (!pad) return MMSYSERR_INVALHANDLE;
863 if (pad->hDrvr) return SendDriverMessage(pad->hDrvr, uMsg, lParam1, lParam2);
864 if (pad->pLocalDrvrInst) return MSACM_DRIVER_SendMessage(pad->pLocalDrvrInst, uMsg, lParam1, lParam2);
865
866 return MMSYSERR_INVALHANDLE;
867 }
868
869 PWINE_ACMLOCALDRIVER MSACM_RegisterLocalDriver(HMODULE hModule, DRIVERPROC lpDriverProc)
870 {
871 PWINE_ACMLOCALDRIVER paldrv;
872
873 TRACE("(%p, %p)\n", hModule, lpDriverProc);
874 if (!hModule || !lpDriverProc) return NULL;
875
876 /* look up previous instance of local driver module */
877 for (paldrv = MSACM_pFirstACMLocalDriver; paldrv; paldrv = paldrv->pNextACMLocalDrv)
878 {
879 if (paldrv->hModule == hModule && paldrv->lpDrvProc == lpDriverProc) return paldrv;
880 }
881
882 paldrv = HeapAlloc(MSACM_hHeap, 0, sizeof(WINE_ACMLOCALDRIVER));
883 paldrv->obj.dwType = WINE_ACMOBJ_LOCALDRIVER;
884 paldrv->obj.pACMDriverID = 0;
885 paldrv->hModule = hModule;
886 paldrv->lpDrvProc = lpDriverProc;
887 paldrv->pACMInstList = NULL;
888
889 paldrv->pNextACMLocalDrv = NULL;
890 paldrv->pPrevACMLocalDrv = MSACM_pLastACMLocalDriver;
891 if (MSACM_pLastACMLocalDriver)
892 MSACM_pLastACMLocalDriver->pNextACMLocalDrv = paldrv;
893 MSACM_pLastACMLocalDriver = paldrv;
894 if (!MSACM_pFirstACMLocalDriver)
895 MSACM_pFirstACMLocalDriver = paldrv;
896
897 return paldrv;
898 }
899
900 /**************************************************************************
901 * MSACM_GetNumberOfModuleRefs [internal]
902 *
903 * Returns the number of open drivers which share the same module.
904 * Inspired from implementation in dlls/winmm/driver.c
905 */
906 static unsigned MSACM_GetNumberOfModuleRefs(HMODULE hModule, DRIVERPROC lpDrvProc, WINE_ACMLOCALDRIVERINST ** found)
907 {
908 PWINE_ACMLOCALDRIVER lpDrv;
909 unsigned count = 0;
910
911 if (found) *found = NULL;
912 for (lpDrv = MSACM_pFirstACMLocalDriver; lpDrv; lpDrv = lpDrv->pNextACMLocalDrv)
913 {
914 if (lpDrv->hModule == hModule && lpDrv->lpDrvProc == lpDrvProc)
915 {
916 PWINE_ACMLOCALDRIVERINST pInst = lpDrv->pACMInstList;
917
918 while (pInst) {
919 if (found && !*found) *found = pInst;
920 count++;
921 pInst = pInst->pNextACMInst;
922 }
923 }
924 }
925 return count;
926 }
927
928 /**************************************************************************
929 * MSACM_RemoveFromList [internal]
930 *
931 * Generates all the logic to handle driver closure / deletion
932 * Removes a driver struct to the list of open drivers.
933 */
934 static BOOL MSACM_RemoveFromList(PWINE_ACMLOCALDRIVERINST lpDrv)
935 {
936 PWINE_ACMLOCALDRIVER pDriverBase = lpDrv->pLocalDriver;
937 PWINE_ACMLOCALDRIVERINST pPrevInst;
938
939 /* last of this driver in list ? */
940 if (MSACM_GetNumberOfModuleRefs(pDriverBase->hModule, pDriverBase->lpDrvProc, NULL) == 1) {
941 MSACM_DRIVER_SendMessage(lpDrv, DRV_DISABLE, 0L, 0L);
942 MSACM_DRIVER_SendMessage(lpDrv, DRV_FREE, 0L, 0L);
943 }
944
945 pPrevInst = NULL;
946 if (pDriverBase->pACMInstList != lpDrv) {
947 pPrevInst = pDriverBase->pACMInstList;
948 while (pPrevInst && pPrevInst->pNextACMInst != lpDrv)
949 pPrevInst = pPrevInst->pNextACMInst;
950 if (!pPrevInst) {
951 ERR("requested to remove invalid instance %p\n", pPrevInst);
952 return FALSE;
953 }
954 }
955 if (!pPrevInst) {
956 /* first driver instance on list */
957 pDriverBase->pACMInstList = lpDrv->pNextACMInst;
958 } else {
959 pPrevInst->pNextACMInst = lpDrv->pNextACMInst;
960 }
961 return TRUE;
962 }
963
964 /**************************************************************************
965 * MSACM_AddToList [internal]
966 *
967 * Adds a driver struct to the list of open drivers.
968 * Generates all the logic to handle driver creation / open.
969 */
970 static BOOL MSACM_AddToList(PWINE_ACMLOCALDRIVERINST lpNewDrv, LPARAM lParam2)
971 {
972 PWINE_ACMLOCALDRIVER pDriverBase = lpNewDrv->pLocalDriver;
973
974 /* first of this driver in list ? */
975 if (MSACM_GetNumberOfModuleRefs(pDriverBase->hModule, pDriverBase->lpDrvProc, NULL) == 0) {
976 if (MSACM_DRIVER_SendMessage(lpNewDrv, DRV_LOAD, 0L, 0L) != DRV_SUCCESS) {
977 FIXME("DRV_LOAD failed on driver %p\n", lpNewDrv);
978 return FALSE;
979 }
980 /* returned value is not checked */
981 MSACM_DRIVER_SendMessage(lpNewDrv, DRV_ENABLE, 0L, 0L);
982 }
983
984 lpNewDrv->pNextACMInst = NULL;
985 if (pDriverBase->pACMInstList == NULL) {
986 pDriverBase->pACMInstList = lpNewDrv;
987 } else {
988 PWINE_ACMLOCALDRIVERINST lpDrvInst = pDriverBase->pACMInstList;
989
990 while (lpDrvInst->pNextACMInst != NULL)
991 lpDrvInst = lpDrvInst->pNextACMInst;
992
993 lpDrvInst->pNextACMInst = lpNewDrv;
994 }
995
996 /* Now just open a new instance of a driver on this module */
997 lpNewDrv->dwDriverID = MSACM_DRIVER_SendMessage(lpNewDrv, DRV_OPEN, 0, lParam2);
998
999 if (lpNewDrv->dwDriverID == 0) {
1000 FIXME("DRV_OPEN failed on driver %p\n", lpNewDrv);
1001 MSACM_RemoveFromList(lpNewDrv);
1002 return FALSE;
1003 }
1004 return TRUE;
1005 }
1006
1007 PWINE_ACMLOCALDRIVERINST MSACM_OpenLocalDriver(PWINE_ACMLOCALDRIVER paldrv, LPARAM lParam2)
1008 {
1009 PWINE_ACMLOCALDRIVERINST pDrvInst;
1010
1011 pDrvInst = HeapAlloc(MSACM_hHeap, 0, sizeof(WINE_ACMLOCALDRIVERINST));
1012 if (!pDrvInst)
1013 return NULL;
1014
1015 pDrvInst->pLocalDriver = paldrv;
1016 pDrvInst->dwDriverID = 0;
1017 pDrvInst->pNextACMInst = NULL;
1018 pDrvInst->bSession = FALSE;
1019
1020 /* Win32 installable drivers must support a two phase opening scheme:
1021 * + first open with NULL as lParam2 (session instance),
1022 * + then do a second open with the real non null lParam2)
1023 */
1024 if (MSACM_GetNumberOfModuleRefs(paldrv->hModule, paldrv->lpDrvProc, NULL) == 0 && lParam2)
1025 {
1026 PWINE_ACMLOCALDRIVERINST ret;
1027
1028 if (!MSACM_AddToList(pDrvInst, 0L))
1029 {
1030 ERR("load0 failed\n");
1031 goto exit;
1032 }
1033 ret = MSACM_OpenLocalDriver(paldrv, lParam2);
1034 if (!ret)
1035 {
1036 ERR("load1 failed\n");
1037 /* If MSACM_CloseLocalDriver returns TRUE,
1038 * then pDrvInst has been freed
1039 */
1040 if (!MSACM_CloseLocalDriver(pDrvInst))
1041 goto exit;
1042
1043 return NULL;
1044 }
1045 pDrvInst->bSession = TRUE;
1046 return ret;
1047 }
1048
1049 if (!MSACM_AddToList(pDrvInst, lParam2))
1050 {
1051 ERR("load failed\n");
1052 goto exit;
1053 }
1054
1055 TRACE("=> %p\n", pDrvInst);
1056 return pDrvInst;
1057 exit:
1058 HeapFree(MSACM_hHeap, 0, pDrvInst);
1059 return NULL;
1060 }
1061
1062 LRESULT MSACM_CloseLocalDriver(PWINE_ACMLOCALDRIVERINST paldrv)
1063 {
1064 if (MSACM_RemoveFromList(paldrv)) {
1065 PWINE_ACMLOCALDRIVERINST lpDrv0;
1066 PWINE_ACMLOCALDRIVER pDriverBase = paldrv->pLocalDriver;
1067
1068 MSACM_DRIVER_SendMessage(paldrv, DRV_CLOSE, 0, 0);
1069 paldrv->dwDriverID = 0;
1070
1071 if (paldrv->bSession)
1072 ERR("should not directly close session instance (%p)\n", paldrv);
1073
1074 /* if driver has an opened session instance, we have to close it too */
1075 if (MSACM_GetNumberOfModuleRefs(pDriverBase->hModule, pDriverBase->lpDrvProc, &lpDrv0) == 1 &&
1076 lpDrv0->bSession)
1077 {
1078 MSACM_DRIVER_SendMessage(lpDrv0, DRV_CLOSE, 0L, 0L);
1079 lpDrv0->dwDriverID = 0;
1080 MSACM_RemoveFromList(lpDrv0);
1081 HeapFree(GetProcessHeap(), 0, lpDrv0);
1082 }
1083
1084 HeapFree(MSACM_hHeap, 0, paldrv);
1085 return TRUE;
1086 }
1087 ERR("unable to close driver instance\n");
1088 return FALSE;
1089 }