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 #define NONAMELESSSTRUCT
27 #define NONAMELESSUNION
29 #include "devenum_private.h"
33 #include "wine/debug.h"
34 #include "wine/unicode.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(devenum
);
39 extern HINSTANCE DEVENUM_hInstance
;
41 const WCHAR wszInstanceKeyName
[] ={'\\','I','n','s','t','a','n','c','e',0};
43 static const WCHAR wszRegSeparator
[] = {'\\', 0 };
44 static const WCHAR wszActiveMovieKey
[] = {'S','o','f','t','w','a','r','e','\\',
45 'M','i','c','r','o','s','o','f','t','\\',
46 'A','c','t','i','v','e','M','o','v','i','e','\\',
47 'd','e','v','e','n','u','m','\\',0};
48 static const WCHAR wszFilterKeyName
[] = {'F','i','l','t','e','r',0};
49 static const WCHAR wszMeritName
[] = {'M','e','r','i','t',0};
50 static const WCHAR wszPins
[] = {'P','i','n','s',0};
51 static const WCHAR wszAllowedMany
[] = {'A','l','l','o','w','e','d','M','a','n','y',0};
52 static const WCHAR wszAllowedZero
[] = {'A','l','l','o','w','e','d','Z','e','r','o',0};
53 static const WCHAR wszDirection
[] = {'D','i','r','e','c','t','i','o','n',0};
54 static const WCHAR wszIsRendered
[] = {'I','s','R','e','n','d','e','r','e','d',0};
55 static const WCHAR wszTypes
[] = {'T','y','p','e','s',0};
56 static const WCHAR wszFriendlyName
[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
57 static const WCHAR wszWaveInID
[] = {'W','a','v','e','I','n','I','D',0};
58 static const WCHAR wszWaveOutID
[] = {'W','a','v','e','O','u','t','I','D',0};
60 static ULONG WINAPI
DEVENUM_ICreateDevEnum_AddRef(ICreateDevEnum
* iface
);
61 static HRESULT
DEVENUM_CreateSpecialCategories(void);
63 /**********************************************************************
64 * DEVENUM_ICreateDevEnum_QueryInterface (also IUnknown)
66 static HRESULT WINAPI
DEVENUM_ICreateDevEnum_QueryInterface(ICreateDevEnum
*iface
, REFIID riid
,
69 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
74 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
75 IsEqualGUID(riid
, &IID_ICreateDevEnum
))
78 DEVENUM_ICreateDevEnum_AddRef(iface
);
82 FIXME("- no interface IID: %s\n", debugstr_guid(riid
));
87 /**********************************************************************
88 * DEVENUM_ICreateDevEnum_AddRef (also IUnknown)
90 static ULONG WINAPI
DEVENUM_ICreateDevEnum_AddRef(ICreateDevEnum
* iface
)
96 return 2; /* non-heap based object */
99 /**********************************************************************
100 * DEVENUM_ICreateDevEnum_Release (also IUnknown)
102 static ULONG WINAPI
DEVENUM_ICreateDevEnum_Release(ICreateDevEnum
* iface
)
106 DEVENUM_UnlockModule();
108 return 1; /* non-heap based object */
111 static BOOL
IsSpecialCategory(const CLSID
*clsid
)
113 return IsEqualGUID(clsid
, &CLSID_AudioRendererCategory
) ||
114 IsEqualGUID(clsid
, &CLSID_AudioInputDeviceCategory
) ||
115 IsEqualGUID(clsid
, &CLSID_VideoInputDeviceCategory
) ||
116 IsEqualGUID(clsid
, &CLSID_VideoCompressorCategory
) ||
117 IsEqualGUID(clsid
, &CLSID_MidiRendererCategory
);
120 HRESULT
DEVENUM_GetCategoryKey(REFCLSID clsidDeviceClass
, HKEY
*pBaseKey
, WCHAR
*wszRegKeyName
, UINT maxLen
)
122 if (IsSpecialCategory(clsidDeviceClass
))
124 *pBaseKey
= HKEY_CURRENT_USER
;
125 strcpyW(wszRegKeyName
, wszActiveMovieKey
);
127 if (!StringFromGUID2(clsidDeviceClass
, wszRegKeyName
+ strlenW(wszRegKeyName
), maxLen
- strlenW(wszRegKeyName
)))
128 return E_OUTOFMEMORY
;
132 *pBaseKey
= HKEY_CLASSES_ROOT
;
133 strcpyW(wszRegKeyName
, clsid_keyname
);
134 strcatW(wszRegKeyName
, wszRegSeparator
);
136 if (!StringFromGUID2(clsidDeviceClass
, wszRegKeyName
+ CLSID_STR_LEN
, maxLen
- CLSID_STR_LEN
))
137 return E_OUTOFMEMORY
;
139 strcatW(wszRegKeyName
, wszInstanceKeyName
);
145 static HKEY
open_category_key(const CLSID
*clsid
)
147 WCHAR key_name
[sizeof(wszInstanceKeyName
)/sizeof(WCHAR
) + CHARS_IN_GUID
-1 + 6 /* strlen("CLSID\") */], *ptr
;
150 strcpyW(key_name
, clsid_keyname
);
151 ptr
= key_name
+ strlenW(key_name
);
154 if (!StringFromGUID2(clsid
, ptr
, CHARS_IN_GUID
))
158 strcpyW(ptr
, wszInstanceKeyName
);
160 if (RegOpenKeyExW(HKEY_CLASSES_ROOT
, key_name
, 0, KEY_READ
, &ret
) != ERROR_SUCCESS
) {
161 WARN("Could not open %s\n", debugstr_w(key_name
));
168 static HKEY
open_special_category_key(const CLSID
*clsid
, BOOL create
)
170 WCHAR key_name
[sizeof(wszActiveMovieKey
)/sizeof(WCHAR
) + CHARS_IN_GUID
-1];
174 strcpyW(key_name
, wszActiveMovieKey
);
175 if (!StringFromGUID2(clsid
, key_name
+ sizeof(wszActiveMovieKey
)/sizeof(WCHAR
)-1, CHARS_IN_GUID
))
179 res
= RegCreateKeyW(HKEY_CURRENT_USER
, key_name
, &ret
);
181 res
= RegOpenKeyExW(HKEY_CURRENT_USER
, key_name
, 0, KEY_READ
, &ret
);
182 if (res
!= ERROR_SUCCESS
) {
183 WARN("Could not open %s\n", debugstr_w(key_name
));
190 static void DEVENUM_ReadPinTypes(HKEY hkeyPinKey
, REGFILTERPINS
*rgPin
)
192 HKEY hkeyTypes
= NULL
;
193 DWORD dwMajorTypes
, i
;
194 REGPINTYPES
*lpMediaType
= NULL
;
195 DWORD dwMediaTypeSize
= 0;
197 if (RegOpenKeyExW(hkeyPinKey
, wszTypes
, 0, KEY_READ
, &hkeyTypes
) != ERROR_SUCCESS
)
200 if (RegQueryInfoKeyW(hkeyTypes
, NULL
, NULL
, NULL
, &dwMajorTypes
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
)
203 RegCloseKey(hkeyTypes
);
207 for (i
= 0; i
< dwMajorTypes
; i
++)
209 HKEY hkeyMajorType
= NULL
;
210 WCHAR wszMajorTypeName
[64];
211 DWORD cName
= sizeof(wszMajorTypeName
) / sizeof(WCHAR
);
212 DWORD dwMinorTypes
, i1
;
214 if (RegEnumKeyExW(hkeyTypes
, i
, wszMajorTypeName
, &cName
, NULL
, NULL
, NULL
, NULL
) != ERROR_SUCCESS
) continue;
216 if (RegOpenKeyExW(hkeyTypes
, wszMajorTypeName
, 0, KEY_READ
, &hkeyMajorType
) != ERROR_SUCCESS
) continue;
218 if (RegQueryInfoKeyW(hkeyMajorType
, NULL
, NULL
, NULL
, &dwMinorTypes
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
)
221 RegCloseKey(hkeyMajorType
);
225 for (i1
= 0; i1
< dwMinorTypes
; i1
++)
227 WCHAR wszMinorTypeName
[64];
228 CLSID
*clsMajorType
= NULL
, *clsMinorType
= NULL
;
231 cName
= sizeof(wszMinorTypeName
) / sizeof(WCHAR
);
232 if (RegEnumKeyExW(hkeyMajorType
, i1
, wszMinorTypeName
, &cName
, NULL
, NULL
, NULL
, NULL
) != ERROR_SUCCESS
) continue;
234 clsMinorType
= CoTaskMemAlloc(sizeof(CLSID
));
235 if (!clsMinorType
) continue;
237 clsMajorType
= CoTaskMemAlloc(sizeof(CLSID
));
238 if (!clsMajorType
) goto error_cleanup_types
;
240 hr
= CLSIDFromString(wszMinorTypeName
, clsMinorType
);
241 if (FAILED(hr
)) goto error_cleanup_types
;
243 hr
= CLSIDFromString(wszMajorTypeName
, clsMajorType
);
244 if (FAILED(hr
)) goto error_cleanup_types
;
246 if (rgPin
->nMediaTypes
== dwMediaTypeSize
)
248 DWORD dwNewSize
= dwMediaTypeSize
+ (dwMediaTypeSize
< 2 ? 1 : dwMediaTypeSize
/ 2);
249 REGPINTYPES
*lpNewMediaType
;
251 lpNewMediaType
= CoTaskMemRealloc(lpMediaType
, sizeof(REGPINTYPES
) * dwNewSize
);
252 if (!lpNewMediaType
) goto error_cleanup_types
;
254 lpMediaType
= lpNewMediaType
;
255 dwMediaTypeSize
= dwNewSize
;
258 lpMediaType
[rgPin
->nMediaTypes
].clsMajorType
= clsMajorType
;
259 lpMediaType
[rgPin
->nMediaTypes
].clsMinorType
= clsMinorType
;
260 rgPin
->nMediaTypes
++;
265 CoTaskMemFree(clsMajorType
);
266 CoTaskMemFree(clsMinorType
);
269 RegCloseKey(hkeyMajorType
);
272 RegCloseKey(hkeyTypes
);
274 if (lpMediaType
&& !rgPin
->nMediaTypes
)
276 CoTaskMemFree(lpMediaType
);
280 rgPin
->lpMediaType
= lpMediaType
;
283 static void DEVENUM_ReadPins(HKEY hkeyFilterClass
, REGFILTER2
*rgf2
)
285 HKEY hkeyPins
= NULL
;
286 DWORD dwPinsSubkeys
, i
;
287 REGFILTERPINS
*rgPins
= NULL
;
289 if (RegOpenKeyExW(hkeyFilterClass
, wszPins
, 0, KEY_READ
, &hkeyPins
) != ERROR_SUCCESS
)
292 if (RegQueryInfoKeyW(hkeyPins
, NULL
, NULL
, NULL
, &dwPinsSubkeys
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
)
295 RegCloseKey(hkeyPins
);
301 rgPins
= CoTaskMemAlloc(sizeof(REGFILTERPINS
) * dwPinsSubkeys
);
304 RegCloseKey(hkeyPins
);
309 for (i
= 0; i
< dwPinsSubkeys
; i
++)
311 HKEY hkeyPinKey
= NULL
;
312 WCHAR wszPinName
[MAX_PATH
];
313 DWORD cName
= sizeof(wszPinName
) / sizeof(WCHAR
);
315 REGFILTERPINS
*rgPin
= &rgPins
[rgf2
->u
.s1
.cPins
];
318 rgPin
->strName
= NULL
;
319 rgPin
->clsConnectsToFilter
= &GUID_NULL
;
320 rgPin
->strConnectsToPin
= NULL
;
321 rgPin
->nMediaTypes
= 0;
322 rgPin
->lpMediaType
= NULL
;
324 if (RegEnumKeyExW(hkeyPins
, i
, wszPinName
, &cName
, NULL
, NULL
, NULL
, NULL
) != ERROR_SUCCESS
) continue;
326 if (RegOpenKeyExW(hkeyPins
, wszPinName
, 0, KEY_READ
, &hkeyPinKey
) != ERROR_SUCCESS
) continue;
328 rgPin
->strName
= CoTaskMemAlloc((strlenW(wszPinName
) + 1) * sizeof(WCHAR
));
329 if (!rgPin
->strName
) goto error_cleanup
;
331 strcpyW(rgPin
->strName
, wszPinName
);
333 cbData
= sizeof(rgPin
->bMany
);
334 lRet
= RegQueryValueExW(hkeyPinKey
, wszAllowedMany
, NULL
, &Type
, (LPBYTE
)&rgPin
->bMany
, &cbData
);
335 if (lRet
!= ERROR_SUCCESS
|| Type
!= REG_DWORD
)
338 cbData
= sizeof(rgPin
->bZero
);
339 lRet
= RegQueryValueExW(hkeyPinKey
, wszAllowedZero
, NULL
, &Type
, (LPBYTE
)&rgPin
->bZero
, &cbData
);
340 if (lRet
!= ERROR_SUCCESS
|| Type
!= REG_DWORD
)
343 cbData
= sizeof(rgPin
->bOutput
);
344 lRet
= RegQueryValueExW(hkeyPinKey
, wszDirection
, NULL
, &Type
, (LPBYTE
)&rgPin
->bOutput
, &cbData
);
345 if (lRet
!= ERROR_SUCCESS
|| Type
!= REG_DWORD
)
348 cbData
= sizeof(rgPin
->bRendered
);
349 lRet
= RegQueryValueExW(hkeyPinKey
, wszIsRendered
, NULL
, &Type
, (LPBYTE
)&rgPin
->bRendered
, &cbData
);
350 if (lRet
!= ERROR_SUCCESS
|| Type
!= REG_DWORD
)
353 DEVENUM_ReadPinTypes(hkeyPinKey
, rgPin
);
360 RegCloseKey(hkeyPinKey
);
361 CoTaskMemFree(rgPin
->strName
);
364 RegCloseKey(hkeyPins
);
366 if (rgPins
&& !rgf2
->u
.s1
.cPins
)
368 CoTaskMemFree(rgPins
);
372 rgf2
->u
.s1
.rgPins
= rgPins
;
375 static HRESULT
DEVENUM_RegisterLegacyAmFilters(void)
377 HKEY hkeyFilter
= NULL
;
378 DWORD dwFilterSubkeys
, i
;
380 IFilterMapper2
*pMapper
= NULL
;
383 hr
= CoCreateInstance(&CLSID_FilterMapper2
, NULL
, CLSCTX_INPROC
,
384 &IID_IFilterMapper2
, (void **) &pMapper
);
387 lRet
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszFilterKeyName
, 0, KEY_READ
, &hkeyFilter
);
388 hr
= HRESULT_FROM_WIN32(lRet
);
393 lRet
= RegQueryInfoKeyW(hkeyFilter
, NULL
, NULL
, NULL
, &dwFilterSubkeys
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
394 hr
= HRESULT_FROM_WIN32(lRet
);
399 for (i
= 0; i
< dwFilterSubkeys
; i
++)
401 WCHAR wszFilterSubkeyName
[64];
402 DWORD cName
= sizeof(wszFilterSubkeyName
) / sizeof(WCHAR
);
403 HKEY hkeyCategoryBaseKey
;
404 WCHAR wszRegKey
[MAX_PATH
];
405 HKEY hkeyInstance
= NULL
;
407 if (RegEnumKeyExW(hkeyFilter
, i
, wszFilterSubkeyName
, &cName
, NULL
, NULL
, NULL
, NULL
) != ERROR_SUCCESS
) continue;
409 hr
= DEVENUM_GetCategoryKey(&CLSID_LegacyAmFilterCategory
, &hkeyCategoryBaseKey
, wszRegKey
, MAX_PATH
);
410 if (FAILED(hr
)) continue;
412 strcatW(wszRegKey
, wszRegSeparator
);
413 strcatW(wszRegKey
, wszFilterSubkeyName
);
415 if (RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszRegKey
, 0, KEY_READ
, &hkeyInstance
) == ERROR_SUCCESS
)
417 RegCloseKey(hkeyInstance
);
421 /* Filter is registered the IFilterMapper(1)-way in HKCR\Filter. Needs to be added to
422 * legacy am filter category. */
423 HKEY hkeyFilterClass
= NULL
;
426 WCHAR wszFilterName
[MAX_PATH
];
430 IMoniker
*pMoniker
= NULL
;
432 TRACE("Registering %s\n", debugstr_w(wszFilterSubkeyName
));
434 strcpyW(wszRegKey
, clsid_keyname
);
435 strcatW(wszRegKey
, wszRegSeparator
);
436 strcatW(wszRegKey
, wszFilterSubkeyName
);
438 if (RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszRegKey
, 0, KEY_READ
, &hkeyFilterClass
) != ERROR_SUCCESS
)
444 rgf2
.u
.s1
.rgPins
= NULL
;
446 cbData
= sizeof(wszFilterName
);
447 if (RegQueryValueExW(hkeyFilterClass
, NULL
, NULL
, &Type
, (LPBYTE
)wszFilterName
, &cbData
) != ERROR_SUCCESS
||
451 cbData
= sizeof(rgf2
.dwMerit
);
452 if (RegQueryValueExW(hkeyFilterClass
, wszMeritName
, NULL
, &Type
, (LPBYTE
)&rgf2
.dwMerit
, &cbData
) != ERROR_SUCCESS
||
456 DEVENUM_ReadPins(hkeyFilterClass
, &rgf2
);
458 res
= CLSIDFromString(wszFilterSubkeyName
, &clsidFilter
);
459 if (FAILED(res
)) goto cleanup
;
461 IFilterMapper2_RegisterFilter(pMapper
, &clsidFilter
, wszFilterName
, &pMoniker
, NULL
, NULL
, &rgf2
);
464 IMoniker_Release(pMoniker
);
468 if (hkeyFilterClass
) RegCloseKey(hkeyFilterClass
);
470 if (rgf2
.u
.s1
.rgPins
)
474 for (iPin
= 0; iPin
< rgf2
.u
.s1
.cPins
; iPin
++)
476 CoTaskMemFree(rgf2
.u
.s1
.rgPins
[iPin
].strName
);
478 if (rgf2
.u
.s1
.rgPins
[iPin
].lpMediaType
)
482 for (iType
= 0; iType
< rgf2
.u
.s1
.rgPins
[iPin
].nMediaTypes
; iType
++)
484 CoTaskMemFree((void*)rgf2
.u
.s1
.rgPins
[iPin
].lpMediaType
[iType
].clsMajorType
);
485 CoTaskMemFree((void*)rgf2
.u
.s1
.rgPins
[iPin
].lpMediaType
[iType
].clsMinorType
);
488 CoTaskMemFree((void*)rgf2
.u
.s1
.rgPins
[iPin
].lpMediaType
);
492 CoTaskMemFree((void*)rgf2
.u
.s1
.rgPins
);
498 if (hkeyFilter
) RegCloseKey(hkeyFilter
);
501 IFilterMapper2_Release(pMapper
);
506 /**********************************************************************
507 * DEVENUM_ICreateDevEnum_CreateClassEnumerator
509 static HRESULT WINAPI
DEVENUM_ICreateDevEnum_CreateClassEnumerator(
510 ICreateDevEnum
* iface
,
511 REFCLSID clsidDeviceClass
,
512 IEnumMoniker
**ppEnumMoniker
,
515 HKEY hkey
, special_hkey
= NULL
;
518 TRACE("(%p)->(%s, %p, %x)\n", iface
, debugstr_guid(clsidDeviceClass
), ppEnumMoniker
, dwFlags
);
523 *ppEnumMoniker
= NULL
;
525 if (IsEqualGUID(clsidDeviceClass
, &CLSID_LegacyAmFilterCategory
))
527 DEVENUM_RegisterLegacyAmFilters();
530 if (IsSpecialCategory(clsidDeviceClass
))
532 hr
= DEVENUM_CreateSpecialCategories();
536 special_hkey
= open_special_category_key(clsidDeviceClass
, FALSE
);
539 ERR("Couldn't open registry key for special device: %s\n",
540 debugstr_guid(clsidDeviceClass
));
545 hkey
= open_category_key(clsidDeviceClass
);
546 if (!hkey
&& !special_hkey
)
548 FIXME("Category %s not found\n", debugstr_guid(clsidDeviceClass
));
552 return DEVENUM_IEnumMoniker_Construct(hkey
, special_hkey
, ppEnumMoniker
);
555 /**********************************************************************
556 * ICreateDevEnum_Vtbl
558 static const ICreateDevEnumVtbl ICreateDevEnum_Vtbl
=
560 DEVENUM_ICreateDevEnum_QueryInterface
,
561 DEVENUM_ICreateDevEnum_AddRef
,
562 DEVENUM_ICreateDevEnum_Release
,
563 DEVENUM_ICreateDevEnum_CreateClassEnumerator
,
566 /**********************************************************************
567 * static CreateDevEnum instance
569 ICreateDevEnum DEVENUM_CreateDevEnum
= { &ICreateDevEnum_Vtbl
};
571 /**********************************************************************
572 * DEVENUM_CreateAMCategoryKey (INTERNAL)
574 * Creates a registry key for a category at HKEY_CURRENT_USER\Software\
575 * Microsoft\ActiveMovie\devenum\{clsid}
577 static HRESULT
DEVENUM_CreateAMCategoryKey(const CLSID
* clsidCategory
)
579 WCHAR wszRegKey
[MAX_PATH
];
581 HKEY hkeyDummy
= NULL
;
583 strcpyW(wszRegKey
, wszActiveMovieKey
);
585 if (!StringFromGUID2(clsidCategory
, wszRegKey
+ strlenW(wszRegKey
), sizeof(wszRegKey
)/sizeof(wszRegKey
[0]) - strlenW(wszRegKey
)))
590 LONG lRes
= RegCreateKeyW(HKEY_CURRENT_USER
, wszRegKey
, &hkeyDummy
);
591 res
= HRESULT_FROM_WIN32(lRes
);
595 RegCloseKey(hkeyDummy
);
598 ERR("Failed to create key HKEY_CURRENT_USER\\%s\n", debugstr_w(wszRegKey
));
603 static void register_vfw_codecs(void)
605 WCHAR avico_clsid_str
[CHARS_IN_GUID
];
610 static const WCHAR CLSIDW
[] = {'C','L','S','I','D',0};
611 static const WCHAR FccHandlerW
[] = {'F','c','c','H','a','n','d','l','e','r',0};
612 static const WCHAR FriendlyNameW
[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
614 StringFromGUID2(&CLSID_AVICo
, avico_clsid_str
, sizeof(avico_clsid_str
)/sizeof(WCHAR
));
616 basekey
= open_special_category_key(&CLSID_VideoCompressorCategory
, TRUE
);
618 ERR("Could not create key\n");
622 for(i
=0; ICInfo(FCC('v','i','d','c'), i
, &icinfo
); i
++) {
623 WCHAR fcc_str
[5] = {LOBYTE(LOWORD(icinfo
.fccHandler
)), HIBYTE(LOWORD(icinfo
.fccHandler
)),
624 LOBYTE(HIWORD(icinfo
.fccHandler
)), HIBYTE(HIWORD(icinfo
.fccHandler
))};
626 res
= RegCreateKeyW(basekey
, fcc_str
, &key
);
627 if(res
!= ERROR_SUCCESS
)
630 RegSetValueExW(key
, CLSIDW
, 0, REG_SZ
, (const BYTE
*)avico_clsid_str
, sizeof(avico_clsid_str
));
631 RegSetValueExW(key
, FccHandlerW
, 0, REG_SZ
, (const BYTE
*)fcc_str
, sizeof(fcc_str
));
632 RegSetValueExW(key
, FriendlyNameW
, 0, REG_SZ
, (const BYTE
*)icinfo
.szName
, (strlenW(icinfo
.szName
)+1)*sizeof(WCHAR
));
633 /* FIXME: Set ClassManagerFlags and FilterData values */
638 RegCloseKey(basekey
);
641 static HANDLE DEVENUM_populate_handle
;
642 static const WCHAR DEVENUM_populate_handle_nameW
[] =
643 {'_','_','W','I','N','E','_',
644 'D','e','v','e','n','u','m','_',
645 'P','o','p','u','l','a','t','e',0};
647 /**********************************************************************
648 * DEVENUM_CreateSpecialCategories (INTERNAL)
650 * Creates the keys in the registry for the dynamic categories
652 static HRESULT
DEVENUM_CreateSpecialCategories(void)
655 WCHAR szDSoundNameFormat
[MAX_PATH
+ 1];
656 WCHAR szDSoundName
[MAX_PATH
+ 1];
657 DWORD iDefaultDevice
= -1;
659 IFilterMapper2
* pMapper
= NULL
;
662 WCHAR path
[MAX_PATH
];
665 if (DEVENUM_populate_handle
)
667 DEVENUM_populate_handle
= CreateEventW(NULL
, TRUE
, FALSE
, DEVENUM_populate_handle_nameW
);
668 if (GetLastError() == ERROR_ALREADY_EXISTS
)
670 /* Webcams can take some time to scan if the driver is badly written and it enables them,
671 * so have a 10 s timeout here
673 if (WaitForSingleObject(DEVENUM_populate_handle
, 10000) == WAIT_TIMEOUT
)
674 WARN("Waiting for object timed out\n");
675 TRACE("No need to rescan\n");
678 TRACE("Scanning for devices\n");
680 /* Since devices can change between session, for example because you just plugged in a webcam
681 * or switched from pulseaudio to alsa, delete all old devices first
683 if (SUCCEEDED(DEVENUM_GetCategoryKey(&CLSID_AudioRendererCategory
, &basekey
, path
, MAX_PATH
)))
684 RegDeleteTreeW(basekey
, path
);
685 if (SUCCEEDED(DEVENUM_GetCategoryKey(&CLSID_AudioInputDeviceCategory
, &basekey
, path
, MAX_PATH
)))
686 RegDeleteTreeW(basekey
, path
);
687 if (SUCCEEDED(DEVENUM_GetCategoryKey(&CLSID_VideoInputDeviceCategory
, &basekey
, path
, MAX_PATH
)))
688 RegDeleteTreeW(basekey
, path
);
689 if (SUCCEEDED(DEVENUM_GetCategoryKey(&CLSID_MidiRendererCategory
, &basekey
, path
, MAX_PATH
)))
690 RegDeleteTreeW(basekey
, path
);
691 if (SUCCEEDED(DEVENUM_GetCategoryKey(&CLSID_VideoCompressorCategory
, &basekey
, path
, MAX_PATH
)))
692 RegDeleteTreeW(basekey
, path
);
695 rf2
.dwMerit
= MERIT_PREFERRED
;
697 rf2
.u
.s2
.rgPins2
= &rfp2
;
700 rfp2
.lpMedium
= NULL
;
701 rfp2
.clsPinCategory
= &IID_NULL
;
703 if (!LoadStringW(DEVENUM_hInstance
, IDS_DEVENUM_DS
, szDSoundNameFormat
, sizeof(szDSoundNameFormat
)/sizeof(szDSoundNameFormat
[0])-1))
705 ERR("Couldn't get string resource (GetLastError() is %d)\n", GetLastError());
706 return HRESULT_FROM_WIN32(GetLastError());
709 res
= CoCreateInstance(&CLSID_FilterMapper2
, NULL
, CLSCTX_INPROC
,
710 &IID_IFilterMapper2
, (void **) &pMapper
);
712 * Fill in info for devices
720 REGPINTYPES
* pTypes
;
721 IPropertyBag
* pPropBag
= NULL
;
723 numDevs
= waveOutGetNumDevs();
725 res
= DEVENUM_CreateAMCategoryKey(&CLSID_AudioRendererCategory
);
726 if (FAILED(res
)) /* can't register any devices in this category */
729 rfp2
.dwFlags
= REG_PINFLAG_B_RENDERER
;
730 for (i
= 0; i
< numDevs
; i
++)
732 if (waveOutGetDevCapsW(i
, &wocaps
, sizeof(WAVEOUTCAPSW
))
735 IMoniker
* pMoniker
= NULL
;
737 rfp2
.nMediaTypes
= 1;
738 pTypes
= CoTaskMemAlloc(rfp2
.nMediaTypes
* sizeof(REGPINTYPES
));
741 IFilterMapper2_Release(pMapper
);
742 return E_OUTOFMEMORY
;
744 /* FIXME: Native devenum seems to register a lot more types for
745 * DSound than we do. Not sure what purpose they serve */
746 pTypes
[0].clsMajorType
= &MEDIATYPE_Audio
;
747 pTypes
[0].clsMinorType
= &MEDIASUBTYPE_PCM
;
749 rfp2
.lpMediaType
= pTypes
;
751 res
= IFilterMapper2_RegisterFilter(pMapper
,
755 &CLSID_AudioRendererCategory
,
765 res
= IMoniker_BindToStorage(pMoniker
, NULL
, NULL
, &IID_IPropertyBag
, (LPVOID
)&pPropBag
);
767 res
= IPropertyBag_Write(pPropBag
, wszWaveOutID
, &var
);
771 V_VT(&var
) = VT_LPWSTR
;
772 V_BSTR(&var
) = wocaps
.szPname
;
774 res
= IPropertyBag_Write(pPropBag
, wszFriendlyName
, &var
);
776 IPropertyBag_Release(pPropBag
);
777 IMoniker_Release(pMoniker
);
781 wsprintfW(szDSoundName
, szDSoundNameFormat
, wocaps
.szPname
);
782 res
= IFilterMapper2_RegisterFilter(pMapper
,
786 &CLSID_AudioRendererCategory
,
790 /* FIXME: do additional stuff with IMoniker here, depending on what RegisterFilter does */
793 IMoniker_Release(pMoniker
);
795 if (i
== iDefaultDevice
)
797 FIXME("Default device\n");
800 CoTaskMemFree(pTypes
);
804 numDevs
= waveInGetNumDevs();
806 res
= DEVENUM_CreateAMCategoryKey(&CLSID_AudioInputDeviceCategory
);
807 if (FAILED(res
)) /* can't register any devices in this category */
810 rfp2
.dwFlags
= REG_PINFLAG_B_OUTPUT
;
811 for (i
= 0; i
< numDevs
; i
++)
813 if (waveInGetDevCapsW(i
, &wicaps
, sizeof(WAVEINCAPSW
))
816 IMoniker
* pMoniker
= NULL
;
818 rfp2
.nMediaTypes
= 1;
819 pTypes
= CoTaskMemAlloc(rfp2
.nMediaTypes
* sizeof(REGPINTYPES
));
822 IFilterMapper2_Release(pMapper
);
823 return E_OUTOFMEMORY
;
826 /* FIXME: Not sure if these are correct */
827 pTypes
[0].clsMajorType
= &MEDIATYPE_Audio
;
828 pTypes
[0].clsMinorType
= &MEDIASUBTYPE_PCM
;
830 rfp2
.lpMediaType
= pTypes
;
832 res
= IFilterMapper2_RegisterFilter(pMapper
,
836 &CLSID_AudioInputDeviceCategory
,
846 res
= IMoniker_BindToStorage(pMoniker
, NULL
, NULL
, &IID_IPropertyBag
, (LPVOID
)&pPropBag
);
848 res
= IPropertyBag_Write(pPropBag
, wszWaveInID
, &var
);
852 V_VT(&var
) = VT_LPWSTR
;
853 V_BSTR(&var
) = wicaps
.szPname
;
855 res
= IPropertyBag_Write(pPropBag
, wszFriendlyName
, &var
);
858 IPropertyBag_Release(pPropBag
);
859 IMoniker_Release(pMoniker
);
862 CoTaskMemFree(pTypes
);
866 numDevs
= midiOutGetNumDevs();
868 res
= DEVENUM_CreateAMCategoryKey(&CLSID_MidiRendererCategory
);
869 if (FAILED(res
)) /* can't register any devices in this category */
872 rfp2
.dwFlags
= REG_PINFLAG_B_RENDERER
;
873 for (i
= 0; i
< numDevs
; i
++)
875 if (midiOutGetDevCapsW(i
, &mocaps
, sizeof(MIDIOUTCAPSW
))
878 IMoniker
* pMoniker
= NULL
;
880 rfp2
.nMediaTypes
= 1;
881 pTypes
= CoTaskMemAlloc(rfp2
.nMediaTypes
* sizeof(REGPINTYPES
));
884 IFilterMapper2_Release(pMapper
);
885 return E_OUTOFMEMORY
;
888 /* FIXME: Not sure if these are correct */
889 pTypes
[0].clsMajorType
= &MEDIATYPE_Midi
;
890 pTypes
[0].clsMinorType
= &MEDIASUBTYPE_None
;
892 rfp2
.lpMediaType
= pTypes
;
894 res
= IFilterMapper2_RegisterFilter(pMapper
,
895 &CLSID_AVIMIDIRender
,
898 &CLSID_MidiRendererCategory
,
902 /* FIXME: do additional stuff with IMoniker here, depending on what RegisterFilter does */
903 /* Native version sets MidiOutId */
906 IMoniker_Release(pMoniker
);
908 if (i
== iDefaultDevice
)
910 FIXME("Default device\n");
913 CoTaskMemFree(pTypes
);
916 res
= DEVENUM_CreateAMCategoryKey(&CLSID_VideoInputDeviceCategory
);
918 for (i
= 0; i
< 10; i
++)
920 WCHAR szDeviceName
[32], szDeviceVersion
[32], szDevicePath
[10];
922 if (capGetDriverDescriptionW ((WORD
) i
,
923 szDeviceName
, sizeof(szDeviceName
)/sizeof(WCHAR
),
924 szDeviceVersion
, sizeof(szDeviceVersion
)/sizeof(WCHAR
)))
926 IMoniker
* pMoniker
= NULL
;
927 WCHAR dprintf
[] = { 'v','i','d','e','o','%','d',0 };
928 snprintfW(szDevicePath
, sizeof(szDevicePath
)/sizeof(WCHAR
), dprintf
, i
);
929 /* The above code prevents 1 device with a different ID overwriting another */
931 rfp2
.nMediaTypes
= 1;
932 pTypes
= CoTaskMemAlloc(rfp2
.nMediaTypes
* sizeof(REGPINTYPES
));
934 IFilterMapper2_Release(pMapper
);
935 return E_OUTOFMEMORY
;
938 pTypes
[0].clsMajorType
= &MEDIATYPE_Video
;
939 pTypes
[0].clsMinorType
= &MEDIASUBTYPE_None
;
941 rfp2
.lpMediaType
= pTypes
;
943 res
= IFilterMapper2_RegisterFilter(pMapper
,
947 &CLSID_VideoInputDeviceCategory
,
952 OLECHAR wszVfwIndex
[] = { 'V','F','W','I','n','d','e','x',0 };
956 res
= IMoniker_BindToStorage(pMoniker
, NULL
, NULL
, &IID_IPropertyBag
, (LPVOID
)&pPropBag
);
957 if (SUCCEEDED(res
)) {
958 res
= IPropertyBag_Write(pPropBag
, wszVfwIndex
, &var
);
959 IPropertyBag_Release(pPropBag
);
961 IMoniker_Release(pMoniker
);
964 if (i
== iDefaultDevice
) FIXME("Default device\n");
965 CoTaskMemFree(pTypes
);
971 IFilterMapper2_Release(pMapper
);
973 register_vfw_codecs();
975 SetEvent(DEVENUM_populate_handle
);