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"
29 extern HINSTANCE DEVENUM_hInstance
;
31 const WCHAR wszInstanceKeyName
[] ={'I','n','s','t','a','n','c','e',0};
33 static const WCHAR wszRegSeparator
[] = {'\\', 0 };
34 static const WCHAR wszActiveMovieKey
[] = {'S','o','f','t','w','a','r','e','\\',
35 'M','i','c','r','o','s','o','f','t','\\',
36 'A','c','t','i','v','e','M','o','v','i','e','\\',
37 'd','e','v','e','n','u','m','\\',0};
38 static const WCHAR wszFilterKeyName
[] = {'F','i','l','t','e','r',0};
39 static const WCHAR wszMeritName
[] = {'M','e','r','i','t',0};
40 static const WCHAR wszPins
[] = {'P','i','n','s',0};
41 static const WCHAR wszAllowedMany
[] = {'A','l','l','o','w','e','d','M','a','n','y',0};
42 static const WCHAR wszAllowedZero
[] = {'A','l','l','o','w','e','d','Z','e','r','o',0};
43 static const WCHAR wszDirection
[] = {'D','i','r','e','c','t','i','o','n',0};
44 static const WCHAR wszIsRendered
[] = {'I','s','R','e','n','d','e','r','e','d',0};
45 static const WCHAR wszTypes
[] = {'T','y','p','e','s',0};
46 static const WCHAR wszFriendlyName
[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
47 static const WCHAR wszWaveInID
[] = {'W','a','v','e','I','n','I','D',0};
48 static const WCHAR wszWaveOutID
[] = {'W','a','v','e','O','u','t','I','D',0};
50 static ULONG WINAPI
DEVENUM_ICreateDevEnum_AddRef(ICreateDevEnum
* iface
);
51 static HRESULT
DEVENUM_CreateSpecialCategories(void);
53 /**********************************************************************
54 * DEVENUM_ICreateDevEnum_QueryInterface (also IUnknown)
56 static HRESULT WINAPI
DEVENUM_ICreateDevEnum_QueryInterface(ICreateDevEnum
*iface
, REFIID riid
,
59 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
64 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
65 IsEqualGUID(riid
, &IID_ICreateDevEnum
))
68 DEVENUM_ICreateDevEnum_AddRef(iface
);
72 FIXME("- no interface IID: %s\n", debugstr_guid(riid
));
77 /**********************************************************************
78 * DEVENUM_ICreateDevEnum_AddRef (also IUnknown)
80 static ULONG WINAPI
DEVENUM_ICreateDevEnum_AddRef(ICreateDevEnum
* iface
)
86 return 2; /* non-heap based object */
89 /**********************************************************************
90 * DEVENUM_ICreateDevEnum_Release (also IUnknown)
92 static ULONG WINAPI
DEVENUM_ICreateDevEnum_Release(ICreateDevEnum
* iface
)
96 DEVENUM_UnlockModule();
98 return 1; /* non-heap based object */
101 HRESULT
DEVENUM_GetCategoryKey(REFCLSID clsidDeviceClass
, HKEY
*pBaseKey
, WCHAR
*wszRegKeyName
, UINT maxLen
)
103 if (IsEqualGUID(clsidDeviceClass
, &CLSID_AudioRendererCategory
) ||
104 IsEqualGUID(clsidDeviceClass
, &CLSID_AudioInputDeviceCategory
) ||
105 IsEqualGUID(clsidDeviceClass
, &CLSID_VideoInputDeviceCategory
) ||
106 IsEqualGUID(clsidDeviceClass
, &CLSID_MidiRendererCategory
))
108 *pBaseKey
= HKEY_CURRENT_USER
;
109 strcpyW(wszRegKeyName
, wszActiveMovieKey
);
111 if (!StringFromGUID2(clsidDeviceClass
, wszRegKeyName
+ strlenW(wszRegKeyName
), maxLen
- strlenW(wszRegKeyName
)))
112 return E_OUTOFMEMORY
;
116 *pBaseKey
= HKEY_CLASSES_ROOT
;
117 strcpyW(wszRegKeyName
, clsid_keyname
);
118 strcatW(wszRegKeyName
, wszRegSeparator
);
120 if (!StringFromGUID2(clsidDeviceClass
, wszRegKeyName
+ CLSID_STR_LEN
, maxLen
- CLSID_STR_LEN
))
121 return E_OUTOFMEMORY
;
123 strcatW(wszRegKeyName
, wszRegSeparator
);
124 strcatW(wszRegKeyName
, wszInstanceKeyName
);
130 static void DEVENUM_ReadPinTypes(HKEY hkeyPinKey
, REGFILTERPINS
*rgPin
)
132 HKEY hkeyTypes
= NULL
;
133 DWORD dwMajorTypes
, i
;
134 REGPINTYPES
*lpMediaType
= NULL
;
135 DWORD dwMediaTypeSize
= 0;
137 if (RegOpenKeyExW(hkeyPinKey
, wszTypes
, 0, KEY_READ
, &hkeyTypes
) != ERROR_SUCCESS
)
140 if (RegQueryInfoKeyW(hkeyTypes
, NULL
, NULL
, NULL
, &dwMajorTypes
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
)
143 RegCloseKey(hkeyTypes
);
147 for (i
= 0; i
< dwMajorTypes
; i
++)
149 HKEY hkeyMajorType
= NULL
;
150 WCHAR wszMajorTypeName
[64];
151 DWORD cName
= sizeof(wszMajorTypeName
) / sizeof(WCHAR
);
152 DWORD dwMinorTypes
, i1
;
154 if (RegEnumKeyExW(hkeyTypes
, i
, wszMajorTypeName
, &cName
, NULL
, NULL
, NULL
, NULL
) != ERROR_SUCCESS
) continue;
156 if (RegOpenKeyExW(hkeyTypes
, wszMajorTypeName
, 0, KEY_READ
, &hkeyMajorType
) != ERROR_SUCCESS
) continue;
158 if (RegQueryInfoKeyW(hkeyMajorType
, NULL
, NULL
, NULL
, &dwMinorTypes
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
)
161 RegCloseKey(hkeyMajorType
);
165 for (i1
= 0; i1
< dwMinorTypes
; i1
++)
167 WCHAR wszMinorTypeName
[64];
168 CLSID
*clsMajorType
= NULL
, *clsMinorType
= NULL
;
171 cName
= sizeof(wszMinorTypeName
) / sizeof(WCHAR
);
172 if (RegEnumKeyExW(hkeyMajorType
, i1
, wszMinorTypeName
, &cName
, NULL
, NULL
, NULL
, NULL
) != ERROR_SUCCESS
) continue;
174 clsMinorType
= CoTaskMemAlloc(sizeof(CLSID
));
175 if (!clsMinorType
) continue;
177 clsMajorType
= CoTaskMemAlloc(sizeof(CLSID
));
178 if (!clsMajorType
) goto error_cleanup_types
;
180 hr
= CLSIDFromString(wszMinorTypeName
, clsMinorType
);
181 if (FAILED(hr
)) goto error_cleanup_types
;
183 hr
= CLSIDFromString(wszMajorTypeName
, clsMajorType
);
184 if (FAILED(hr
)) goto error_cleanup_types
;
186 if (rgPin
->nMediaTypes
== dwMediaTypeSize
)
188 DWORD dwNewSize
= dwMediaTypeSize
+ (dwMediaTypeSize
< 2 ? 1 : dwMediaTypeSize
/ 2);
189 REGPINTYPES
*lpNewMediaType
;
191 lpNewMediaType
= CoTaskMemRealloc(lpMediaType
, sizeof(REGPINTYPES
) * dwNewSize
);
192 if (!lpNewMediaType
) goto error_cleanup_types
;
194 lpMediaType
= lpNewMediaType
;
195 dwMediaTypeSize
= dwNewSize
;
198 lpMediaType
[rgPin
->nMediaTypes
].clsMajorType
= clsMajorType
;
199 lpMediaType
[rgPin
->nMediaTypes
].clsMinorType
= clsMinorType
;
200 rgPin
->nMediaTypes
++;
205 if (clsMajorType
) CoTaskMemFree(clsMajorType
);
206 if (clsMinorType
) CoTaskMemFree(clsMinorType
);
209 RegCloseKey(hkeyMajorType
);
212 RegCloseKey(hkeyTypes
);
214 if (lpMediaType
&& !rgPin
->nMediaTypes
)
216 CoTaskMemFree(lpMediaType
);
220 rgPin
->lpMediaType
= lpMediaType
;
223 static void DEVENUM_ReadPins(HKEY hkeyFilterClass
, REGFILTER2
*rgf2
)
225 HKEY hkeyPins
= NULL
;
226 DWORD dwPinsSubkeys
, i
;
227 REGFILTERPINS
*rgPins
= NULL
;
229 if (RegOpenKeyExW(hkeyFilterClass
, wszPins
, 0, KEY_READ
, &hkeyPins
) != ERROR_SUCCESS
)
232 if (RegQueryInfoKeyW(hkeyPins
, NULL
, NULL
, NULL
, &dwPinsSubkeys
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
)
235 RegCloseKey(hkeyPins
);
241 rgPins
= CoTaskMemAlloc(sizeof(REGFILTERPINS
) * dwPinsSubkeys
);
244 RegCloseKey(hkeyPins
);
249 for (i
= 0; i
< dwPinsSubkeys
; i
++)
251 HKEY hkeyPinKey
= NULL
;
252 WCHAR wszPinName
[MAX_PATH
];
253 DWORD cName
= sizeof(wszPinName
) / sizeof(WCHAR
);
255 REGFILTERPINS
*rgPin
= &rgPins
[rgf2
->u
.s1
.cPins
];
258 rgPin
->strName
= NULL
;
259 rgPin
->clsConnectsToFilter
= &GUID_NULL
;
260 rgPin
->strConnectsToPin
= NULL
;
261 rgPin
->nMediaTypes
= 0;
262 rgPin
->lpMediaType
= NULL
;
264 if (RegEnumKeyExW(hkeyPins
, i
, wszPinName
, &cName
, NULL
, NULL
, NULL
, NULL
) != ERROR_SUCCESS
) continue;
266 if (RegOpenKeyExW(hkeyPins
, wszPinName
, 0, KEY_READ
, &hkeyPinKey
) != ERROR_SUCCESS
) continue;
268 rgPin
->strName
= CoTaskMemAlloc((strlenW(wszPinName
) + 1) * sizeof(WCHAR
));
269 if (!rgPin
->strName
) goto error_cleanup
;
271 strcpyW(rgPin
->strName
, wszPinName
);
273 cbData
= sizeof(rgPin
->bMany
);
274 lRet
= RegQueryValueExW(hkeyPinKey
, wszAllowedMany
, NULL
, &Type
, (LPBYTE
)&rgPin
->bMany
, &cbData
);
275 if (lRet
!= ERROR_SUCCESS
|| Type
!= REG_DWORD
)
278 cbData
= sizeof(rgPin
->bZero
);
279 lRet
= RegQueryValueExW(hkeyPinKey
, wszAllowedZero
, NULL
, &Type
, (LPBYTE
)&rgPin
->bZero
, &cbData
);
280 if (lRet
!= ERROR_SUCCESS
|| Type
!= REG_DWORD
)
283 cbData
= sizeof(rgPin
->bOutput
);
284 lRet
= RegQueryValueExW(hkeyPinKey
, wszDirection
, NULL
, &Type
, (LPBYTE
)&rgPin
->bOutput
, &cbData
);
285 if (lRet
!= ERROR_SUCCESS
|| Type
!= REG_DWORD
)
288 cbData
= sizeof(rgPin
->bRendered
);
289 lRet
= RegQueryValueExW(hkeyPinKey
, wszIsRendered
, NULL
, &Type
, (LPBYTE
)&rgPin
->bRendered
, &cbData
);
290 if (lRet
!= ERROR_SUCCESS
|| Type
!= REG_DWORD
)
293 DEVENUM_ReadPinTypes(hkeyPinKey
, rgPin
);
300 RegCloseKey(hkeyPinKey
);
301 if (rgPin
->strName
) CoTaskMemFree(rgPin
->strName
);
304 RegCloseKey(hkeyPins
);
306 if (rgPins
&& !rgf2
->u
.s1
.cPins
)
308 CoTaskMemFree(rgPins
);
312 rgf2
->u
.s1
.rgPins
= rgPins
;
315 static HRESULT
DEVENUM_RegisterLegacyAmFilters(void)
317 HKEY hkeyFilter
= NULL
;
318 DWORD dwFilterSubkeys
, i
;
320 IFilterMapper2
*pMapper
= NULL
;
323 hr
= CoCreateInstance(&CLSID_FilterMapper2
, NULL
, CLSCTX_INPROC
,
324 &IID_IFilterMapper2
, (void **) &pMapper
);
327 lRet
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszFilterKeyName
, 0, KEY_READ
, &hkeyFilter
);
328 hr
= HRESULT_FROM_WIN32(lRet
);
333 lRet
= RegQueryInfoKeyW(hkeyFilter
, NULL
, NULL
, NULL
, &dwFilterSubkeys
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
334 hr
= HRESULT_FROM_WIN32(lRet
);
339 for (i
= 0; i
< dwFilterSubkeys
; i
++)
341 WCHAR wszFilterSubkeyName
[64];
342 DWORD cName
= sizeof(wszFilterSubkeyName
) / sizeof(WCHAR
);
343 HKEY hkeyCategoryBaseKey
;
344 WCHAR wszRegKey
[MAX_PATH
];
345 HKEY hkeyInstance
= NULL
;
347 if (RegEnumKeyExW(hkeyFilter
, i
, wszFilterSubkeyName
, &cName
, NULL
, NULL
, NULL
, NULL
) != ERROR_SUCCESS
) continue;
349 hr
= DEVENUM_GetCategoryKey(&CLSID_LegacyAmFilterCategory
, &hkeyCategoryBaseKey
, wszRegKey
, MAX_PATH
);
350 if (FAILED(hr
)) continue;
352 strcatW(wszRegKey
, wszRegSeparator
);
353 strcatW(wszRegKey
, wszFilterSubkeyName
);
355 if (RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszRegKey
, 0, KEY_READ
, &hkeyInstance
) == ERROR_SUCCESS
)
357 RegCloseKey(hkeyInstance
);
361 /* Filter is registered the IFilterMapper(1)-way in HKCR\Filter. Needs to be added to
362 * legacy am filter category. */
363 HKEY hkeyFilterClass
= NULL
;
366 WCHAR wszFilterName
[MAX_PATH
];
370 IMoniker
*pMoniker
= NULL
;
372 TRACE("Registering %s\n", debugstr_w(wszFilterSubkeyName
));
374 strcpyW(wszRegKey
, clsid_keyname
);
375 strcatW(wszRegKey
, wszRegSeparator
);
376 strcatW(wszRegKey
, wszFilterSubkeyName
);
378 if (RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszRegKey
, 0, KEY_READ
, &hkeyFilterClass
) != ERROR_SUCCESS
)
384 rgf2
.u
.s1
.rgPins
= NULL
;
386 cbData
= sizeof(wszFilterName
);
387 if (RegQueryValueExW(hkeyFilterClass
, NULL
, NULL
, &Type
, (LPBYTE
)wszFilterName
, &cbData
) != ERROR_SUCCESS
||
391 cbData
= sizeof(rgf2
.dwMerit
);
392 if (RegQueryValueExW(hkeyFilterClass
, wszMeritName
, NULL
, &Type
, (LPBYTE
)&rgf2
.dwMerit
, &cbData
) != ERROR_SUCCESS
||
396 DEVENUM_ReadPins(hkeyFilterClass
, &rgf2
);
398 res
= CLSIDFromString(wszFilterSubkeyName
, &clsidFilter
);
399 if (FAILED(res
)) goto cleanup
;
401 IFilterMapper2_RegisterFilter(pMapper
, &clsidFilter
, wszFilterName
, &pMoniker
, NULL
, NULL
, &rgf2
);
404 IMoniker_Release(pMoniker
);
408 if (hkeyFilterClass
) RegCloseKey(hkeyFilterClass
);
410 if (rgf2
.u
.s1
.rgPins
)
414 for (iPin
= 0; iPin
< rgf2
.u
.s1
.cPins
; iPin
++)
416 CoTaskMemFree(rgf2
.u
.s1
.rgPins
[iPin
].strName
);
418 if (rgf2
.u
.s1
.rgPins
[iPin
].lpMediaType
)
422 for (iType
= 0; iType
< rgf2
.u
.s1
.rgPins
[iPin
].nMediaTypes
; iType
++)
424 CoTaskMemFree((void*)rgf2
.u
.s1
.rgPins
[iPin
].lpMediaType
[iType
].clsMajorType
);
425 CoTaskMemFree((void*)rgf2
.u
.s1
.rgPins
[iPin
].lpMediaType
[iType
].clsMinorType
);
428 CoTaskMemFree((void*)rgf2
.u
.s1
.rgPins
[iPin
].lpMediaType
);
432 CoTaskMemFree((void*)rgf2
.u
.s1
.rgPins
);
438 if (hkeyFilter
) RegCloseKey(hkeyFilter
);
441 IFilterMapper2_Release(pMapper
);
446 /**********************************************************************
447 * DEVENUM_ICreateDevEnum_CreateClassEnumerator
449 static HRESULT WINAPI
DEVENUM_ICreateDevEnum_CreateClassEnumerator(
450 ICreateDevEnum
* iface
,
451 REFCLSID clsidDeviceClass
,
452 IEnumMoniker
**ppEnumMoniker
,
455 WCHAR wszRegKey
[MAX_PATH
];
460 TRACE("(%p)->(%s, %p, %x)\n", iface
, debugstr_guid(clsidDeviceClass
), ppEnumMoniker
, dwFlags
);
465 *ppEnumMoniker
= NULL
;
467 if (IsEqualGUID(clsidDeviceClass
, &CLSID_LegacyAmFilterCategory
))
469 DEVENUM_RegisterLegacyAmFilters();
472 hr
= DEVENUM_GetCategoryKey(clsidDeviceClass
, &hbasekey
, wszRegKey
, MAX_PATH
);
476 if (IsEqualGUID(clsidDeviceClass
, &CLSID_AudioRendererCategory
) ||
477 IsEqualGUID(clsidDeviceClass
, &CLSID_AudioInputDeviceCategory
) ||
478 IsEqualGUID(clsidDeviceClass
, &CLSID_VideoInputDeviceCategory
) ||
479 IsEqualGUID(clsidDeviceClass
, &CLSID_MidiRendererCategory
))
481 hr
= DEVENUM_CreateSpecialCategories();
484 if (RegOpenKeyW(hbasekey
, wszRegKey
, &hkey
) != ERROR_SUCCESS
)
486 ERR("Couldn't open registry key for special device: %s\n",
487 debugstr_guid(clsidDeviceClass
));
491 else if (RegOpenKeyW(hbasekey
, wszRegKey
, &hkey
) != ERROR_SUCCESS
)
493 FIXME("Category %s not found\n", debugstr_guid(clsidDeviceClass
));
497 return DEVENUM_IEnumMoniker_Construct(hkey
, ppEnumMoniker
);
500 /**********************************************************************
501 * ICreateDevEnum_Vtbl
503 static const ICreateDevEnumVtbl ICreateDevEnum_Vtbl
=
505 DEVENUM_ICreateDevEnum_QueryInterface
,
506 DEVENUM_ICreateDevEnum_AddRef
,
507 DEVENUM_ICreateDevEnum_Release
,
508 DEVENUM_ICreateDevEnum_CreateClassEnumerator
,
511 /**********************************************************************
512 * static CreateDevEnum instance
514 ICreateDevEnum DEVENUM_CreateDevEnum
= { &ICreateDevEnum_Vtbl
};
516 /**********************************************************************
517 * DEVENUM_CreateAMCategoryKey (INTERNAL)
519 * Creates a registry key for a category at HKEY_CURRENT_USER\Software\
520 * Microsoft\ActiveMovie\devenum\{clsid}
522 static HRESULT
DEVENUM_CreateAMCategoryKey(const CLSID
* clsidCategory
)
524 WCHAR wszRegKey
[MAX_PATH
];
526 HKEY hkeyDummy
= NULL
;
528 strcpyW(wszRegKey
, wszActiveMovieKey
);
530 if (!StringFromGUID2(clsidCategory
, wszRegKey
+ strlenW(wszRegKey
), sizeof(wszRegKey
)/sizeof(wszRegKey
[0]) - strlenW(wszRegKey
)))
535 LONG lRes
= RegCreateKeyW(HKEY_CURRENT_USER
, wszRegKey
, &hkeyDummy
);
536 res
= HRESULT_FROM_WIN32(lRes
);
540 RegCloseKey(hkeyDummy
);
543 ERR("Failed to create key HKEY_CURRENT_USER\\%s\n", debugstr_w(wszRegKey
));
548 static HANDLE DEVENUM_populate_handle
;
549 static const WCHAR DEVENUM_populate_handle_nameW
[] =
550 {'_','_','W','I','N','E','_',
551 'D','e','v','e','n','u','m','_',
552 'P','o','p','u','l','a','t','e',0};
554 /**********************************************************************
555 * DEVENUM_CreateSpecialCategories (INTERNAL)
557 * Creates the keys in the registry for the dynamic categories
559 static HRESULT
DEVENUM_CreateSpecialCategories(void)
562 WCHAR szDSoundNameFormat
[MAX_PATH
+ 1];
563 WCHAR szDSoundName
[MAX_PATH
+ 1];
564 DWORD iDefaultDevice
= -1;
566 IFilterMapper2
* pMapper
= NULL
;
569 WCHAR path
[MAX_PATH
];
572 if (DEVENUM_populate_handle
)
574 DEVENUM_populate_handle
= CreateEventW(NULL
, TRUE
, FALSE
, DEVENUM_populate_handle_nameW
);
575 if (GetLastError() == ERROR_ALREADY_EXISTS
)
577 /* Webcams can take some time to scan if the driver is badly written and it enables them,
578 * so have a 10 s timeout here
580 if (WaitForSingleObject(DEVENUM_populate_handle
, 10000) == WAIT_TIMEOUT
)
581 WARN("Waiting for object timed out\n");
582 TRACE("No need to rescan\n");
585 TRACE("Scanning for devices\n");
587 /* Since devices can change between session, for example because you just plugged in a webcam
588 * or switched from pulseaudio to alsa, delete all old devices first
590 if (SUCCEEDED(DEVENUM_GetCategoryKey(&CLSID_AudioRendererCategory
, &basekey
, path
, MAX_PATH
)))
591 RegDeleteTreeW(basekey
, path
);
592 if (SUCCEEDED(DEVENUM_GetCategoryKey(&CLSID_AudioInputDeviceCategory
, &basekey
, path
, MAX_PATH
)))
593 RegDeleteTreeW(basekey
, path
);
594 if (SUCCEEDED(DEVENUM_GetCategoryKey(&CLSID_VideoInputDeviceCategory
, &basekey
, path
, MAX_PATH
)))
595 RegDeleteTreeW(basekey
, path
);
596 if (SUCCEEDED(DEVENUM_GetCategoryKey(&CLSID_MidiRendererCategory
, &basekey
, path
, MAX_PATH
)))
597 RegDeleteTreeW(basekey
, path
);
600 rf2
.dwMerit
= MERIT_PREFERRED
;
602 rf2
.u
.s2
.rgPins2
= &rfp2
;
605 rfp2
.lpMedium
= NULL
;
606 rfp2
.clsPinCategory
= &IID_NULL
;
608 if (!LoadStringW(DEVENUM_hInstance
, IDS_DEVENUM_DS
, szDSoundNameFormat
, sizeof(szDSoundNameFormat
)/sizeof(szDSoundNameFormat
[0])-1))
610 ERR("Couldn't get string resource (GetLastError() is %d)\n", GetLastError());
611 return HRESULT_FROM_WIN32(GetLastError());
614 res
= CoCreateInstance(&CLSID_FilterMapper2
, NULL
, CLSCTX_INPROC
,
615 &IID_IFilterMapper2
, (void **) &pMapper
);
617 * Fill in info for devices
625 REGPINTYPES
* pTypes
;
626 IPropertyBag
* pPropBag
= NULL
;
628 numDevs
= waveOutGetNumDevs();
630 res
= DEVENUM_CreateAMCategoryKey(&CLSID_AudioRendererCategory
);
631 if (FAILED(res
)) /* can't register any devices in this category */
634 rfp2
.dwFlags
= REG_PINFLAG_B_RENDERER
;
635 for (i
= 0; i
< numDevs
; i
++)
637 if (waveOutGetDevCapsW(i
, &wocaps
, sizeof(WAVEOUTCAPSW
))
640 IMoniker
* pMoniker
= NULL
;
642 rfp2
.nMediaTypes
= 1;
643 pTypes
= CoTaskMemAlloc(rfp2
.nMediaTypes
* sizeof(REGPINTYPES
));
646 IFilterMapper2_Release(pMapper
);
647 return E_OUTOFMEMORY
;
649 /* FIXME: Native devenum seems to register a lot more types for
650 * DSound than we do. Not sure what purpose they serve */
651 pTypes
[0].clsMajorType
= &MEDIATYPE_Audio
;
652 pTypes
[0].clsMinorType
= &MEDIASUBTYPE_PCM
;
654 rfp2
.lpMediaType
= pTypes
;
656 res
= IFilterMapper2_RegisterFilter(pMapper
,
660 &CLSID_AudioRendererCategory
,
669 V_UNION(&var
, ulVal
) = i
;
670 res
= IMoniker_BindToStorage(pMoniker
, NULL
, NULL
, &IID_IPropertyBag
, (LPVOID
)&pPropBag
);
672 res
= IPropertyBag_Write(pPropBag
, wszWaveOutID
, &var
);
676 V_VT(&var
) = VT_LPWSTR
;
677 V_UNION(&var
, bstrVal
) = wocaps
.szPname
;
679 res
= IPropertyBag_Write(pPropBag
, wszFriendlyName
, &var
);
681 IPropertyBag_Release(pPropBag
);
682 IMoniker_Release(pMoniker
);
686 wsprintfW(szDSoundName
, szDSoundNameFormat
, wocaps
.szPname
);
687 res
= IFilterMapper2_RegisterFilter(pMapper
,
691 &CLSID_AudioRendererCategory
,
695 /* FIXME: do additional stuff with IMoniker here, depending on what RegisterFilter does */
698 IMoniker_Release(pMoniker
);
700 if (i
== iDefaultDevice
)
702 FIXME("Default device\n");
705 CoTaskMemFree(pTypes
);
709 numDevs
= waveInGetNumDevs();
711 res
= DEVENUM_CreateAMCategoryKey(&CLSID_AudioInputDeviceCategory
);
712 if (FAILED(res
)) /* can't register any devices in this category */
715 rfp2
.dwFlags
= REG_PINFLAG_B_OUTPUT
;
716 for (i
= 0; i
< numDevs
; i
++)
718 if (waveInGetDevCapsW(i
, &wicaps
, sizeof(WAVEINCAPSW
))
721 IMoniker
* pMoniker
= NULL
;
723 rfp2
.nMediaTypes
= 1;
724 pTypes
= CoTaskMemAlloc(rfp2
.nMediaTypes
* sizeof(REGPINTYPES
));
727 IFilterMapper2_Release(pMapper
);
728 return E_OUTOFMEMORY
;
731 /* FIXME: Not sure if these are correct */
732 pTypes
[0].clsMajorType
= &MEDIATYPE_Audio
;
733 pTypes
[0].clsMinorType
= &MEDIASUBTYPE_PCM
;
735 rfp2
.lpMediaType
= pTypes
;
737 res
= IFilterMapper2_RegisterFilter(pMapper
,
741 &CLSID_AudioInputDeviceCategory
,
750 V_UNION(&var
, ulVal
) = i
;
751 res
= IMoniker_BindToStorage(pMoniker
, NULL
, NULL
, &IID_IPropertyBag
, (LPVOID
)&pPropBag
);
753 res
= IPropertyBag_Write(pPropBag
, wszWaveInID
, &var
);
757 V_VT(&var
) = VT_LPWSTR
;
758 V_UNION(&var
, bstrVal
) = wicaps
.szPname
;
760 res
= IPropertyBag_Write(pPropBag
, wszFriendlyName
, &var
);
763 IPropertyBag_Release(pPropBag
);
764 IMoniker_Release(pMoniker
);
767 CoTaskMemFree(pTypes
);
771 numDevs
= midiOutGetNumDevs();
773 res
= DEVENUM_CreateAMCategoryKey(&CLSID_MidiRendererCategory
);
774 if (FAILED(res
)) /* can't register any devices in this category */
777 rfp2
.dwFlags
= REG_PINFLAG_B_RENDERER
;
778 for (i
= 0; i
< numDevs
; i
++)
780 if (midiOutGetDevCapsW(i
, &mocaps
, sizeof(MIDIOUTCAPSW
))
783 IMoniker
* pMoniker
= NULL
;
785 rfp2
.nMediaTypes
= 1;
786 pTypes
= CoTaskMemAlloc(rfp2
.nMediaTypes
* sizeof(REGPINTYPES
));
789 IFilterMapper2_Release(pMapper
);
790 return E_OUTOFMEMORY
;
793 /* FIXME: Not sure if these are correct */
794 pTypes
[0].clsMajorType
= &MEDIATYPE_Midi
;
795 pTypes
[0].clsMinorType
= &MEDIASUBTYPE_None
;
797 rfp2
.lpMediaType
= pTypes
;
799 res
= IFilterMapper2_RegisterFilter(pMapper
,
800 &CLSID_AVIMIDIRender
,
803 &CLSID_MidiRendererCategory
,
807 /* FIXME: do additional stuff with IMoniker here, depending on what RegisterFilter does */
808 /* Native version sets MidiOutId */
811 IMoniker_Release(pMoniker
);
813 if (i
== iDefaultDevice
)
815 FIXME("Default device\n");
818 CoTaskMemFree(pTypes
);
821 res
= DEVENUM_CreateAMCategoryKey(&CLSID_VideoInputDeviceCategory
);
823 for (i
= 0; i
< 10; i
++)
825 WCHAR szDeviceName
[32], szDeviceVersion
[32], szDevicePath
[10];
827 if (capGetDriverDescriptionW ((WORD
) i
,
828 szDeviceName
, sizeof(szDeviceName
)/sizeof(WCHAR
),
829 szDeviceVersion
, sizeof(szDeviceVersion
)/sizeof(WCHAR
)))
831 IMoniker
* pMoniker
= NULL
;
832 WCHAR dprintf
[] = { 'v','i','d','e','o','%','d',0 };
833 snprintfW(szDevicePath
, sizeof(szDevicePath
)/sizeof(WCHAR
), dprintf
, i
);
834 /* The above code prevents 1 device with a different ID overwriting another */
836 rfp2
.nMediaTypes
= 1;
837 pTypes
= CoTaskMemAlloc(rfp2
.nMediaTypes
* sizeof(REGPINTYPES
));
839 IFilterMapper2_Release(pMapper
);
840 return E_OUTOFMEMORY
;
843 pTypes
[0].clsMajorType
= &MEDIATYPE_Video
;
844 pTypes
[0].clsMinorType
= &MEDIASUBTYPE_None
;
846 rfp2
.lpMediaType
= pTypes
;
848 res
= IFilterMapper2_RegisterFilter(pMapper
,
852 &CLSID_VideoInputDeviceCategory
,
857 OLECHAR wszVfwIndex
[] = { 'V','F','W','I','n','d','e','x',0 };
860 V_UNION(&var
, ulVal
) = i
;
861 res
= IMoniker_BindToStorage(pMoniker
, NULL
, NULL
, &IID_IPropertyBag
, (LPVOID
)&pPropBag
);
862 if (SUCCEEDED(res
)) {
863 res
= IPropertyBag_Write(pPropBag
, wszVfwIndex
, &var
);
864 IPropertyBag_Release(pPropBag
);
866 IMoniker_Release(pMoniker
);
869 if (i
== iDefaultDevice
) FIXME("Default device\n");
870 CoTaskMemFree(pTypes
);
876 IFilterMapper2_Release(pMapper
);
877 SetEvent(DEVENUM_populate_handle
);