cmd: Improve 'attrib' builtin to handle at least setting/clearing single attributes.
[wine/multimedia.git] / dlls / msacm32 / driver.c
blob9ca16dc75f4d476578479786d1948485f0adb3bd
1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
3 /*
4 * MSACM32 library
6 * Copyright 1998 Patrik Stridvall
7 * 1999 Eric Pouech
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.
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.
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
24 #include "config.h"
25 #include "wine/port.h"
27 #include <stdarg.h>
28 #include <stdio.h>
30 #include "windef.h"
31 #include "winbase.h"
32 #include "wingdi.h"
33 #include "winuser.h"
34 #include "winnls.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"
43 WINE_DEFAULT_DEBUG_CHANNEL(msacm);
45 /***********************************************************************
46 * acmDriverAddA (MSACM32.@)
48 MMRESULT WINAPI acmDriverAddA(PHACMDRIVERID phadid, HINSTANCE hinstModule,
49 LPARAM lParam, DWORD dwPriority, DWORD fdwAdd)
51 MMRESULT resultW;
52 WCHAR * driverW = NULL;
53 LPARAM lParamW = lParam;
55 TRACE("(%p, %p, %08lx, %08x, %08x)\n",
56 phadid, hinstModule, lParam, dwPriority, fdwAdd);
58 if (!phadid) {
59 WARN("invalid parameter\n");
60 return MMSYSERR_INVALPARAM;
63 /* Check if any unknown flags */
64 if (fdwAdd &
65 ~(ACM_DRIVERADDF_FUNCTION|ACM_DRIVERADDF_NOTIFYHWND|
66 ACM_DRIVERADDF_GLOBAL)) {
67 WARN("invalid flag\n");
68 return MMSYSERR_INVALFLAG;
71 /* Check if any incompatible flags */
72 if ((fdwAdd & ACM_DRIVERADDF_FUNCTION) &&
73 (fdwAdd & ACM_DRIVERADDF_NOTIFYHWND)) {
74 WARN("invalid flag\n");
75 return MMSYSERR_INVALFLAG;
78 /* A->W translation of name */
79 if ((fdwAdd & ACM_DRIVERADDF_TYPEMASK) == ACM_DRIVERADDF_NAME) {
80 unsigned long len;
82 if (lParam == 0) return MMSYSERR_INVALPARAM;
83 len = MultiByteToWideChar(CP_ACP, 0, (LPSTR)lParam, -1, NULL, 0);
84 driverW = HeapAlloc(MSACM_hHeap, 0, len * sizeof(WCHAR));
85 if (!driverW) return MMSYSERR_NOMEM;
86 MultiByteToWideChar(CP_ACP, 0, (LPSTR)lParam, -1, driverW, len);
87 lParamW = (LPARAM)driverW;
90 resultW = acmDriverAddW(phadid, hinstModule, lParamW, dwPriority, fdwAdd);
91 HeapFree(MSACM_hHeap, 0, driverW);
92 return resultW;
95 /***********************************************************************
96 * acmDriverAddW (MSACM32.@)
99 MMRESULT WINAPI acmDriverAddW(PHACMDRIVERID phadid, HINSTANCE hinstModule,
100 LPARAM lParam, DWORD dwPriority, DWORD fdwAdd)
102 PWINE_ACMLOCALDRIVER pLocalDrv = NULL;
104 TRACE("(%p, %p, %08lx, %08x, %08x)\n",
105 phadid, hinstModule, lParam, dwPriority, fdwAdd);
107 if (!phadid) {
108 WARN("invalid parameter\n");
109 return MMSYSERR_INVALPARAM;
112 /* Check if any unknown flags */
113 if (fdwAdd &
114 ~(ACM_DRIVERADDF_FUNCTION|ACM_DRIVERADDF_NOTIFYHWND|
115 ACM_DRIVERADDF_GLOBAL)) {
116 WARN("invalid flag\n");
117 return MMSYSERR_INVALFLAG;
120 /* Check if any incompatible flags */
121 if ((fdwAdd & ACM_DRIVERADDF_FUNCTION) &&
122 (fdwAdd & ACM_DRIVERADDF_NOTIFYHWND)) {
123 WARN("invalid flag\n");
124 return MMSYSERR_INVALFLAG;
127 switch (fdwAdd & ACM_DRIVERADDF_TYPEMASK) {
128 case ACM_DRIVERADDF_NAME:
130 hInstModule (unused)
131 lParam name of value in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Drivers32
132 dwPriority (unused, set to 0)
134 *phadid = (HACMDRIVERID) MSACM_RegisterDriverFromRegistry((LPCWSTR)lParam);
135 if (!*phadid) {
136 ERR("Unable to register driver via ACM_DRIVERADDF_NAME\n");
137 return MMSYSERR_INVALPARAM;
139 break;
140 case ACM_DRIVERADDF_FUNCTION:
142 hInstModule Handle of module which contains driver entry proc
143 lParam Driver function address
144 dwPriority (unused, set to 0)
146 fdwAdd &= ~ACM_DRIVERADDF_TYPEMASK;
147 /* FIXME: fdwAdd ignored */
148 /* Application-supplied acmDriverProc's are placed at the top of the priority unless
149 fdwAdd indicates ACM_DRIVERADDF_GLOBAL
151 pLocalDrv = MSACM_RegisterLocalDriver(hinstModule, (DRIVERPROC)lParam);
152 *phadid = pLocalDrv ? (HACMDRIVERID) MSACM_RegisterDriver(NULL, NULL, pLocalDrv) : NULL;
153 if (!*phadid) {
154 ERR("Unable to register driver via ACM_DRIVERADDF_FUNCTION\n");
155 return MMSYSERR_INVALPARAM;
157 break;
158 case ACM_DRIVERADDF_NOTIFYHWND:
160 hInstModule (unused)
161 lParam Handle of notification window
162 dwPriority Window message to send for notification broadcasts
164 *phadid = (HACMDRIVERID) MSACM_RegisterNotificationWindow((HWND)lParam, dwPriority);
165 if (!*phadid) {
166 ERR("Unable to register driver via ACM_DRIVERADDF_NOTIFYHWND\n");
167 return MMSYSERR_INVALPARAM;
169 break;
170 default:
171 ERR("invalid flag value 0x%08lx for fdwAdd\n", fdwAdd & ACM_DRIVERADDF_TYPEMASK);
172 return MMSYSERR_INVALFLAG;
175 MSACM_BroadcastNotification();
176 return MMSYSERR_NOERROR;
179 /***********************************************************************
180 * acmDriverClose (MSACM32.@)
182 MMRESULT WINAPI acmDriverClose(HACMDRIVER had, DWORD fdwClose)
184 PWINE_ACMDRIVER pad;
185 PWINE_ACMDRIVERID padid;
186 PWINE_ACMDRIVER* tpad;
188 TRACE("(%p, %08x)\n", had, fdwClose);
190 if (fdwClose) {
191 WARN("invalid flag\n");
192 return MMSYSERR_INVALFLAG;
195 pad = MSACM_GetDriver(had);
196 if (!pad) {
197 WARN("invalid handle\n");
198 return MMSYSERR_INVALHANDLE;
201 padid = pad->obj.pACMDriverID;
203 /* remove driver from list */
204 for (tpad = &(padid->pACMDriverList); *tpad; tpad = &((*tpad)->pNextACMDriver)) {
205 if (*tpad == pad) {
206 *tpad = (*tpad)->pNextACMDriver;
207 break;
211 /* close driver if it has been opened */
212 if (pad->hDrvr && !pad->pLocalDrvrInst)
213 CloseDriver(pad->hDrvr, 0, 0);
214 else if (pad->pLocalDrvrInst)
215 MSACM_CloseLocalDriver(pad->pLocalDrvrInst);
217 HeapFree(MSACM_hHeap, 0, pad);
219 return MMSYSERR_NOERROR;
222 /***********************************************************************
223 * acmDriverDetailsA (MSACM32.@)
225 MMRESULT WINAPI acmDriverDetailsA(HACMDRIVERID hadid, PACMDRIVERDETAILSA padd, DWORD fdwDetails)
227 MMRESULT mmr;
228 ACMDRIVERDETAILSW addw;
230 TRACE("(%p, %p, %08x)\n", hadid, padd, fdwDetails);
232 if (!padd) {
233 WARN("invalid parameter\n");
234 return MMSYSERR_INVALPARAM;
237 if (padd->cbStruct < 4) {
238 WARN("invalid parameter\n");
239 return MMSYSERR_INVALPARAM;
242 addw.cbStruct = sizeof(addw);
243 mmr = acmDriverDetailsW(hadid, &addw, fdwDetails);
244 if (mmr == 0) {
245 ACMDRIVERDETAILSA padda;
247 padda.fccType = addw.fccType;
248 padda.fccComp = addw.fccComp;
249 padda.wMid = addw.wMid;
250 padda.wPid = addw.wPid;
251 padda.vdwACM = addw.vdwACM;
252 padda.vdwDriver = addw.vdwDriver;
253 padda.fdwSupport = addw.fdwSupport;
254 padda.cFormatTags = addw.cFormatTags;
255 padda.cFilterTags = addw.cFilterTags;
256 padda.hicon = addw.hicon;
257 WideCharToMultiByte( CP_ACP, 0, addw.szShortName, -1, padda.szShortName,
258 sizeof(padda.szShortName), NULL, NULL );
259 WideCharToMultiByte( CP_ACP, 0, addw.szLongName, -1, padda.szLongName,
260 sizeof(padda.szLongName), NULL, NULL );
261 WideCharToMultiByte( CP_ACP, 0, addw.szCopyright, -1, padda.szCopyright,
262 sizeof(padda.szCopyright), NULL, NULL );
263 WideCharToMultiByte( CP_ACP, 0, addw.szLicensing, -1, padda.szLicensing,
264 sizeof(padda.szLicensing), NULL, NULL );
265 WideCharToMultiByte( CP_ACP, 0, addw.szFeatures, -1, padda.szFeatures,
266 sizeof(padda.szFeatures), NULL, NULL );
267 padda.cbStruct = min(padd->cbStruct, sizeof(*padd));
268 memcpy(padd, &padda, padda.cbStruct);
270 return mmr;
273 /***********************************************************************
274 * acmDriverDetailsW (MSACM32.@)
276 MMRESULT WINAPI acmDriverDetailsW(HACMDRIVERID hadid, PACMDRIVERDETAILSW padd, DWORD fdwDetails)
278 HACMDRIVER acmDrvr;
279 MMRESULT mmr;
281 TRACE("(%p, %p, %08x)\n", hadid, padd, fdwDetails);
283 if (!padd) {
284 WARN("invalid parameter\n");
285 return MMSYSERR_INVALPARAM;
288 if (padd->cbStruct < 4) {
289 WARN("invalid parameter\n");
290 return MMSYSERR_INVALPARAM;
293 if (fdwDetails) {
294 WARN("invalid flag\n");
295 return MMSYSERR_INVALFLAG;
298 mmr = acmDriverOpen(&acmDrvr, hadid, 0);
299 if (mmr == MMSYSERR_NOERROR) {
300 ACMDRIVERDETAILSW paddw;
301 paddw.cbStruct = sizeof(paddw);
302 mmr = MSACM_Message(acmDrvr, ACMDM_DRIVER_DETAILS, (LPARAM)&paddw, 0);
304 acmDriverClose(acmDrvr, 0);
305 paddw.cbStruct = min(padd->cbStruct, sizeof(*padd));
306 memcpy(padd, &paddw, paddw.cbStruct);
308 else if (mmr == MMSYSERR_NODRIVER)
309 return MMSYSERR_NOTSUPPORTED;
311 return mmr;
314 /***********************************************************************
315 * acmDriverEnum (MSACM32.@)
317 MMRESULT WINAPI acmDriverEnum(ACMDRIVERENUMCB fnCallback, DWORD_PTR dwInstance,
318 DWORD fdwEnum)
320 PWINE_ACMDRIVERID padid;
321 DWORD fdwSupport;
323 TRACE("(%p, %08lx, %08x)\n", fnCallback, dwInstance, fdwEnum);
325 if (!fnCallback) {
326 WARN("invalid parameter\n");
327 return MMSYSERR_INVALPARAM;
330 if (fdwEnum & ~(ACM_DRIVERENUMF_NOLOCAL|ACM_DRIVERENUMF_DISABLED)) {
331 WARN("invalid flag\n");
332 return MMSYSERR_INVALFLAG;
335 for (padid = MSACM_pFirstACMDriverID; padid; padid = padid->pNextACMDriverID) {
336 fdwSupport = padid->fdwSupport;
338 if (padid->fdwSupport & ACMDRIVERDETAILS_SUPPORTF_DISABLED) {
339 if (fdwEnum & ACM_DRIVERENUMF_DISABLED)
340 fdwSupport |= ACMDRIVERDETAILS_SUPPORTF_DISABLED;
341 else
342 continue;
344 if (!(*fnCallback)((HACMDRIVERID)padid, dwInstance, fdwSupport))
345 break;
348 return MMSYSERR_NOERROR;
351 /***********************************************************************
352 * acmDriverID (MSACM32.@)
354 MMRESULT WINAPI acmDriverID(HACMOBJ hao, PHACMDRIVERID phadid, DWORD fdwDriverID)
356 PWINE_ACMOBJ pao;
358 TRACE("(%p, %p, %08x)\n", hao, phadid, fdwDriverID);
360 if (fdwDriverID) {
361 WARN("invalid flag\n");
362 return MMSYSERR_INVALFLAG;
365 pao = MSACM_GetObj(hao, WINE_ACMOBJ_DONTCARE);
366 if (!pao) {
367 WARN("invalid handle\n");
368 return MMSYSERR_INVALHANDLE;
371 if (!phadid) {
372 WARN("invalid parameter\n");
373 return MMSYSERR_INVALPARAM;
376 *phadid = (HACMDRIVERID) pao->pACMDriverID;
378 return MMSYSERR_NOERROR;
381 /***********************************************************************
382 * acmDriverMessage (MSACM32.@)
384 * Note: MSDN documentation (July 2001) is incomplete. This function
385 * accepts sending messages to an HACMDRIVERID in addition to the
386 * documented HACMDRIVER. In fact, for DRV_QUERYCONFIGURE and DRV_CONFIGURE,
387 * this might actually be the required mode of operation.
389 * Note: For DRV_CONFIGURE, msacm supplies its own DRVCONFIGINFO structure
390 * when the application fails to supply one. Some native drivers depend on
391 * this and refuse to display unless a valid DRVCONFIGINFO structure is
392 * built and supplied.
394 LRESULT WINAPI acmDriverMessage(HACMDRIVER had, UINT uMsg, LPARAM lParam1, LPARAM lParam2)
396 TRACE("(%p, %04x, %08lx, %08lx\n", had, uMsg, lParam1, lParam2);
398 if ((uMsg >= ACMDM_USER && uMsg < ACMDM_RESERVED_LOW) ||
399 uMsg == ACMDM_DRIVER_ABOUT ||
400 uMsg == DRV_QUERYCONFIGURE ||
401 uMsg == DRV_CONFIGURE)
403 PWINE_ACMDRIVERID padid;
404 LRESULT lResult;
405 LPDRVCONFIGINFO pConfigInfo = NULL;
406 LPWSTR section_name = NULL;
407 LPWSTR alias_name = NULL;
409 /* Check whether handle is an HACMDRIVERID */
410 padid = MSACM_GetDriverID((HACMDRIVERID)had);
412 /* If the message is DRV_CONFIGURE, and the application provides no
413 DRVCONFIGINFO structure, msacm must supply its own.
415 if (uMsg == DRV_CONFIGURE && lParam2 == 0) {
416 LPWSTR pAlias;
418 /* Get the alias from the HACMDRIVERID */
419 if (padid) {
420 pAlias = padid->pszDriverAlias;
421 if (pAlias == NULL) {
422 WARN("DRV_CONFIGURE: no alias for this driver, cannot self-supply alias\n");
424 } else {
425 FIXME("DRV_CONFIGURE: reverse lookup HACMDRIVER -> HACMDRIVERID not implemented\n");
426 pAlias = NULL;
429 if (pAlias != NULL) {
430 /* DRVCONFIGINFO is only 12 bytes long, but native msacm
431 * reports a 16-byte structure to codecs, so allocate 16 bytes,
432 * just to be on the safe side.
434 const unsigned int iStructSize = 16;
435 pConfigInfo = HeapAlloc(MSACM_hHeap, 0, iStructSize);
436 if (!pConfigInfo) {
437 ERR("OOM while supplying DRVCONFIGINFO for DRV_CONFIGURE, using NULL\n");
438 } else {
439 static const WCHAR drivers32[] = {'D','r','i','v','e','r','s','3','2','\0'};
441 pConfigInfo->dwDCISize = iStructSize;
443 section_name = HeapAlloc(MSACM_hHeap, 0, (strlenW(drivers32) + 1) * sizeof(WCHAR));
444 if (section_name) strcpyW(section_name, drivers32);
445 pConfigInfo->lpszDCISectionName = section_name;
446 alias_name = HeapAlloc(MSACM_hHeap, 0, (strlenW(pAlias) + 1) * sizeof(WCHAR));
447 if (alias_name) strcpyW(alias_name, pAlias);
448 pConfigInfo->lpszDCIAliasName = alias_name;
450 if (pConfigInfo->lpszDCISectionName == NULL || pConfigInfo->lpszDCIAliasName == NULL) {
451 HeapFree(MSACM_hHeap, 0, alias_name);
452 HeapFree(MSACM_hHeap, 0, section_name);
453 HeapFree(MSACM_hHeap, 0, pConfigInfo);
454 pConfigInfo = NULL;
455 ERR("OOM while supplying DRVCONFIGINFO for DRV_CONFIGURE, using NULL\n");
460 lParam2 = (LPARAM)pConfigInfo;
463 if (padid) {
464 /* Handle is really an HACMDRIVERID, must have an open session to get an HACMDRIVER */
465 if (padid->pACMDriverList != NULL) {
466 lResult = MSACM_Message((HACMDRIVER)padid->pACMDriverList, uMsg, lParam1, lParam2);
467 } else {
468 MMRESULT mmr = acmDriverOpen(&had, (HACMDRIVERID)padid, 0);
469 if (mmr != MMSYSERR_NOERROR) {
470 lResult = MMSYSERR_INVALPARAM;
471 } else {
472 lResult = acmDriverMessage(had, uMsg, lParam1, lParam2);
473 acmDriverClose(had, 0);
476 } else {
477 lResult = MSACM_Message(had, uMsg, lParam1, lParam2);
479 if (pConfigInfo) {
480 HeapFree(MSACM_hHeap, 0, alias_name);
481 HeapFree(MSACM_hHeap, 0, section_name);
482 HeapFree(MSACM_hHeap, 0, pConfigInfo);
484 return lResult;
486 WARN("invalid parameter\n");
487 return MMSYSERR_INVALPARAM;
490 /***********************************************************************
491 * acmDriverOpen (MSACM32.@)
493 MMRESULT WINAPI acmDriverOpen(PHACMDRIVER phad, HACMDRIVERID hadid, DWORD fdwOpen)
495 PWINE_ACMDRIVERID padid;
496 PWINE_ACMDRIVER pad = NULL;
497 MMRESULT ret;
499 TRACE("(%p, %p, %08u)\n", phad, hadid, fdwOpen);
501 if (!phad) {
502 WARN("invalid parameter\n");
503 return MMSYSERR_INVALPARAM;
506 if (fdwOpen) {
507 WARN("invalid flag\n");
508 return MMSYSERR_INVALFLAG;
511 padid = MSACM_GetDriverID(hadid);
512 if (!padid) {
513 WARN("invalid handle\n");
514 return MMSYSERR_INVALHANDLE;
517 pad = HeapAlloc(MSACM_hHeap, 0, sizeof(WINE_ACMDRIVER));
518 if (!pad) {
519 WARN("no memory\n");
520 return MMSYSERR_NOMEM;
523 pad->obj.dwType = WINE_ACMOBJ_DRIVER;
524 pad->obj.pACMDriverID = padid;
525 pad->hDrvr = 0;
526 pad->pLocalDrvrInst = NULL;
528 if (padid->pLocalDriver == NULL)
530 ACMDRVOPENDESCW adod;
531 int len;
532 LPWSTR section_name;
534 /* this is not an externally added driver... need to actually load it */
535 if (!padid->pszDriverAlias)
537 ret = MMSYSERR_ERROR;
538 goto gotError;
541 adod.cbStruct = sizeof(adod);
542 adod.fccType = ACMDRIVERDETAILS_FCCTYPE_AUDIOCODEC;
543 adod.fccComp = ACMDRIVERDETAILS_FCCCOMP_UNDEFINED;
544 adod.dwVersion = acmGetVersion();
545 adod.dwFlags = fdwOpen;
546 adod.dwError = 0;
547 len = strlen("Drivers32") + 1;
548 section_name = HeapAlloc(MSACM_hHeap, 0, len * sizeof(WCHAR));
549 MultiByteToWideChar(CP_ACP, 0, "Drivers32", -1, section_name, len);
550 adod.pszSectionName = section_name;
551 adod.pszAliasName = padid->pszDriverAlias;
552 adod.dnDevNode = 0;
554 pad->hDrvr = OpenDriver(padid->pszDriverAlias, NULL, (DWORD_PTR)&adod);
556 HeapFree(MSACM_hHeap, 0, section_name);
557 if (!pad->hDrvr)
559 ret = adod.dwError;
560 if (ret == MMSYSERR_NOERROR)
561 ret = MMSYSERR_NODRIVER;
562 goto gotError;
565 else
567 ACMDRVOPENDESCW adod;
569 pad->hDrvr = NULL;
571 adod.cbStruct = sizeof(adod);
572 adod.fccType = ACMDRIVERDETAILS_FCCTYPE_AUDIOCODEC;
573 adod.fccComp = ACMDRIVERDETAILS_FCCCOMP_UNDEFINED;
574 adod.dwVersion = acmGetVersion();
575 adod.dwFlags = fdwOpen;
576 adod.dwError = 0;
577 adod.pszSectionName = NULL;
578 adod.pszAliasName = NULL;
579 adod.dnDevNode = 0;
581 pad->pLocalDrvrInst = MSACM_OpenLocalDriver(padid->pLocalDriver, (DWORD_PTR)&adod);
582 if (!pad->pLocalDrvrInst)
584 ret = adod.dwError;
585 if (ret == MMSYSERR_NOERROR)
586 ret = MMSYSERR_NODRIVER;
587 goto gotError;
591 /* insert new pad at beg of list */
592 pad->pNextACMDriver = padid->pACMDriverList;
593 padid->pACMDriverList = pad;
595 /* FIXME: Create a WINE_ACMDRIVER32 */
596 *phad = (HACMDRIVER)pad;
597 TRACE("%s => %p\n", debugstr_w(padid->pszDriverAlias), pad);
599 return MMSYSERR_NOERROR;
600 gotError:
601 WARN("failed: ret = %08x\n", ret);
602 if (pad && !pad->hDrvr)
603 HeapFree(MSACM_hHeap, 0, pad);
604 return ret;
607 /***********************************************************************
608 * acmDriverPriority (MSACM32.@)
610 MMRESULT WINAPI acmDriverPriority(HACMDRIVERID hadid, DWORD dwPriority, DWORD fdwPriority)
613 TRACE("(%p, %08x, %08x)\n", hadid, dwPriority, fdwPriority);
615 /* Check for unknown flags */
616 if (fdwPriority &
617 ~(ACM_DRIVERPRIORITYF_ENABLE|ACM_DRIVERPRIORITYF_DISABLE|
618 ACM_DRIVERPRIORITYF_BEGIN|ACM_DRIVERPRIORITYF_END)) {
619 WARN("invalid flag\n");
620 return MMSYSERR_INVALFLAG;
623 /* Check for incompatible flags */
624 if ((fdwPriority & ACM_DRIVERPRIORITYF_ENABLE) &&
625 (fdwPriority & ACM_DRIVERPRIORITYF_DISABLE)) {
626 WARN("invalid flag\n");
627 return MMSYSERR_INVALFLAG;
630 /* Check for incompatible flags */
631 if ((fdwPriority & ACM_DRIVERPRIORITYF_BEGIN) &&
632 (fdwPriority & ACM_DRIVERPRIORITYF_END)) {
633 WARN("invalid flag\n");
634 return MMSYSERR_INVALFLAG;
637 /* According to MSDN, ACM_DRIVERPRIORITYF_BEGIN and ACM_DRIVERPRIORITYF_END
638 may only appear by themselves, and in addition, hadid and dwPriority must
639 both be zero */
640 if ((fdwPriority & ACM_DRIVERPRIORITYF_BEGIN) ||
641 (fdwPriority & ACM_DRIVERPRIORITYF_END)) {
642 if (fdwPriority & ~(ACM_DRIVERPRIORITYF_BEGIN|ACM_DRIVERPRIORITYF_END)) {
643 WARN("ACM_DRIVERPRIORITYF_[BEGIN|END] cannot be used with any other flags\n");
644 return MMSYSERR_INVALPARAM;
646 if (dwPriority) {
647 WARN("priority invalid with ACM_DRIVERPRIORITYF_[BEGIN|END]\n");
648 return MMSYSERR_INVALPARAM;
650 if (hadid) {
651 WARN("non-null hadid invalid with ACM_DRIVERPRIORITYF_[BEGIN|END]\n");
652 return MMSYSERR_INVALPARAM;
654 /* FIXME: MSDN wording suggests that deferred notification should be
655 implemented as a system-wide lock held by a calling task, and that
656 re-enabling notifications should broadcast them across all processes.
657 This implementation uses a simple DWORD counter. One consequence of the
658 current implementation is that applications will never see
659 MMSYSERR_ALLOCATED as a return error.
661 if (fdwPriority & ACM_DRIVERPRIORITYF_BEGIN) {
662 MSACM_DisableNotifications();
663 } else if (fdwPriority & ACM_DRIVERPRIORITYF_END) {
664 MSACM_EnableNotifications();
666 return MMSYSERR_NOERROR;
667 } else {
668 PWINE_ACMDRIVERID padid;
669 PWINE_ACMNOTIFYWND panwnd;
670 BOOL bPerformBroadcast = FALSE;
672 /* Fetch driver ID */
673 padid = MSACM_GetDriverID(hadid);
674 panwnd = MSACM_GetNotifyWnd(hadid);
675 if (!padid && !panwnd) {
676 WARN("invalid handle\n");
677 return MMSYSERR_INVALHANDLE;
680 if (padid) {
681 /* Check whether driver ID is appropriate for requested op */
682 if (dwPriority) {
683 if (padid->fdwSupport & ACMDRIVERDETAILS_SUPPORTF_LOCAL) {
684 return MMSYSERR_NOTSUPPORTED;
686 if (dwPriority != 1 && dwPriority != (DWORD)-1) {
687 FIXME("unexpected priority %d, using sign only\n", dwPriority);
688 if ((signed)dwPriority < 0) dwPriority = (DWORD)-1;
689 if (dwPriority > 0) dwPriority = 1;
692 if (dwPriority == 1 && (padid->pPrevACMDriverID == NULL ||
693 (padid->pPrevACMDriverID->fdwSupport & ACMDRIVERDETAILS_SUPPORTF_LOCAL))) {
694 /* do nothing - driver is first of list, or first after last
695 local driver */
696 } else if (dwPriority == (DWORD)-1 && padid->pNextACMDriverID == NULL) {
697 /* do nothing - driver is last of list */
698 } else {
699 MSACM_RePositionDriver(padid, dwPriority);
700 bPerformBroadcast = TRUE;
704 /* Check whether driver ID should be enabled or disabled */
705 if (fdwPriority & ACM_DRIVERPRIORITYF_DISABLE) {
706 if (!(padid->fdwSupport & ACMDRIVERDETAILS_SUPPORTF_DISABLED)) {
707 padid->fdwSupport |= ACMDRIVERDETAILS_SUPPORTF_DISABLED;
708 bPerformBroadcast = TRUE;
710 } else if (fdwPriority & ACM_DRIVERPRIORITYF_ENABLE) {
711 if (padid->fdwSupport & ACMDRIVERDETAILS_SUPPORTF_DISABLED) {
712 padid->fdwSupport &= ~ACMDRIVERDETAILS_SUPPORTF_DISABLED;
713 bPerformBroadcast = TRUE;
718 if (panwnd) {
719 if (dwPriority) {
720 return MMSYSERR_NOTSUPPORTED;
723 /* Check whether notify window should be enabled or disabled */
724 if (fdwPriority & ACM_DRIVERPRIORITYF_DISABLE) {
725 if (!(panwnd->fdwSupport & ACMDRIVERDETAILS_SUPPORTF_DISABLED)) {
726 panwnd->fdwSupport |= ACMDRIVERDETAILS_SUPPORTF_DISABLED;
727 bPerformBroadcast = TRUE;
729 } else if (fdwPriority & ACM_DRIVERPRIORITYF_ENABLE) {
730 if (panwnd->fdwSupport & ACMDRIVERDETAILS_SUPPORTF_DISABLED) {
731 panwnd->fdwSupport &= ~ACMDRIVERDETAILS_SUPPORTF_DISABLED;
732 bPerformBroadcast = TRUE;
737 /* Perform broadcast of changes */
738 if (bPerformBroadcast) {
739 MSACM_WriteCurrentPriorities();
740 MSACM_BroadcastNotification();
742 return MMSYSERR_NOERROR;
746 /***********************************************************************
747 * acmDriverRemove (MSACM32.@)
749 MMRESULT WINAPI acmDriverRemove(HACMDRIVERID hadid, DWORD fdwRemove)
751 PWINE_ACMDRIVERID padid;
752 PWINE_ACMNOTIFYWND panwnd;
754 TRACE("(%p, %08x)\n", hadid, fdwRemove);
756 padid = MSACM_GetDriverID(hadid);
757 panwnd = MSACM_GetNotifyWnd(hadid);
758 if (!padid && !panwnd) {
759 WARN("invalid handle\n");
760 return MMSYSERR_INVALHANDLE;
763 if (fdwRemove) {
764 WARN("invalid flag\n");
765 return MMSYSERR_INVALFLAG;
768 if (padid) MSACM_UnregisterDriver(padid);
769 if (panwnd) MSACM_UnRegisterNotificationWindow(panwnd);
770 MSACM_BroadcastNotification();
772 return MMSYSERR_NOERROR;