1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
6 * Copyright 1998 Patrik Stridvall
23 #include "debugtools.h"
25 DEFAULT_DEBUG_CHANNEL(msacm
);
27 /***********************************************************************
28 * acmDriverAddA (MSACM32.@)
30 MMRESULT WINAPI
acmDriverAddA(PHACMDRIVERID phadid
, HINSTANCE hinstModule
,
31 LPARAM lParam
, DWORD dwPriority
, DWORD fdwAdd
)
34 return MMSYSERR_INVALPARAM
;
36 /* Check if any unknown flags */
38 ~(ACM_DRIVERADDF_FUNCTION
|ACM_DRIVERADDF_NOTIFYHWND
|
39 ACM_DRIVERADDF_GLOBAL
))
40 return MMSYSERR_INVALFLAG
;
42 /* Check if any incompatible flags */
43 if ((fdwAdd
& ACM_DRIVERADDF_FUNCTION
) &&
44 (fdwAdd
& ACM_DRIVERADDF_NOTIFYHWND
))
45 return MMSYSERR_INVALFLAG
;
47 /* FIXME: in fact, should GetModuleFileName(hinstModule) and do a
48 * LoadDriver on it, to be sure we can call SendDriverMessage on the
51 *phadid
= (HACMDRIVERID
) MSACM_RegisterDriver(NULL
, NULL
, hinstModule
);
53 /* FIXME: lParam, dwPriority and fdwAdd ignored */
55 return MMSYSERR_NOERROR
;
58 /***********************************************************************
59 * acmDriverAddW (MSACM32.@)
63 MMRESULT WINAPI
acmDriverAddW(PHACMDRIVERID phadid
, HINSTANCE hinstModule
,
64 LPARAM lParam
, DWORD dwPriority
, DWORD fdwAdd
)
66 FIXME("(%p, 0x%08x, %ld, %ld, %ld): stub\n",
67 phadid
, hinstModule
, lParam
, dwPriority
, fdwAdd
);
69 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
70 return MMSYSERR_ERROR
;
73 /***********************************************************************
74 * acmDriverClose (MSACM32.@)
76 MMRESULT WINAPI
acmDriverClose(HACMDRIVER had
, DWORD fdwClose
)
79 PWINE_ACMDRIVERID padid
;
80 PWINE_ACMDRIVER
* tpad
;
83 return MMSYSERR_INVALFLAG
;
85 pad
= MSACM_GetDriver(had
);
87 return MMSYSERR_INVALHANDLE
;
89 padid
= pad
->obj
.pACMDriverID
;
91 /* remove driver from list */
92 for (tpad
= &(padid
->pACMDriverList
); *tpad
; *tpad
= (*tpad
)->pNextACMDriver
) {
94 *tpad
= (*tpad
)->pNextACMDriver
;
99 /* close driver if it has been opened */
100 if (pad
->hDrvr
&& !padid
->hInstModule
)
101 CloseDriver(pad
->hDrvr
, 0, 0);
103 HeapFree(MSACM_hHeap
, 0, pad
);
105 return MMSYSERR_NOERROR
;
108 /***********************************************************************
109 * acmDriverDetailsA (MSACM32.@)
111 MMRESULT WINAPI
acmDriverDetailsA(HACMDRIVERID hadid
, PACMDRIVERDETAILSA padd
, DWORD fdwDetails
)
114 ACMDRIVERDETAILSW addw
;
116 addw
.cbStruct
= sizeof(addw
);
117 mmr
= acmDriverDetailsW(hadid
, &addw
, fdwDetails
);
119 padd
->fccType
= addw
.fccType
;
120 padd
->fccComp
= addw
.fccComp
;
121 padd
->wMid
= addw
.wMid
;
122 padd
->wPid
= addw
.wPid
;
123 padd
->vdwACM
= addw
.vdwACM
;
124 padd
->vdwDriver
= addw
.vdwDriver
;
125 padd
->fdwSupport
= addw
.fdwSupport
;
126 padd
->cFormatTags
= addw
.cFormatTags
;
127 padd
->cFilterTags
= addw
.cFilterTags
;
128 padd
->hicon
= addw
.hicon
;
129 WideCharToMultiByte( CP_ACP
, 0, addw
.szShortName
, -1, padd
->szShortName
,
130 sizeof(padd
->szShortName
), NULL
, NULL
);
131 WideCharToMultiByte( CP_ACP
, 0, addw
.szLongName
, -1, padd
->szLongName
,
132 sizeof(padd
->szLongName
), NULL
, NULL
);
133 WideCharToMultiByte( CP_ACP
, 0, addw
.szCopyright
, -1, padd
->szCopyright
,
134 sizeof(padd
->szCopyright
), NULL
, NULL
);
135 WideCharToMultiByte( CP_ACP
, 0, addw
.szLicensing
, -1, padd
->szLicensing
,
136 sizeof(padd
->szLicensing
), NULL
, NULL
);
137 WideCharToMultiByte( CP_ACP
, 0, addw
.szFeatures
, -1, padd
->szFeatures
,
138 sizeof(padd
->szFeatures
), NULL
, NULL
);
143 /***********************************************************************
144 * acmDriverDetailsW (MSACM32.@)
146 MMRESULT WINAPI
acmDriverDetailsW(HACMDRIVERID hadid
, PACMDRIVERDETAILSW padd
, DWORD fdwDetails
)
152 return MMSYSERR_INVALFLAG
;
154 mmr
= acmDriverOpen(&acmDrvr
, hadid
, 0);
155 if (mmr
== MMSYSERR_NOERROR
) {
156 mmr
= (MMRESULT
)MSACM_Message(acmDrvr
, ACMDM_DRIVER_DETAILS
, (LPARAM
)padd
, 0);
158 acmDriverClose(acmDrvr
, 0);
164 /***********************************************************************
165 * acmDriverEnum (MSACM32.@)
167 MMRESULT WINAPI
acmDriverEnum(ACMDRIVERENUMCB fnCallback
, DWORD dwInstance
, DWORD fdwEnum
)
169 PWINE_ACMDRIVERID padid
;
172 if (!fnCallback
) return MMSYSERR_INVALPARAM
;
174 if (fdwEnum
& ~(ACM_DRIVERENUMF_NOLOCAL
|ACM_DRIVERENUMF_DISABLED
))
175 return MMSYSERR_INVALFLAG
;
177 for (padid
= MSACM_pFirstACMDriverID
; padid
; padid
= padid
->pNextACMDriverID
) {
178 fdwSupport
= padid
->fdwSupport
;
180 if (padid
->fdwSupport
& ACMDRIVERDETAILS_SUPPORTF_DISABLED
) {
181 if (fdwEnum
& ACM_DRIVERENUMF_DISABLED
)
182 fdwSupport
|= ACMDRIVERDETAILS_SUPPORTF_DISABLED
;
186 if (!(*fnCallback
)((HACMDRIVERID
)padid
, dwInstance
, fdwSupport
))
190 return MMSYSERR_NOERROR
;
193 /***********************************************************************
194 * acmDriverID (MSACM32.@)
196 MMRESULT WINAPI
acmDriverID(HACMOBJ hao
, PHACMDRIVERID phadid
, DWORD fdwDriverID
)
201 return MMSYSERR_INVALPARAM
;
204 return MMSYSERR_INVALFLAG
;
206 pao
= MSACM_GetObj(hao
, WINE_ACMOBJ_DONTCARE
);
208 return MMSYSERR_INVALHANDLE
;
210 *phadid
= (HACMDRIVERID
) pao
->pACMDriverID
;
212 return MMSYSERR_NOERROR
;
215 /***********************************************************************
216 * acmDriverMessage (MSACM32.@)
219 LRESULT WINAPI
acmDriverMessage(HACMDRIVER had
, UINT uMsg
, LPARAM lParam1
, LPARAM lParam2
)
221 if ((uMsg
>= ACMDM_USER
&& uMsg
< ACMDM_RESERVED_LOW
) ||
222 uMsg
== ACMDM_DRIVER_ABOUT
||
223 uMsg
== DRV_QUERYCONFIGURE
||
224 uMsg
== DRV_CONFIGURE
)
225 return MSACM_Message(had
, uMsg
, lParam1
, lParam2
);
226 return MMSYSERR_INVALPARAM
;
229 static MMRESULT
MSACM_DriverOpenHelper(PWINE_ACMDRIVER
* ppad
, PWINE_ACMDRIVERID padid
, DWORD fdwOpen
, BOOL useDesc
)
231 MMRESULT ret
= MMSYSERR_ERROR
;
236 pad
= HeapAlloc(MSACM_hHeap
, 0, sizeof(WINE_ACMDRIVER
));
237 if (!pad
) return MMSYSERR_NOMEM
;
239 pad
->obj
.dwType
= WINE_ACMOBJ_DRIVER
;
240 pad
->obj
.pACMDriverID
= padid
;
242 if (!(pad
->hDrvr
= padid
->hInstModule
)) {
243 /* this is not an externally added driver... need to load it */
244 if (!padid
->pszDriverAlias
) goto gotError
;
247 ACMDRVOPENDESCW adod
;
250 adod
.cbStruct
= sizeof(adod
);
251 adod
.fccType
= ACMDRIVERDETAILS_FCCTYPE_AUDIOCODEC
;
252 adod
.fccComp
= ACMDRIVERDETAILS_FCCCOMP_UNDEFINED
;
253 adod
.dwVersion
= acmGetVersion();
254 adod
.dwFlags
= fdwOpen
;
256 len
= strlen("Drivers32") + 1;
257 adod
.pszSectionName
= HeapAlloc(MSACM_hHeap
, 0, len
* sizeof(WCHAR
));
258 MultiByteToWideChar(CP_ACP
, 0, "Drivers32", -1, (LPWSTR
)adod
.pszSectionName
, len
);
259 len
= strlen(padid
->pszDriverAlias
) + 1;
260 adod
.pszAliasName
= HeapAlloc(MSACM_hHeap
, 0, len
* sizeof(WCHAR
));
261 MultiByteToWideChar(CP_ACP
, 0, padid
->pszDriverAlias
, -1, (LPWSTR
)adod
.pszAliasName
, len
);
264 pad
->hDrvr
= OpenDriverA(padid
->pszDriverAlias
, NULL
, (DWORD
)&adod
);
266 HeapFree(MSACM_hHeap
, 0, (LPWSTR
)adod
.pszSectionName
);
267 HeapFree(MSACM_hHeap
, 0, (LPWSTR
)adod
.pszAliasName
);
273 if (!(pad
->hDrvr
= OpenDriverA(padid
->pszDriverAlias
, 0L, 0L))) {
274 ret
= MMSYSERR_ERROR
;
280 return MMSYSERR_NOERROR
;
282 HeapFree(MSACM_hHeap
, 0, pad
);
286 /***********************************************************************
287 * acmDriverOpen (MSACM32.@)
289 MMRESULT WINAPI
acmDriverOpen(PHACMDRIVER phad
, HACMDRIVERID hadid
, DWORD fdwOpen
)
291 PWINE_ACMDRIVERID padid
;
292 PWINE_ACMDRIVER pad
= NULL
, first_pad
= NULL
;
295 TRACE("(%p, %x, %08lu)\n", phad
, hadid
, fdwOpen
);
298 return MMSYSERR_INVALPARAM
;
301 return MMSYSERR_INVALFLAG
;
303 padid
= MSACM_GetDriverID(hadid
);
305 return MMSYSERR_INVALHANDLE
;
307 /* first driver to be loaded ? */
308 if (!padid
->pACMDriverList
&& !padid
->hInstModule
) {
309 ret
= MSACM_DriverOpenHelper(&first_pad
, padid
, fdwOpen
, FALSE
);
310 if (ret
) goto gotError
;
313 /* insert new pad at beg of list */
314 first_pad
->pNextACMDriver
= NULL
;
315 padid
->pACMDriverList
= first_pad
;
318 ret
= MSACM_DriverOpenHelper(&pad
, padid
, fdwOpen
, TRUE
);
321 acmDriverClose((HACMDRIVER
)first_pad
, 0L);
325 /* insert new pad at beg of list */
326 pad
->pNextACMDriver
= padid
->pACMDriverList
;
327 padid
->pACMDriverList
= pad
;
329 /* FIXME: Create a WINE_ACMDRIVER32 */
330 *phad
= (HACMDRIVER
)pad
;
331 TRACE("'%s' => %08lx\n", padid
->pszDriverAlias
, (DWORD
)pad
);
333 return MMSYSERR_NOERROR
;
335 if (pad
&& !pad
->hDrvr
)
336 HeapFree(MSACM_hHeap
, 0, pad
);
340 /***********************************************************************
341 * acmDriverPriority (MSACM32.@)
343 MMRESULT WINAPI
acmDriverPriority(HACMDRIVERID hadid
, DWORD dwPriority
, DWORD fdwPriority
)
345 PWINE_ACMDRIVERID padid
;
348 LONG lBufferLength
= sizeof(szBuffer
);
351 DWORD dwPriorityCounter
;
353 padid
= MSACM_GetDriverID(hadid
);
355 return MMSYSERR_INVALHANDLE
;
357 /* Check for unknown flags */
359 ~(ACM_DRIVERPRIORITYF_ENABLE
|ACM_DRIVERPRIORITYF_DISABLE
|
360 ACM_DRIVERPRIORITYF_BEGIN
|ACM_DRIVERPRIORITYF_END
))
361 return MMSYSERR_INVALFLAG
;
363 /* Check for incompatible flags */
364 if ((fdwPriority
& ACM_DRIVERPRIORITYF_ENABLE
) &&
365 (fdwPriority
& ACM_DRIVERPRIORITYF_DISABLE
))
366 return MMSYSERR_INVALFLAG
;
368 /* Check for incompatible flags */
369 if ((fdwPriority
& ACM_DRIVERPRIORITYF_BEGIN
) &&
370 (fdwPriority
& ACM_DRIVERPRIORITYF_END
))
371 return MMSYSERR_INVALFLAG
;
373 lError
= RegOpenKeyA(HKEY_CURRENT_USER
,
374 "Software\\Microsoft\\Multimedia\\"
375 "Audio Compression Manager\\Priority v4.00",
378 /* FIXME: Create key */
379 if (lError
!= ERROR_SUCCESS
)
380 return MMSYSERR_ERROR
;
382 for (dwPriorityCounter
= 1; ; dwPriorityCounter
++) {
383 snprintf(szSubKey
, 17, "Priorty%ld", dwPriorityCounter
);
384 lError
= RegQueryValueA(hPriorityKey
, szSubKey
, szBuffer
, &lBufferLength
);
385 if (lError
!= ERROR_SUCCESS
)
388 FIXME("(0x%08x, %ld, %ld): stub (partial)\n",
389 hadid
, dwPriority
, fdwPriority
);
393 RegCloseKey(hPriorityKey
);
395 return MMSYSERR_ERROR
;
398 /***********************************************************************
399 * acmDriverRemove (MSACM32.@)
401 MMRESULT WINAPI
acmDriverRemove(HACMDRIVERID hadid
, DWORD fdwRemove
)
403 PWINE_ACMDRIVERID padid
;
405 padid
= MSACM_GetDriverID(hadid
);
407 return MMSYSERR_INVALHANDLE
;
410 return MMSYSERR_INVALFLAG
;
412 MSACM_UnregisterDriver(padid
);
414 return MMSYSERR_NOERROR
;