Call IShellExecuteHook interface for ShellExecute() calls with ID
[wine/multimedia.git] / dlls / msacm / driver.c
blobb473f9c4d7333a1721de4c1d381be041c5e1ab71
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 "winerror.h"
33 #include "wingdi.h"
34 #include "winuser.h"
35 #include "winnls.h"
36 #include "winreg.h"
37 #include "mmsystem.h"
38 #include "mmreg.h"
39 #include "msacm.h"
40 #include "msacmdrv.h"
41 #include "wineacm.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(msacm);
46 /***********************************************************************
47 * acmDriverAddA (MSACM32.@)
49 MMRESULT WINAPI acmDriverAddA(PHACMDRIVERID phadid, HINSTANCE hinstModule,
50 LPARAM lParam, DWORD dwPriority, DWORD fdwAdd)
52 if (!phadid)
53 return MMSYSERR_INVALPARAM;
55 /* Check if any unknown flags */
56 if (fdwAdd &
57 ~(ACM_DRIVERADDF_FUNCTION|ACM_DRIVERADDF_NOTIFYHWND|
58 ACM_DRIVERADDF_GLOBAL))
59 return MMSYSERR_INVALFLAG;
61 /* Check if any incompatible flags */
62 if ((fdwAdd & ACM_DRIVERADDF_FUNCTION) &&
63 (fdwAdd & ACM_DRIVERADDF_NOTIFYHWND))
64 return MMSYSERR_INVALFLAG;
66 /* FIXME: in fact, should GetModuleFileName(hinstModule) and do a
67 * LoadDriver on it, to be sure we can call SendDriverMessage on the
68 * hDrvr handle.
70 *phadid = (HACMDRIVERID) MSACM_RegisterDriver(NULL, NULL, hinstModule);
72 /* FIXME: lParam, dwPriority and fdwAdd ignored */
74 return MMSYSERR_NOERROR;
77 /***********************************************************************
78 * acmDriverAddW (MSACM32.@)
79 * FIXME
80 * Not implemented
82 MMRESULT WINAPI acmDriverAddW(PHACMDRIVERID phadid, HINSTANCE hinstModule,
83 LPARAM lParam, DWORD dwPriority, DWORD fdwAdd)
85 FIXME("(%p, %p, %ld, %ld, %ld): stub\n",
86 phadid, hinstModule, lParam, dwPriority, fdwAdd);
88 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
89 return MMSYSERR_ERROR;
92 /***********************************************************************
93 * acmDriverClose (MSACM32.@)
95 MMRESULT WINAPI acmDriverClose(HACMDRIVER had, DWORD fdwClose)
97 PWINE_ACMDRIVER pad;
98 PWINE_ACMDRIVERID padid;
99 PWINE_ACMDRIVER* tpad;
101 if (fdwClose)
102 return MMSYSERR_INVALFLAG;
104 pad = MSACM_GetDriver(had);
105 if (!pad)
106 return MMSYSERR_INVALHANDLE;
108 padid = pad->obj.pACMDriverID;
110 /* remove driver from list */
111 for (tpad = &(padid->pACMDriverList); *tpad; *tpad = (*tpad)->pNextACMDriver) {
112 if (*tpad == pad) {
113 *tpad = (*tpad)->pNextACMDriver;
114 break;
118 /* close driver if it has been opened */
119 if (pad->hDrvr && !padid->hInstModule)
120 CloseDriver(pad->hDrvr, 0, 0);
122 HeapFree(MSACM_hHeap, 0, pad);
124 return MMSYSERR_NOERROR;
127 /***********************************************************************
128 * acmDriverDetailsA (MSACM32.@)
130 MMRESULT WINAPI acmDriverDetailsA(HACMDRIVERID hadid, PACMDRIVERDETAILSA padd, DWORD fdwDetails)
132 MMRESULT mmr;
133 ACMDRIVERDETAILSW addw;
135 addw.cbStruct = sizeof(addw);
136 mmr = acmDriverDetailsW(hadid, &addw, fdwDetails);
137 if (mmr == 0) {
138 padd->fccType = addw.fccType;
139 padd->fccComp = addw.fccComp;
140 padd->wMid = addw.wMid;
141 padd->wPid = addw.wPid;
142 padd->vdwACM = addw.vdwACM;
143 padd->vdwDriver = addw.vdwDriver;
144 padd->fdwSupport = addw.fdwSupport;
145 padd->cFormatTags = addw.cFormatTags;
146 padd->cFilterTags = addw.cFilterTags;
147 padd->hicon = addw.hicon;
148 WideCharToMultiByte( CP_ACP, 0, addw.szShortName, -1, padd->szShortName,
149 sizeof(padd->szShortName), NULL, NULL );
150 WideCharToMultiByte( CP_ACP, 0, addw.szLongName, -1, padd->szLongName,
151 sizeof(padd->szLongName), NULL, NULL );
152 WideCharToMultiByte( CP_ACP, 0, addw.szCopyright, -1, padd->szCopyright,
153 sizeof(padd->szCopyright), NULL, NULL );
154 WideCharToMultiByte( CP_ACP, 0, addw.szLicensing, -1, padd->szLicensing,
155 sizeof(padd->szLicensing), NULL, NULL );
156 WideCharToMultiByte( CP_ACP, 0, addw.szFeatures, -1, padd->szFeatures,
157 sizeof(padd->szFeatures), NULL, NULL );
159 return mmr;
162 /***********************************************************************
163 * acmDriverDetailsW (MSACM32.@)
165 MMRESULT WINAPI acmDriverDetailsW(HACMDRIVERID hadid, PACMDRIVERDETAILSW padd, DWORD fdwDetails)
167 HACMDRIVER acmDrvr;
168 MMRESULT mmr;
170 if (fdwDetails)
171 return MMSYSERR_INVALFLAG;
173 mmr = acmDriverOpen(&acmDrvr, hadid, 0);
174 if (mmr == MMSYSERR_NOERROR) {
175 mmr = (MMRESULT)MSACM_Message(acmDrvr, ACMDM_DRIVER_DETAILS, (LPARAM)padd, 0);
177 acmDriverClose(acmDrvr, 0);
180 return mmr;
183 /***********************************************************************
184 * acmDriverEnum (MSACM32.@)
186 MMRESULT WINAPI acmDriverEnum(ACMDRIVERENUMCB fnCallback, DWORD dwInstance, DWORD fdwEnum)
188 PWINE_ACMDRIVERID padid;
189 DWORD fdwSupport;
191 if (!fnCallback) return MMSYSERR_INVALPARAM;
193 if (fdwEnum & ~(ACM_DRIVERENUMF_NOLOCAL|ACM_DRIVERENUMF_DISABLED))
194 return MMSYSERR_INVALFLAG;
196 for (padid = MSACM_pFirstACMDriverID; padid; padid = padid->pNextACMDriverID) {
197 fdwSupport = padid->fdwSupport;
199 if (padid->fdwSupport & ACMDRIVERDETAILS_SUPPORTF_DISABLED) {
200 if (fdwEnum & ACM_DRIVERENUMF_DISABLED)
201 fdwSupport |= ACMDRIVERDETAILS_SUPPORTF_DISABLED;
202 else
203 continue;
205 if (!(*fnCallback)((HACMDRIVERID)padid, dwInstance, fdwSupport))
206 break;
209 return MMSYSERR_NOERROR;
212 /***********************************************************************
213 * acmDriverID (MSACM32.@)
215 MMRESULT WINAPI acmDriverID(HACMOBJ hao, PHACMDRIVERID phadid, DWORD fdwDriverID)
217 PWINE_ACMOBJ pao;
219 if (!phadid)
220 return MMSYSERR_INVALPARAM;
222 if (fdwDriverID)
223 return MMSYSERR_INVALFLAG;
225 pao = MSACM_GetObj(hao, WINE_ACMOBJ_DONTCARE);
226 if (!pao)
227 return MMSYSERR_INVALHANDLE;
229 *phadid = (HACMDRIVERID) pao->pACMDriverID;
231 return MMSYSERR_NOERROR;
234 /***********************************************************************
235 * acmDriverMessage (MSACM32.@)
238 LRESULT WINAPI acmDriverMessage(HACMDRIVER had, UINT uMsg, LPARAM lParam1, LPARAM lParam2)
240 if ((uMsg >= ACMDM_USER && uMsg < ACMDM_RESERVED_LOW) ||
241 uMsg == ACMDM_DRIVER_ABOUT ||
242 uMsg == DRV_QUERYCONFIGURE ||
243 uMsg == DRV_CONFIGURE)
244 return MSACM_Message(had, uMsg, lParam1, lParam2);
245 return MMSYSERR_INVALPARAM;
248 /***********************************************************************
249 * acmDriverOpen (MSACM32.@)
251 MMRESULT WINAPI acmDriverOpen(PHACMDRIVER phad, HACMDRIVERID hadid, DWORD fdwOpen)
253 PWINE_ACMDRIVERID padid;
254 PWINE_ACMDRIVER pad = NULL;
255 MMRESULT ret;
257 TRACE("(%p, %p, %08lu)\n", phad, hadid, fdwOpen);
259 if (!phad)
260 return MMSYSERR_INVALPARAM;
262 if (fdwOpen)
263 return MMSYSERR_INVALFLAG;
265 padid = MSACM_GetDriverID(hadid);
266 if (!padid)
267 return MMSYSERR_INVALHANDLE;
269 pad = HeapAlloc(MSACM_hHeap, 0, sizeof(WINE_ACMDRIVER));
270 if (!pad)
271 return MMSYSERR_NOMEM;
273 pad->obj.dwType = WINE_ACMOBJ_DRIVER;
274 pad->obj.pACMDriverID = padid;
276 if (!(pad->hDrvr = (HDRVR)padid->hInstModule))
278 ACMDRVOPENDESCW adod;
279 int len;
281 /* this is not an externally added driver... need to actually load it */
282 if (!padid->pszDriverAlias)
284 ret = MMSYSERR_ERROR;
285 goto gotError;
288 adod.cbStruct = sizeof(adod);
289 adod.fccType = ACMDRIVERDETAILS_FCCTYPE_AUDIOCODEC;
290 adod.fccComp = ACMDRIVERDETAILS_FCCCOMP_UNDEFINED;
291 adod.dwVersion = acmGetVersion();
292 adod.dwFlags = fdwOpen;
293 adod.dwError = 0;
294 len = strlen("Drivers32") + 1;
295 adod.pszSectionName = HeapAlloc(MSACM_hHeap, 0, len * sizeof(WCHAR));
296 MultiByteToWideChar(CP_ACP, 0, "Drivers32", -1, (LPWSTR)adod.pszSectionName, len);
297 adod.pszAliasName = padid->pszDriverAlias;
298 adod.dnDevNode = 0;
300 pad->hDrvr = OpenDriver(padid->pszDriverAlias, NULL, (DWORD)&adod);
302 HeapFree(MSACM_hHeap, 0, (LPWSTR)adod.pszSectionName);
303 if (!pad->hDrvr)
305 ret = adod.dwError;
306 goto gotError;
310 /* insert new pad at beg of list */
311 pad->pNextACMDriver = padid->pACMDriverList;
312 padid->pACMDriverList = pad;
314 /* FIXME: Create a WINE_ACMDRIVER32 */
315 *phad = (HACMDRIVER)pad;
316 TRACE("'%s' => %08lx\n", debugstr_w(padid->pszDriverAlias), (DWORD)pad);
318 return MMSYSERR_NOERROR;
319 gotError:
320 if (pad && !pad->hDrvr)
321 HeapFree(MSACM_hHeap, 0, pad);
322 return ret;
325 /***********************************************************************
326 * acmDriverPriority (MSACM32.@)
328 MMRESULT WINAPI acmDriverPriority(HACMDRIVERID hadid, DWORD dwPriority, DWORD fdwPriority)
330 PWINE_ACMDRIVERID padid;
331 CHAR szSubKey[17];
332 CHAR szBuffer[256];
333 LONG lBufferLength = sizeof(szBuffer);
334 LONG lError;
335 HKEY hPriorityKey;
336 DWORD dwPriorityCounter;
338 padid = MSACM_GetDriverID(hadid);
339 if (!padid)
340 return MMSYSERR_INVALHANDLE;
342 /* Check for unknown flags */
343 if (fdwPriority &
344 ~(ACM_DRIVERPRIORITYF_ENABLE|ACM_DRIVERPRIORITYF_DISABLE|
345 ACM_DRIVERPRIORITYF_BEGIN|ACM_DRIVERPRIORITYF_END))
346 return MMSYSERR_INVALFLAG;
348 /* Check for incompatible flags */
349 if ((fdwPriority & ACM_DRIVERPRIORITYF_ENABLE) &&
350 (fdwPriority & ACM_DRIVERPRIORITYF_DISABLE))
351 return MMSYSERR_INVALFLAG;
353 /* Check for incompatible flags */
354 if ((fdwPriority & ACM_DRIVERPRIORITYF_BEGIN) &&
355 (fdwPriority & ACM_DRIVERPRIORITYF_END))
356 return MMSYSERR_INVALFLAG;
358 lError = RegOpenKeyA(HKEY_CURRENT_USER,
359 "Software\\Microsoft\\Multimedia\\"
360 "Audio Compression Manager\\Priority v4.00",
361 &hPriorityKey
363 /* FIXME: Create key */
364 if (lError != ERROR_SUCCESS)
365 return MMSYSERR_ERROR;
367 for (dwPriorityCounter = 1; ; dwPriorityCounter++) {
368 snprintf(szSubKey, 17, "Priority%ld", dwPriorityCounter);
369 lError = RegQueryValueA(hPriorityKey, szSubKey, szBuffer, &lBufferLength);
370 if (lError != ERROR_SUCCESS)
371 break;
373 FIXME("(%p, %ld, %ld): stub (partial)\n",
374 hadid, dwPriority, fdwPriority);
375 break;
378 RegCloseKey(hPriorityKey);
380 return MMSYSERR_ERROR;
383 /***********************************************************************
384 * acmDriverRemove (MSACM32.@)
386 MMRESULT WINAPI acmDriverRemove(HACMDRIVERID hadid, DWORD fdwRemove)
388 PWINE_ACMDRIVERID padid;
390 padid = MSACM_GetDriverID(hadid);
391 if (!padid)
392 return MMSYSERR_INVALHANDLE;
394 if (fdwRemove)
395 return MMSYSERR_INVALFLAG;
397 MSACM_UnregisterDriver(padid);
399 return MMSYSERR_NOERROR;