2 * ICreateDevEnum implementation for DEVENUM.dll
4 * Copyright (C) 2002 Robert Shearman
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 * - Implements ICreateDevEnum interface which creates an IEnumMoniker
23 * - Also creates the special registry keys created at run-time
26 #include "devenum_private.h"
34 extern HINSTANCE DEVENUM_hInstance
;
36 const WCHAR wszInstanceKeyName
[] ={'\\','I','n','s','t','a','n','c','e',0};
38 static const WCHAR wszRegSeparator
[] = {'\\', 0 };
39 static const WCHAR wszActiveMovieKey
[] = {'S','o','f','t','w','a','r','e','\\',
40 'M','i','c','r','o','s','o','f','t','\\',
41 'A','c','t','i','v','e','M','o','v','i','e','\\',
42 'd','e','v','e','n','u','m','\\',0};
43 static const WCHAR wszFilterKeyName
[] = {'F','i','l','t','e','r',0};
44 static const WCHAR wszMeritName
[] = {'M','e','r','i','t',0};
45 static const WCHAR wszPins
[] = {'P','i','n','s',0};
46 static const WCHAR wszAllowedMany
[] = {'A','l','l','o','w','e','d','M','a','n','y',0};
47 static const WCHAR wszAllowedZero
[] = {'A','l','l','o','w','e','d','Z','e','r','o',0};
48 static const WCHAR wszDirection
[] = {'D','i','r','e','c','t','i','o','n',0};
49 static const WCHAR wszIsRendered
[] = {'I','s','R','e','n','d','e','r','e','d',0};
50 static const WCHAR wszTypes
[] = {'T','y','p','e','s',0};
51 static const WCHAR wszFriendlyName
[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
52 static const WCHAR wszWaveInID
[] = {'W','a','v','e','I','n','I','D',0};
53 static const WCHAR wszWaveOutID
[] = {'W','a','v','e','O','u','t','I','D',0};
55 static ULONG WINAPI
DEVENUM_ICreateDevEnum_AddRef(ICreateDevEnum
* iface
);
56 static HRESULT
DEVENUM_CreateSpecialCategories(void);
58 /**********************************************************************
59 * DEVENUM_ICreateDevEnum_QueryInterface (also IUnknown)
61 static HRESULT WINAPI
DEVENUM_ICreateDevEnum_QueryInterface(ICreateDevEnum
*iface
, REFIID riid
,
64 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
69 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
70 IsEqualGUID(riid
, &IID_ICreateDevEnum
))
73 DEVENUM_ICreateDevEnum_AddRef(iface
);
77 FIXME("- no interface IID: %s\n", debugstr_guid(riid
));
82 /**********************************************************************
83 * DEVENUM_ICreateDevEnum_AddRef (also IUnknown)
85 static ULONG WINAPI
DEVENUM_ICreateDevEnum_AddRef(ICreateDevEnum
* iface
)
91 return 2; /* non-heap based object */
94 /**********************************************************************
95 * DEVENUM_ICreateDevEnum_Release (also IUnknown)
97 static ULONG WINAPI
DEVENUM_ICreateDevEnum_Release(ICreateDevEnum
* iface
)
101 DEVENUM_UnlockModule();
103 return 1; /* non-heap based object */
106 static BOOL
IsSpecialCategory(const CLSID
*clsid
)
108 return IsEqualGUID(clsid
, &CLSID_AudioRendererCategory
) ||
109 IsEqualGUID(clsid
, &CLSID_AudioInputDeviceCategory
) ||
110 IsEqualGUID(clsid
, &CLSID_VideoInputDeviceCategory
) ||
111 IsEqualGUID(clsid
, &CLSID_VideoCompressorCategory
) ||
112 IsEqualGUID(clsid
, &CLSID_MidiRendererCategory
);
115 HRESULT
DEVENUM_GetCategoryKey(REFCLSID clsidDeviceClass
, HKEY
*pBaseKey
, WCHAR
*wszRegKeyName
, UINT maxLen
)
117 if (IsSpecialCategory(clsidDeviceClass
))
119 *pBaseKey
= HKEY_CURRENT_USER
;
120 strcpyW(wszRegKeyName
, wszActiveMovieKey
);
122 if (!StringFromGUID2(clsidDeviceClass
, wszRegKeyName
+ strlenW(wszRegKeyName
), maxLen
- strlenW(wszRegKeyName
)))
123 return E_OUTOFMEMORY
;
127 *pBaseKey
= HKEY_CLASSES_ROOT
;
128 strcpyW(wszRegKeyName
, clsid_keyname
);
129 strcatW(wszRegKeyName
, wszRegSeparator
);
131 if (!StringFromGUID2(clsidDeviceClass
, wszRegKeyName
+ CLSID_STR_LEN
, maxLen
- CLSID_STR_LEN
))
132 return E_OUTOFMEMORY
;
134 strcatW(wszRegKeyName
, wszInstanceKeyName
);
140 static HKEY
open_category_key(const CLSID
*clsid
)
142 WCHAR key_name
[sizeof(wszInstanceKeyName
)/sizeof(WCHAR
) + CHARS_IN_GUID
-1 + 6 /* strlen("CLSID\") */], *ptr
;
145 strcpyW(key_name
, clsid_keyname
);
146 ptr
= key_name
+ strlenW(key_name
);
149 if (!StringFromGUID2(clsid
, ptr
, CHARS_IN_GUID
))
153 strcpyW(ptr
, wszInstanceKeyName
);
155 if (RegOpenKeyExW(HKEY_CLASSES_ROOT
, key_name
, 0, KEY_READ
, &ret
) != ERROR_SUCCESS
) {
156 WARN("Could not open %s\n", debugstr_w(key_name
));
163 static HKEY
open_special_category_key(const CLSID
*clsid
, BOOL create
)
165 WCHAR key_name
[sizeof(wszActiveMovieKey
)/sizeof(WCHAR
) + CHARS_IN_GUID
-1];
169 strcpyW(key_name
, wszActiveMovieKey
);
170 if (!StringFromGUID2(clsid
, key_name
+ sizeof(wszActiveMovieKey
)/sizeof(WCHAR
)-1, CHARS_IN_GUID
))
174 res
= RegCreateKeyW(HKEY_CURRENT_USER
, key_name
, &ret
);
176 res
= RegOpenKeyExW(HKEY_CURRENT_USER
, key_name
, 0, KEY_READ
, &ret
);
177 if (res
!= ERROR_SUCCESS
) {
178 WARN("Could not open %s\n", debugstr_w(key_name
));
185 static void DEVENUM_ReadPinTypes(HKEY hkeyPinKey
, REGFILTERPINS
*rgPin
)
187 HKEY hkeyTypes
= NULL
;
188 DWORD dwMajorTypes
, i
;
189 REGPINTYPES
*lpMediaType
= NULL
;
190 DWORD dwMediaTypeSize
= 0;
192 if (RegOpenKeyExW(hkeyPinKey
, wszTypes
, 0, KEY_READ
, &hkeyTypes
) != ERROR_SUCCESS
)
195 if (RegQueryInfoKeyW(hkeyTypes
, NULL
, NULL
, NULL
, &dwMajorTypes
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
)
198 RegCloseKey(hkeyTypes
);
202 for (i
= 0; i
< dwMajorTypes
; i
++)
204 HKEY hkeyMajorType
= NULL
;
205 WCHAR wszMajorTypeName
[64];
206 DWORD cName
= sizeof(wszMajorTypeName
) / sizeof(WCHAR
);
207 DWORD dwMinorTypes
, i1
;
209 if (RegEnumKeyExW(hkeyTypes
, i
, wszMajorTypeName
, &cName
, NULL
, NULL
, NULL
, NULL
) != ERROR_SUCCESS
) continue;
211 if (RegOpenKeyExW(hkeyTypes
, wszMajorTypeName
, 0, KEY_READ
, &hkeyMajorType
) != ERROR_SUCCESS
) continue;
213 if (RegQueryInfoKeyW(hkeyMajorType
, NULL
, NULL
, NULL
, &dwMinorTypes
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
)
216 RegCloseKey(hkeyMajorType
);
220 for (i1
= 0; i1
< dwMinorTypes
; i1
++)
222 WCHAR wszMinorTypeName
[64];
223 CLSID
*clsMajorType
= NULL
, *clsMinorType
= NULL
;
226 cName
= sizeof(wszMinorTypeName
) / sizeof(WCHAR
);
227 if (RegEnumKeyExW(hkeyMajorType
, i1
, wszMinorTypeName
, &cName
, NULL
, NULL
, NULL
, NULL
) != ERROR_SUCCESS
) continue;
229 clsMinorType
= CoTaskMemAlloc(sizeof(CLSID
));
230 if (!clsMinorType
) continue;
232 clsMajorType
= CoTaskMemAlloc(sizeof(CLSID
));
233 if (!clsMajorType
) goto error_cleanup_types
;
235 hr
= CLSIDFromString(wszMinorTypeName
, clsMinorType
);
236 if (FAILED(hr
)) goto error_cleanup_types
;
238 hr
= CLSIDFromString(wszMajorTypeName
, clsMajorType
);
239 if (FAILED(hr
)) goto error_cleanup_types
;
241 if (rgPin
->nMediaTypes
== dwMediaTypeSize
)
243 DWORD dwNewSize
= dwMediaTypeSize
+ (dwMediaTypeSize
< 2 ? 1 : dwMediaTypeSize
/ 2);
244 REGPINTYPES
*lpNewMediaType
;
246 lpNewMediaType
= CoTaskMemRealloc(lpMediaType
, sizeof(REGPINTYPES
) * dwNewSize
);
247 if (!lpNewMediaType
) goto error_cleanup_types
;
249 lpMediaType
= lpNewMediaType
;
250 dwMediaTypeSize
= dwNewSize
;
253 lpMediaType
[rgPin
->nMediaTypes
].clsMajorType
= clsMajorType
;
254 lpMediaType
[rgPin
->nMediaTypes
].clsMinorType
= clsMinorType
;
255 rgPin
->nMediaTypes
++;
260 if (clsMajorType
) CoTaskMemFree(clsMajorType
);
261 if (clsMinorType
) CoTaskMemFree(clsMinorType
);
264 RegCloseKey(hkeyMajorType
);
267 RegCloseKey(hkeyTypes
);
269 if (lpMediaType
&& !rgPin
->nMediaTypes
)
271 CoTaskMemFree(lpMediaType
);
275 rgPin
->lpMediaType
= lpMediaType
;
278 static void DEVENUM_ReadPins(HKEY hkeyFilterClass
, REGFILTER2
*rgf2
)
280 HKEY hkeyPins
= NULL
;
281 DWORD dwPinsSubkeys
, i
;
282 REGFILTERPINS
*rgPins
= NULL
;
284 if (RegOpenKeyExW(hkeyFilterClass
, wszPins
, 0, KEY_READ
, &hkeyPins
) != ERROR_SUCCESS
)
287 if (RegQueryInfoKeyW(hkeyPins
, NULL
, NULL
, NULL
, &dwPinsSubkeys
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
)
290 RegCloseKey(hkeyPins
);
296 rgPins
= CoTaskMemAlloc(sizeof(REGFILTERPINS
) * dwPinsSubkeys
);
299 RegCloseKey(hkeyPins
);
304 for (i
= 0; i
< dwPinsSubkeys
; i
++)
306 HKEY hkeyPinKey
= NULL
;
307 WCHAR wszPinName
[MAX_PATH
];
308 DWORD cName
= sizeof(wszPinName
) / sizeof(WCHAR
);
310 REGFILTERPINS
*rgPin
= &rgPins
[rgf2
->u
.s1
.cPins
];
313 rgPin
->strName
= NULL
;
314 rgPin
->clsConnectsToFilter
= &GUID_NULL
;
315 rgPin
->strConnectsToPin
= NULL
;
316 rgPin
->nMediaTypes
= 0;
317 rgPin
->lpMediaType
= NULL
;
319 if (RegEnumKeyExW(hkeyPins
, i
, wszPinName
, &cName
, NULL
, NULL
, NULL
, NULL
) != ERROR_SUCCESS
) continue;
321 if (RegOpenKeyExW(hkeyPins
, wszPinName
, 0, KEY_READ
, &hkeyPinKey
) != ERROR_SUCCESS
) continue;
323 rgPin
->strName
= CoTaskMemAlloc((strlenW(wszPinName
) + 1) * sizeof(WCHAR
));
324 if (!rgPin
->strName
) goto error_cleanup
;
326 strcpyW(rgPin
->strName
, wszPinName
);
328 cbData
= sizeof(rgPin
->bMany
);
329 lRet
= RegQueryValueExW(hkeyPinKey
, wszAllowedMany
, NULL
, &Type
, (LPBYTE
)&rgPin
->bMany
, &cbData
);
330 if (lRet
!= ERROR_SUCCESS
|| Type
!= REG_DWORD
)
333 cbData
= sizeof(rgPin
->bZero
);
334 lRet
= RegQueryValueExW(hkeyPinKey
, wszAllowedZero
, NULL
, &Type
, (LPBYTE
)&rgPin
->bZero
, &cbData
);
335 if (lRet
!= ERROR_SUCCESS
|| Type
!= REG_DWORD
)
338 cbData
= sizeof(rgPin
->bOutput
);
339 lRet
= RegQueryValueExW(hkeyPinKey
, wszDirection
, NULL
, &Type
, (LPBYTE
)&rgPin
->bOutput
, &cbData
);
340 if (lRet
!= ERROR_SUCCESS
|| Type
!= REG_DWORD
)
343 cbData
= sizeof(rgPin
->bRendered
);
344 lRet
= RegQueryValueExW(hkeyPinKey
, wszIsRendered
, NULL
, &Type
, (LPBYTE
)&rgPin
->bRendered
, &cbData
);
345 if (lRet
!= ERROR_SUCCESS
|| Type
!= REG_DWORD
)
348 DEVENUM_ReadPinTypes(hkeyPinKey
, rgPin
);
355 RegCloseKey(hkeyPinKey
);
356 if (rgPin
->strName
) CoTaskMemFree(rgPin
->strName
);
359 RegCloseKey(hkeyPins
);
361 if (rgPins
&& !rgf2
->u
.s1
.cPins
)
363 CoTaskMemFree(rgPins
);
367 rgf2
->u
.s1
.rgPins
= rgPins
;
370 static HRESULT
DEVENUM_RegisterLegacyAmFilters(void)
372 HKEY hkeyFilter
= NULL
;
373 DWORD dwFilterSubkeys
, i
;
375 IFilterMapper2
*pMapper
= NULL
;
378 hr
= CoCreateInstance(&CLSID_FilterMapper2
, NULL
, CLSCTX_INPROC
,
379 &IID_IFilterMapper2
, (void **) &pMapper
);
382 lRet
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszFilterKeyName
, 0, KEY_READ
, &hkeyFilter
);
383 hr
= HRESULT_FROM_WIN32(lRet
);
388 lRet
= RegQueryInfoKeyW(hkeyFilter
, NULL
, NULL
, NULL
, &dwFilterSubkeys
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
389 hr
= HRESULT_FROM_WIN32(lRet
);
394 for (i
= 0; i
< dwFilterSubkeys
; i
++)
396 WCHAR wszFilterSubkeyName
[64];
397 DWORD cName
= sizeof(wszFilterSubkeyName
) / sizeof(WCHAR
);
398 HKEY hkeyCategoryBaseKey
;
399 WCHAR wszRegKey
[MAX_PATH
];
400 HKEY hkeyInstance
= NULL
;
402 if (RegEnumKeyExW(hkeyFilter
, i
, wszFilterSubkeyName
, &cName
, NULL
, NULL
, NULL
, NULL
) != ERROR_SUCCESS
) continue;
404 hr
= DEVENUM_GetCategoryKey(&CLSID_LegacyAmFilterCategory
, &hkeyCategoryBaseKey
, wszRegKey
, MAX_PATH
);
405 if (FAILED(hr
)) continue;
407 strcatW(wszRegKey
, wszRegSeparator
);
408 strcatW(wszRegKey
, wszFilterSubkeyName
);
410 if (RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszRegKey
, 0, KEY_READ
, &hkeyInstance
) == ERROR_SUCCESS
)
412 RegCloseKey(hkeyInstance
);
416 /* Filter is registered the IFilterMapper(1)-way in HKCR\Filter. Needs to be added to
417 * legacy am filter category. */
418 HKEY hkeyFilterClass
= NULL
;
421 WCHAR wszFilterName
[MAX_PATH
];
425 IMoniker
*pMoniker
= NULL
;
427 TRACE("Registering %s\n", debugstr_w(wszFilterSubkeyName
));
429 strcpyW(wszRegKey
, clsid_keyname
);
430 strcatW(wszRegKey
, wszRegSeparator
);
431 strcatW(wszRegKey
, wszFilterSubkeyName
);
433 if (RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszRegKey
, 0, KEY_READ
, &hkeyFilterClass
) != ERROR_SUCCESS
)
439 rgf2
.u
.s1
.rgPins
= NULL
;
441 cbData
= sizeof(wszFilterName
);
442 if (RegQueryValueExW(hkeyFilterClass
, NULL
, NULL
, &Type
, (LPBYTE
)wszFilterName
, &cbData
) != ERROR_SUCCESS
||
446 cbData
= sizeof(rgf2
.dwMerit
);
447 if (RegQueryValueExW(hkeyFilterClass
, wszMeritName
, NULL
, &Type
, (LPBYTE
)&rgf2
.dwMerit
, &cbData
) != ERROR_SUCCESS
||
451 DEVENUM_ReadPins(hkeyFilterClass
, &rgf2
);
453 res
= CLSIDFromString(wszFilterSubkeyName
, &clsidFilter
);
454 if (FAILED(res
)) goto cleanup
;
456 IFilterMapper2_RegisterFilter(pMapper
, &clsidFilter
, wszFilterName
, &pMoniker
, NULL
, NULL
, &rgf2
);
459 IMoniker_Release(pMoniker
);
463 if (hkeyFilterClass
) RegCloseKey(hkeyFilterClass
);
465 if (rgf2
.u
.s1
.rgPins
)
469 for (iPin
= 0; iPin
< rgf2
.u
.s1
.cPins
; iPin
++)
471 CoTaskMemFree(rgf2
.u
.s1
.rgPins
[iPin
].strName
);
473 if (rgf2
.u
.s1
.rgPins
[iPin
].lpMediaType
)
477 for (iType
= 0; iType
< rgf2
.u
.s1
.rgPins
[iPin
].nMediaTypes
; iType
++)
479 CoTaskMemFree((void*)rgf2
.u
.s1
.rgPins
[iPin
].lpMediaType
[iType
].clsMajorType
);
480 CoTaskMemFree((void*)rgf2
.u
.s1
.rgPins
[iPin
].lpMediaType
[iType
].clsMinorType
);
483 CoTaskMemFree((void*)rgf2
.u
.s1
.rgPins
[iPin
].lpMediaType
);
487 CoTaskMemFree((void*)rgf2
.u
.s1
.rgPins
);
493 if (hkeyFilter
) RegCloseKey(hkeyFilter
);
496 IFilterMapper2_Release(pMapper
);
501 /**********************************************************************
502 * DEVENUM_ICreateDevEnum_CreateClassEnumerator
504 static HRESULT WINAPI
DEVENUM_ICreateDevEnum_CreateClassEnumerator(
505 ICreateDevEnum
* iface
,
506 REFCLSID clsidDeviceClass
,
507 IEnumMoniker
**ppEnumMoniker
,
510 HKEY hkey
, special_hkey
= NULL
;
513 TRACE("(%p)->(%s, %p, %x)\n", iface
, debugstr_guid(clsidDeviceClass
), ppEnumMoniker
, dwFlags
);
518 *ppEnumMoniker
= NULL
;
520 if (IsEqualGUID(clsidDeviceClass
, &CLSID_LegacyAmFilterCategory
))
522 DEVENUM_RegisterLegacyAmFilters();
525 if (IsSpecialCategory(clsidDeviceClass
))
527 hr
= DEVENUM_CreateSpecialCategories();
531 special_hkey
= open_special_category_key(clsidDeviceClass
, FALSE
);
534 ERR("Couldn't open registry key for special device: %s\n",
535 debugstr_guid(clsidDeviceClass
));
540 hkey
= open_category_key(clsidDeviceClass
);
541 if (!hkey
&& !special_hkey
)
543 FIXME("Category %s not found\n", debugstr_guid(clsidDeviceClass
));
547 return DEVENUM_IEnumMoniker_Construct(hkey
, special_hkey
, ppEnumMoniker
);
550 /**********************************************************************
551 * ICreateDevEnum_Vtbl
553 static const ICreateDevEnumVtbl ICreateDevEnum_Vtbl
=
555 DEVENUM_ICreateDevEnum_QueryInterface
,
556 DEVENUM_ICreateDevEnum_AddRef
,
557 DEVENUM_ICreateDevEnum_Release
,
558 DEVENUM_ICreateDevEnum_CreateClassEnumerator
,
561 /**********************************************************************
562 * static CreateDevEnum instance
564 ICreateDevEnum DEVENUM_CreateDevEnum
= { &ICreateDevEnum_Vtbl
};
566 /**********************************************************************
567 * DEVENUM_CreateAMCategoryKey (INTERNAL)
569 * Creates a registry key for a category at HKEY_CURRENT_USER\Software\
570 * Microsoft\ActiveMovie\devenum\{clsid}
572 static HRESULT
DEVENUM_CreateAMCategoryKey(const CLSID
* clsidCategory
)
574 WCHAR wszRegKey
[MAX_PATH
];
576 HKEY hkeyDummy
= NULL
;
578 strcpyW(wszRegKey
, wszActiveMovieKey
);
580 if (!StringFromGUID2(clsidCategory
, wszRegKey
+ strlenW(wszRegKey
), sizeof(wszRegKey
)/sizeof(wszRegKey
[0]) - strlenW(wszRegKey
)))
585 LONG lRes
= RegCreateKeyW(HKEY_CURRENT_USER
, wszRegKey
, &hkeyDummy
);
586 res
= HRESULT_FROM_WIN32(lRes
);
590 RegCloseKey(hkeyDummy
);
593 ERR("Failed to create key HKEY_CURRENT_USER\\%s\n", debugstr_w(wszRegKey
));
598 static void register_vfw_codecs(void)
600 WCHAR avico_clsid_str
[CHARS_IN_GUID
];
605 static const WCHAR CLSIDW
[] = {'C','L','S','I','D',0};
606 static const WCHAR FccHandlerW
[] = {'F','c','c','H','a','n','d','l','e','r',0};
607 static const WCHAR FriendlyNameW
[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
609 StringFromGUID2(&CLSID_AVICo
, avico_clsid_str
, sizeof(avico_clsid_str
)/sizeof(WCHAR
));
611 basekey
= open_special_category_key(&CLSID_VideoCompressorCategory
, TRUE
);
613 ERR("Could not create key\n");
617 for(i
=0; ICInfo(FCC('v','i','d','c'), i
, &icinfo
); i
++) {
618 WCHAR fcc_str
[5] = {LOBYTE(LOWORD(icinfo
.fccHandler
)), HIBYTE(LOWORD(icinfo
.fccHandler
)),
619 LOBYTE(HIWORD(icinfo
.fccHandler
)), HIBYTE(HIWORD(icinfo
.fccHandler
))};
621 res
= RegCreateKeyW(basekey
, fcc_str
, &key
);
622 if(res
!= ERROR_SUCCESS
)
625 RegSetValueExW(key
, CLSIDW
, 0, REG_SZ
, (const BYTE
*)avico_clsid_str
, sizeof(avico_clsid_str
));
626 RegSetValueExW(key
, FccHandlerW
, 0, REG_SZ
, (const BYTE
*)fcc_str
, sizeof(fcc_str
));
627 RegSetValueExW(key
, FriendlyNameW
, 0, REG_SZ
, (const BYTE
*)icinfo
.szName
, (strlenW(icinfo
.szName
)+1)*sizeof(WCHAR
));
628 /* FIXME: Set ClassManagerFlags and FilterData values */
633 RegCloseKey(basekey
);
636 static HANDLE DEVENUM_populate_handle
;
637 static const WCHAR DEVENUM_populate_handle_nameW
[] =
638 {'_','_','W','I','N','E','_',
639 'D','e','v','e','n','u','m','_',
640 'P','o','p','u','l','a','t','e',0};
642 /**********************************************************************
643 * DEVENUM_CreateSpecialCategories (INTERNAL)
645 * Creates the keys in the registry for the dynamic categories
647 static HRESULT
DEVENUM_CreateSpecialCategories(void)
650 WCHAR szDSoundNameFormat
[MAX_PATH
+ 1];
651 WCHAR szDSoundName
[MAX_PATH
+ 1];
652 DWORD iDefaultDevice
= -1;
654 IFilterMapper2
* pMapper
= NULL
;
657 WCHAR path
[MAX_PATH
];
660 if (DEVENUM_populate_handle
)
662 DEVENUM_populate_handle
= CreateEventW(NULL
, TRUE
, FALSE
, DEVENUM_populate_handle_nameW
);
663 if (GetLastError() == ERROR_ALREADY_EXISTS
)
665 /* Webcams can take some time to scan if the driver is badly written and it enables them,
666 * so have a 10 s timeout here
668 if (WaitForSingleObject(DEVENUM_populate_handle
, 10000) == WAIT_TIMEOUT
)
669 WARN("Waiting for object timed out\n");
670 TRACE("No need to rescan\n");
673 TRACE("Scanning for devices\n");
675 /* Since devices can change between session, for example because you just plugged in a webcam
676 * or switched from pulseaudio to alsa, delete all old devices first
678 if (SUCCEEDED(DEVENUM_GetCategoryKey(&CLSID_AudioRendererCategory
, &basekey
, path
, MAX_PATH
)))
679 SHDeleteKeyW(basekey
, path
);
680 if (SUCCEEDED(DEVENUM_GetCategoryKey(&CLSID_AudioInputDeviceCategory
, &basekey
, path
, MAX_PATH
)))
681 SHDeleteKeyW(basekey
, path
);
682 if (SUCCEEDED(DEVENUM_GetCategoryKey(&CLSID_VideoInputDeviceCategory
, &basekey
, path
, MAX_PATH
)))
683 SHDeleteKeyW(basekey
, path
);
684 if (SUCCEEDED(DEVENUM_GetCategoryKey(&CLSID_MidiRendererCategory
, &basekey
, path
, MAX_PATH
)))
685 SHDeleteKeyW(basekey
, path
);
686 if (SUCCEEDED(DEVENUM_GetCategoryKey(&CLSID_VideoCompressorCategory
, &basekey
, path
, MAX_PATH
)))
687 SHDeleteKeyW(basekey
, path
);
690 rf2
.dwMerit
= MERIT_PREFERRED
;
692 rf2
.u
.s2
.rgPins2
= &rfp2
;
695 rfp2
.lpMedium
= NULL
;
696 rfp2
.clsPinCategory
= &IID_NULL
;
698 if (!LoadStringW(DEVENUM_hInstance
, IDS_DEVENUM_DS
, szDSoundNameFormat
, sizeof(szDSoundNameFormat
)/sizeof(szDSoundNameFormat
[0])-1))
700 ERR("Couldn't get string resource (GetLastError() is %d)\n", GetLastError());
701 return HRESULT_FROM_WIN32(GetLastError());
704 res
= CoCreateInstance(&CLSID_FilterMapper2
, NULL
, CLSCTX_INPROC
,
705 &IID_IFilterMapper2
, (void **) &pMapper
);
707 * Fill in info for devices
715 REGPINTYPES
* pTypes
;
716 IPropertyBag
* pPropBag
= NULL
;
718 numDevs
= waveOutGetNumDevs();
720 res
= DEVENUM_CreateAMCategoryKey(&CLSID_AudioRendererCategory
);
721 if (FAILED(res
)) /* can't register any devices in this category */
724 rfp2
.dwFlags
= REG_PINFLAG_B_RENDERER
;
725 for (i
= 0; i
< numDevs
; i
++)
727 if (waveOutGetDevCapsW(i
, &wocaps
, sizeof(WAVEOUTCAPSW
))
730 IMoniker
* pMoniker
= NULL
;
732 rfp2
.nMediaTypes
= 1;
733 pTypes
= CoTaskMemAlloc(rfp2
.nMediaTypes
* sizeof(REGPINTYPES
));
736 IFilterMapper2_Release(pMapper
);
737 return E_OUTOFMEMORY
;
739 /* FIXME: Native devenum seems to register a lot more types for
740 * DSound than we do. Not sure what purpose they serve */
741 pTypes
[0].clsMajorType
= &MEDIATYPE_Audio
;
742 pTypes
[0].clsMinorType
= &MEDIASUBTYPE_PCM
;
744 rfp2
.lpMediaType
= pTypes
;
746 res
= IFilterMapper2_RegisterFilter(pMapper
,
750 &CLSID_AudioRendererCategory
,
760 res
= IMoniker_BindToStorage(pMoniker
, NULL
, NULL
, &IID_IPropertyBag
, (LPVOID
)&pPropBag
);
762 res
= IPropertyBag_Write(pPropBag
, wszWaveOutID
, &var
);
766 V_VT(&var
) = VT_LPWSTR
;
767 V_BSTR(&var
) = wocaps
.szPname
;
769 res
= IPropertyBag_Write(pPropBag
, wszFriendlyName
, &var
);
771 IPropertyBag_Release(pPropBag
);
772 IMoniker_Release(pMoniker
);
776 wsprintfW(szDSoundName
, szDSoundNameFormat
, wocaps
.szPname
);
777 res
= IFilterMapper2_RegisterFilter(pMapper
,
781 &CLSID_AudioRendererCategory
,
785 /* FIXME: do additional stuff with IMoniker here, depending on what RegisterFilter does */
788 IMoniker_Release(pMoniker
);
790 if (i
== iDefaultDevice
)
792 FIXME("Default device\n");
795 CoTaskMemFree(pTypes
);
799 numDevs
= waveInGetNumDevs();
801 res
= DEVENUM_CreateAMCategoryKey(&CLSID_AudioInputDeviceCategory
);
802 if (FAILED(res
)) /* can't register any devices in this category */
805 rfp2
.dwFlags
= REG_PINFLAG_B_OUTPUT
;
806 for (i
= 0; i
< numDevs
; i
++)
808 if (waveInGetDevCapsW(i
, &wicaps
, sizeof(WAVEINCAPSW
))
811 IMoniker
* pMoniker
= NULL
;
813 rfp2
.nMediaTypes
= 1;
814 pTypes
= CoTaskMemAlloc(rfp2
.nMediaTypes
* sizeof(REGPINTYPES
));
817 IFilterMapper2_Release(pMapper
);
818 return E_OUTOFMEMORY
;
821 /* FIXME: Not sure if these are correct */
822 pTypes
[0].clsMajorType
= &MEDIATYPE_Audio
;
823 pTypes
[0].clsMinorType
= &MEDIASUBTYPE_PCM
;
825 rfp2
.lpMediaType
= pTypes
;
827 res
= IFilterMapper2_RegisterFilter(pMapper
,
831 &CLSID_AudioInputDeviceCategory
,
841 res
= IMoniker_BindToStorage(pMoniker
, NULL
, NULL
, &IID_IPropertyBag
, (LPVOID
)&pPropBag
);
843 res
= IPropertyBag_Write(pPropBag
, wszWaveInID
, &var
);
847 V_VT(&var
) = VT_LPWSTR
;
848 V_BSTR(&var
) = wicaps
.szPname
;
850 res
= IPropertyBag_Write(pPropBag
, wszFriendlyName
, &var
);
853 IPropertyBag_Release(pPropBag
);
854 IMoniker_Release(pMoniker
);
857 CoTaskMemFree(pTypes
);
861 numDevs
= midiOutGetNumDevs();
863 res
= DEVENUM_CreateAMCategoryKey(&CLSID_MidiRendererCategory
);
864 if (FAILED(res
)) /* can't register any devices in this category */
867 rfp2
.dwFlags
= REG_PINFLAG_B_RENDERER
;
868 for (i
= 0; i
< numDevs
; i
++)
870 if (midiOutGetDevCapsW(i
, &mocaps
, sizeof(MIDIOUTCAPSW
))
873 IMoniker
* pMoniker
= NULL
;
875 rfp2
.nMediaTypes
= 1;
876 pTypes
= CoTaskMemAlloc(rfp2
.nMediaTypes
* sizeof(REGPINTYPES
));
879 IFilterMapper2_Release(pMapper
);
880 return E_OUTOFMEMORY
;
883 /* FIXME: Not sure if these are correct */
884 pTypes
[0].clsMajorType
= &MEDIATYPE_Midi
;
885 pTypes
[0].clsMinorType
= &MEDIASUBTYPE_None
;
887 rfp2
.lpMediaType
= pTypes
;
889 res
= IFilterMapper2_RegisterFilter(pMapper
,
890 &CLSID_AVIMIDIRender
,
893 &CLSID_MidiRendererCategory
,
897 /* FIXME: do additional stuff with IMoniker here, depending on what RegisterFilter does */
898 /* Native version sets MidiOutId */
901 IMoniker_Release(pMoniker
);
903 if (i
== iDefaultDevice
)
905 FIXME("Default device\n");
908 CoTaskMemFree(pTypes
);
911 res
= DEVENUM_CreateAMCategoryKey(&CLSID_VideoInputDeviceCategory
);
913 for (i
= 0; i
< 10; i
++)
915 WCHAR szDeviceName
[32], szDeviceVersion
[32], szDevicePath
[10];
917 if (capGetDriverDescriptionW ((WORD
) i
,
918 szDeviceName
, sizeof(szDeviceName
)/sizeof(WCHAR
),
919 szDeviceVersion
, sizeof(szDeviceVersion
)/sizeof(WCHAR
)))
921 IMoniker
* pMoniker
= NULL
;
922 WCHAR dprintf
[] = { 'v','i','d','e','o','%','d',0 };
923 snprintfW(szDevicePath
, sizeof(szDevicePath
)/sizeof(WCHAR
), dprintf
, i
);
924 /* The above code prevents 1 device with a different ID overwriting another */
926 rfp2
.nMediaTypes
= 1;
927 pTypes
= CoTaskMemAlloc(rfp2
.nMediaTypes
* sizeof(REGPINTYPES
));
929 IFilterMapper2_Release(pMapper
);
930 return E_OUTOFMEMORY
;
933 pTypes
[0].clsMajorType
= &MEDIATYPE_Video
;
934 pTypes
[0].clsMinorType
= &MEDIASUBTYPE_None
;
936 rfp2
.lpMediaType
= pTypes
;
938 res
= IFilterMapper2_RegisterFilter(pMapper
,
942 &CLSID_VideoInputDeviceCategory
,
947 OLECHAR wszVfwIndex
[] = { 'V','F','W','I','n','d','e','x',0 };
951 res
= IMoniker_BindToStorage(pMoniker
, NULL
, NULL
, &IID_IPropertyBag
, (LPVOID
)&pPropBag
);
952 if (SUCCEEDED(res
)) {
953 res
= IPropertyBag_Write(pPropBag
, wszVfwIndex
, &var
);
954 IPropertyBag_Release(pPropBag
);
956 IMoniker_Release(pMoniker
);
959 if (i
== iDefaultDevice
) FIXME("Default device\n");
960 CoTaskMemFree(pTypes
);
966 IFilterMapper2_Release(pMapper
);
968 register_vfw_codecs();
970 SetEvent(DEVENUM_populate_handle
);