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"
32 extern HINSTANCE DEVENUM_hInstance
;
34 const WCHAR wszInstanceKeyName
[] ={'I','n','s','t','a','n','c','e',0};
36 static const WCHAR wszRegSeparator
[] = {'\\', 0 };
37 static const WCHAR wszActiveMovieKey
[] = {'S','o','f','t','w','a','r','e','\\',
38 'M','i','c','r','o','s','o','f','t','\\',
39 'A','c','t','i','v','e','M','o','v','i','e','\\',
40 'd','e','v','e','n','u','m','\\',0};
41 static const WCHAR wszFilterKeyName
[] = {'F','i','l','t','e','r',0};
42 static const WCHAR wszMeritName
[] = {'M','e','r','i','t',0};
43 static const WCHAR wszPins
[] = {'P','i','n','s',0};
44 static const WCHAR wszAllowedMany
[] = {'A','l','l','o','w','e','d','M','a','n','y',0};
45 static const WCHAR wszAllowedZero
[] = {'A','l','l','o','w','e','d','Z','e','r','o',0};
46 static const WCHAR wszDirection
[] = {'D','i','r','e','c','t','i','o','n',0};
47 static const WCHAR wszIsRendered
[] = {'I','s','R','e','n','d','e','r','e','d',0};
48 static const WCHAR wszTypes
[] = {'T','y','p','e','s',0};
49 static const WCHAR wszFriendlyName
[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
50 static const WCHAR wszWaveInID
[] = {'W','a','v','e','I','n','I','D',0};
51 static const WCHAR wszWaveOutID
[] = {'W','a','v','e','O','u','t','I','D',0};
53 static ULONG WINAPI
DEVENUM_ICreateDevEnum_AddRef(ICreateDevEnum
* iface
);
54 static HRESULT
DEVENUM_CreateSpecialCategories(void);
56 /**********************************************************************
57 * DEVENUM_ICreateDevEnum_QueryInterface (also IUnknown)
59 static HRESULT WINAPI
DEVENUM_ICreateDevEnum_QueryInterface(ICreateDevEnum
*iface
, REFIID riid
,
62 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
67 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
68 IsEqualGUID(riid
, &IID_ICreateDevEnum
))
71 DEVENUM_ICreateDevEnum_AddRef(iface
);
75 FIXME("- no interface IID: %s\n", debugstr_guid(riid
));
80 /**********************************************************************
81 * DEVENUM_ICreateDevEnum_AddRef (also IUnknown)
83 static ULONG WINAPI
DEVENUM_ICreateDevEnum_AddRef(ICreateDevEnum
* iface
)
89 return 2; /* non-heap based object */
92 /**********************************************************************
93 * DEVENUM_ICreateDevEnum_Release (also IUnknown)
95 static ULONG WINAPI
DEVENUM_ICreateDevEnum_Release(ICreateDevEnum
* iface
)
99 DEVENUM_UnlockModule();
101 return 1; /* non-heap based object */
104 HRESULT
DEVENUM_GetCategoryKey(REFCLSID clsidDeviceClass
, HKEY
*pBaseKey
, WCHAR
*wszRegKeyName
, UINT maxLen
)
106 if (IsEqualGUID(clsidDeviceClass
, &CLSID_AudioRendererCategory
) ||
107 IsEqualGUID(clsidDeviceClass
, &CLSID_AudioInputDeviceCategory
) ||
108 IsEqualGUID(clsidDeviceClass
, &CLSID_VideoInputDeviceCategory
) ||
109 IsEqualGUID(clsidDeviceClass
, &CLSID_MidiRendererCategory
))
111 *pBaseKey
= HKEY_CURRENT_USER
;
112 strcpyW(wszRegKeyName
, wszActiveMovieKey
);
114 if (!StringFromGUID2(clsidDeviceClass
, wszRegKeyName
+ strlenW(wszRegKeyName
), maxLen
- strlenW(wszRegKeyName
)))
115 return E_OUTOFMEMORY
;
119 *pBaseKey
= HKEY_CLASSES_ROOT
;
120 strcpyW(wszRegKeyName
, clsid_keyname
);
121 strcatW(wszRegKeyName
, wszRegSeparator
);
123 if (!StringFromGUID2(clsidDeviceClass
, wszRegKeyName
+ CLSID_STR_LEN
, maxLen
- CLSID_STR_LEN
))
124 return E_OUTOFMEMORY
;
126 strcatW(wszRegKeyName
, wszRegSeparator
);
127 strcatW(wszRegKeyName
, wszInstanceKeyName
);
133 static void DEVENUM_ReadPinTypes(HKEY hkeyPinKey
, REGFILTERPINS
*rgPin
)
135 HKEY hkeyTypes
= NULL
;
136 DWORD dwMajorTypes
, i
;
137 REGPINTYPES
*lpMediaType
= NULL
;
138 DWORD dwMediaTypeSize
= 0;
140 if (RegOpenKeyExW(hkeyPinKey
, wszTypes
, 0, KEY_READ
, &hkeyTypes
) != ERROR_SUCCESS
)
143 if (RegQueryInfoKeyW(hkeyTypes
, NULL
, NULL
, NULL
, &dwMajorTypes
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
)
146 RegCloseKey(hkeyTypes
);
150 for (i
= 0; i
< dwMajorTypes
; i
++)
152 HKEY hkeyMajorType
= NULL
;
153 WCHAR wszMajorTypeName
[64];
154 DWORD cName
= sizeof(wszMajorTypeName
) / sizeof(WCHAR
);
155 DWORD dwMinorTypes
, i1
;
157 if (RegEnumKeyExW(hkeyTypes
, i
, wszMajorTypeName
, &cName
, NULL
, NULL
, NULL
, NULL
) != ERROR_SUCCESS
) continue;
159 if (RegOpenKeyExW(hkeyTypes
, wszMajorTypeName
, 0, KEY_READ
, &hkeyMajorType
) != ERROR_SUCCESS
) continue;
161 if (RegQueryInfoKeyW(hkeyMajorType
, NULL
, NULL
, NULL
, &dwMinorTypes
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
)
164 RegCloseKey(hkeyMajorType
);
168 for (i1
= 0; i1
< dwMinorTypes
; i1
++)
170 WCHAR wszMinorTypeName
[64];
171 CLSID
*clsMajorType
= NULL
, *clsMinorType
= NULL
;
174 cName
= sizeof(wszMinorTypeName
) / sizeof(WCHAR
);
175 if (RegEnumKeyExW(hkeyMajorType
, i1
, wszMinorTypeName
, &cName
, NULL
, NULL
, NULL
, NULL
) != ERROR_SUCCESS
) continue;
177 clsMinorType
= CoTaskMemAlloc(sizeof(CLSID
));
178 if (!clsMinorType
) continue;
180 clsMajorType
= CoTaskMemAlloc(sizeof(CLSID
));
181 if (!clsMajorType
) goto error_cleanup_types
;
183 hr
= CLSIDFromString(wszMinorTypeName
, clsMinorType
);
184 if (FAILED(hr
)) goto error_cleanup_types
;
186 hr
= CLSIDFromString(wszMajorTypeName
, clsMajorType
);
187 if (FAILED(hr
)) goto error_cleanup_types
;
189 if (rgPin
->nMediaTypes
== dwMediaTypeSize
)
191 DWORD dwNewSize
= dwMediaTypeSize
+ (dwMediaTypeSize
< 2 ? 1 : dwMediaTypeSize
/ 2);
192 REGPINTYPES
*lpNewMediaType
;
194 lpNewMediaType
= CoTaskMemRealloc(lpMediaType
, sizeof(REGPINTYPES
) * dwNewSize
);
195 if (!lpNewMediaType
) goto error_cleanup_types
;
197 lpMediaType
= lpNewMediaType
;
198 dwMediaTypeSize
= dwNewSize
;
201 lpMediaType
[rgPin
->nMediaTypes
].clsMajorType
= clsMajorType
;
202 lpMediaType
[rgPin
->nMediaTypes
].clsMinorType
= clsMinorType
;
203 rgPin
->nMediaTypes
++;
208 if (clsMajorType
) CoTaskMemFree(clsMajorType
);
209 if (clsMinorType
) CoTaskMemFree(clsMinorType
);
212 RegCloseKey(hkeyMajorType
);
215 RegCloseKey(hkeyTypes
);
217 if (lpMediaType
&& !rgPin
->nMediaTypes
)
219 CoTaskMemFree(lpMediaType
);
223 rgPin
->lpMediaType
= lpMediaType
;
226 static void DEVENUM_ReadPins(HKEY hkeyFilterClass
, REGFILTER2
*rgf2
)
228 HKEY hkeyPins
= NULL
;
229 DWORD dwPinsSubkeys
, i
;
230 REGFILTERPINS
*rgPins
= NULL
;
232 if (RegOpenKeyExW(hkeyFilterClass
, wszPins
, 0, KEY_READ
, &hkeyPins
) != ERROR_SUCCESS
)
235 if (RegQueryInfoKeyW(hkeyPins
, NULL
, NULL
, NULL
, &dwPinsSubkeys
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
)
238 RegCloseKey(hkeyPins
);
244 rgPins
= CoTaskMemAlloc(sizeof(REGFILTERPINS
) * dwPinsSubkeys
);
247 RegCloseKey(hkeyPins
);
252 for (i
= 0; i
< dwPinsSubkeys
; i
++)
254 HKEY hkeyPinKey
= NULL
;
255 WCHAR wszPinName
[MAX_PATH
];
256 DWORD cName
= sizeof(wszPinName
) / sizeof(WCHAR
);
258 REGFILTERPINS
*rgPin
= &rgPins
[rgf2
->u
.s1
.cPins
];
261 rgPin
->strName
= NULL
;
262 rgPin
->clsConnectsToFilter
= &GUID_NULL
;
263 rgPin
->strConnectsToPin
= NULL
;
264 rgPin
->nMediaTypes
= 0;
265 rgPin
->lpMediaType
= NULL
;
267 if (RegEnumKeyExW(hkeyPins
, i
, wszPinName
, &cName
, NULL
, NULL
, NULL
, NULL
) != ERROR_SUCCESS
) continue;
269 if (RegOpenKeyExW(hkeyPins
, wszPinName
, 0, KEY_READ
, &hkeyPinKey
) != ERROR_SUCCESS
) continue;
271 rgPin
->strName
= CoTaskMemAlloc((strlenW(wszPinName
) + 1) * sizeof(WCHAR
));
272 if (!rgPin
->strName
) goto error_cleanup
;
274 strcpyW(rgPin
->strName
, wszPinName
);
276 cbData
= sizeof(rgPin
->bMany
);
277 lRet
= RegQueryValueExW(hkeyPinKey
, wszAllowedMany
, NULL
, &Type
, (LPBYTE
)&rgPin
->bMany
, &cbData
);
278 if (lRet
!= ERROR_SUCCESS
|| Type
!= REG_DWORD
)
281 cbData
= sizeof(rgPin
->bZero
);
282 lRet
= RegQueryValueExW(hkeyPinKey
, wszAllowedZero
, NULL
, &Type
, (LPBYTE
)&rgPin
->bZero
, &cbData
);
283 if (lRet
!= ERROR_SUCCESS
|| Type
!= REG_DWORD
)
286 cbData
= sizeof(rgPin
->bOutput
);
287 lRet
= RegQueryValueExW(hkeyPinKey
, wszDirection
, NULL
, &Type
, (LPBYTE
)&rgPin
->bOutput
, &cbData
);
288 if (lRet
!= ERROR_SUCCESS
|| Type
!= REG_DWORD
)
291 cbData
= sizeof(rgPin
->bRendered
);
292 lRet
= RegQueryValueExW(hkeyPinKey
, wszIsRendered
, NULL
, &Type
, (LPBYTE
)&rgPin
->bRendered
, &cbData
);
293 if (lRet
!= ERROR_SUCCESS
|| Type
!= REG_DWORD
)
296 DEVENUM_ReadPinTypes(hkeyPinKey
, rgPin
);
303 RegCloseKey(hkeyPinKey
);
304 if (rgPin
->strName
) CoTaskMemFree(rgPin
->strName
);
307 RegCloseKey(hkeyPins
);
309 if (rgPins
&& !rgf2
->u
.s1
.cPins
)
311 CoTaskMemFree(rgPins
);
315 rgf2
->u
.s1
.rgPins
= rgPins
;
318 static HRESULT
DEVENUM_RegisterLegacyAmFilters(void)
320 HKEY hkeyFilter
= NULL
;
321 DWORD dwFilterSubkeys
, i
;
323 IFilterMapper2
*pMapper
= NULL
;
326 hr
= CoCreateInstance(&CLSID_FilterMapper2
, NULL
, CLSCTX_INPROC
,
327 &IID_IFilterMapper2
, (void **) &pMapper
);
330 lRet
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszFilterKeyName
, 0, KEY_READ
, &hkeyFilter
);
331 hr
= HRESULT_FROM_WIN32(lRet
);
336 lRet
= RegQueryInfoKeyW(hkeyFilter
, NULL
, NULL
, NULL
, &dwFilterSubkeys
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
337 hr
= HRESULT_FROM_WIN32(lRet
);
342 for (i
= 0; i
< dwFilterSubkeys
; i
++)
344 WCHAR wszFilterSubkeyName
[64];
345 DWORD cName
= sizeof(wszFilterSubkeyName
) / sizeof(WCHAR
);
346 HKEY hkeyCategoryBaseKey
;
347 WCHAR wszRegKey
[MAX_PATH
];
348 HKEY hkeyInstance
= NULL
;
350 if (RegEnumKeyExW(hkeyFilter
, i
, wszFilterSubkeyName
, &cName
, NULL
, NULL
, NULL
, NULL
) != ERROR_SUCCESS
) continue;
352 hr
= DEVENUM_GetCategoryKey(&CLSID_LegacyAmFilterCategory
, &hkeyCategoryBaseKey
, wszRegKey
, MAX_PATH
);
353 if (FAILED(hr
)) continue;
355 strcatW(wszRegKey
, wszRegSeparator
);
356 strcatW(wszRegKey
, wszFilterSubkeyName
);
358 if (RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszRegKey
, 0, KEY_READ
, &hkeyInstance
) == ERROR_SUCCESS
)
360 RegCloseKey(hkeyInstance
);
364 /* Filter is registered the IFilterMapper(1)-way in HKCR\Filter. Needs to be added to
365 * legacy am filter category. */
366 HKEY hkeyFilterClass
= NULL
;
369 WCHAR wszFilterName
[MAX_PATH
];
373 IMoniker
*pMoniker
= NULL
;
375 TRACE("Registering %s\n", debugstr_w(wszFilterSubkeyName
));
377 strcpyW(wszRegKey
, clsid_keyname
);
378 strcatW(wszRegKey
, wszRegSeparator
);
379 strcatW(wszRegKey
, wszFilterSubkeyName
);
381 if (RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszRegKey
, 0, KEY_READ
, &hkeyFilterClass
) != ERROR_SUCCESS
)
387 rgf2
.u
.s1
.rgPins
= NULL
;
389 cbData
= sizeof(wszFilterName
);
390 if (RegQueryValueExW(hkeyFilterClass
, NULL
, NULL
, &Type
, (LPBYTE
)wszFilterName
, &cbData
) != ERROR_SUCCESS
||
394 cbData
= sizeof(rgf2
.dwMerit
);
395 if (RegQueryValueExW(hkeyFilterClass
, wszMeritName
, NULL
, &Type
, (LPBYTE
)&rgf2
.dwMerit
, &cbData
) != ERROR_SUCCESS
||
399 DEVENUM_ReadPins(hkeyFilterClass
, &rgf2
);
401 res
= CLSIDFromString(wszFilterSubkeyName
, &clsidFilter
);
402 if (FAILED(res
)) goto cleanup
;
404 IFilterMapper2_RegisterFilter(pMapper
, &clsidFilter
, wszFilterName
, &pMoniker
, NULL
, NULL
, &rgf2
);
407 IMoniker_Release(pMoniker
);
411 if (hkeyFilterClass
) RegCloseKey(hkeyFilterClass
);
413 if (rgf2
.u
.s1
.rgPins
)
417 for (iPin
= 0; iPin
< rgf2
.u
.s1
.cPins
; iPin
++)
419 CoTaskMemFree(rgf2
.u
.s1
.rgPins
[iPin
].strName
);
421 if (rgf2
.u
.s1
.rgPins
[iPin
].lpMediaType
)
425 for (iType
= 0; iType
< rgf2
.u
.s1
.rgPins
[iPin
].nMediaTypes
; iType
++)
427 CoTaskMemFree((void*)rgf2
.u
.s1
.rgPins
[iPin
].lpMediaType
[iType
].clsMajorType
);
428 CoTaskMemFree((void*)rgf2
.u
.s1
.rgPins
[iPin
].lpMediaType
[iType
].clsMinorType
);
431 CoTaskMemFree((void*)rgf2
.u
.s1
.rgPins
[iPin
].lpMediaType
);
435 CoTaskMemFree((void*)rgf2
.u
.s1
.rgPins
);
441 if (hkeyFilter
) RegCloseKey(hkeyFilter
);
444 IFilterMapper2_Release(pMapper
);
449 /**********************************************************************
450 * DEVENUM_ICreateDevEnum_CreateClassEnumerator
452 static HRESULT WINAPI
DEVENUM_ICreateDevEnum_CreateClassEnumerator(
453 ICreateDevEnum
* iface
,
454 REFCLSID clsidDeviceClass
,
455 IEnumMoniker
**ppEnumMoniker
,
458 WCHAR wszRegKey
[MAX_PATH
];
463 TRACE("(%p)->(%s, %p, %x)\n", iface
, debugstr_guid(clsidDeviceClass
), ppEnumMoniker
, dwFlags
);
468 *ppEnumMoniker
= NULL
;
470 if (IsEqualGUID(clsidDeviceClass
, &CLSID_LegacyAmFilterCategory
))
472 DEVENUM_RegisterLegacyAmFilters();
475 hr
= DEVENUM_GetCategoryKey(clsidDeviceClass
, &hbasekey
, wszRegKey
, MAX_PATH
);
479 if (IsEqualGUID(clsidDeviceClass
, &CLSID_AudioRendererCategory
) ||
480 IsEqualGUID(clsidDeviceClass
, &CLSID_AudioInputDeviceCategory
) ||
481 IsEqualGUID(clsidDeviceClass
, &CLSID_VideoInputDeviceCategory
) ||
482 IsEqualGUID(clsidDeviceClass
, &CLSID_MidiRendererCategory
))
484 hr
= DEVENUM_CreateSpecialCategories();
487 if (RegOpenKeyW(hbasekey
, wszRegKey
, &hkey
) != ERROR_SUCCESS
)
489 ERR("Couldn't open registry key for special device: %s\n",
490 debugstr_guid(clsidDeviceClass
));
494 else if (RegOpenKeyW(hbasekey
, wszRegKey
, &hkey
) != ERROR_SUCCESS
)
496 FIXME("Category %s not found\n", debugstr_guid(clsidDeviceClass
));
500 return DEVENUM_IEnumMoniker_Construct(hkey
, ppEnumMoniker
);
503 /**********************************************************************
504 * ICreateDevEnum_Vtbl
506 static const ICreateDevEnumVtbl ICreateDevEnum_Vtbl
=
508 DEVENUM_ICreateDevEnum_QueryInterface
,
509 DEVENUM_ICreateDevEnum_AddRef
,
510 DEVENUM_ICreateDevEnum_Release
,
511 DEVENUM_ICreateDevEnum_CreateClassEnumerator
,
514 /**********************************************************************
515 * static CreateDevEnum instance
517 ICreateDevEnum DEVENUM_CreateDevEnum
= { &ICreateDevEnum_Vtbl
};
519 /**********************************************************************
520 * DEVENUM_CreateAMCategoryKey (INTERNAL)
522 * Creates a registry key for a category at HKEY_CURRENT_USER\Software\
523 * Microsoft\ActiveMovie\devenum\{clsid}
525 static HRESULT
DEVENUM_CreateAMCategoryKey(const CLSID
* clsidCategory
)
527 WCHAR wszRegKey
[MAX_PATH
];
529 HKEY hkeyDummy
= NULL
;
531 strcpyW(wszRegKey
, wszActiveMovieKey
);
533 if (!StringFromGUID2(clsidCategory
, wszRegKey
+ strlenW(wszRegKey
), sizeof(wszRegKey
)/sizeof(wszRegKey
[0]) - strlenW(wszRegKey
)))
538 LONG lRes
= RegCreateKeyW(HKEY_CURRENT_USER
, wszRegKey
, &hkeyDummy
);
539 res
= HRESULT_FROM_WIN32(lRes
);
543 RegCloseKey(hkeyDummy
);
546 ERR("Failed to create key HKEY_CURRENT_USER\\%s\n", debugstr_w(wszRegKey
));
551 static HANDLE DEVENUM_populate_handle
;
552 static const WCHAR DEVENUM_populate_handle_nameW
[] =
553 {'_','_','W','I','N','E','_',
554 'D','e','v','e','n','u','m','_',
555 'P','o','p','u','l','a','t','e',0};
557 /**********************************************************************
558 * DEVENUM_CreateSpecialCategories (INTERNAL)
560 * Creates the keys in the registry for the dynamic categories
562 static HRESULT
DEVENUM_CreateSpecialCategories(void)
565 WCHAR szDSoundNameFormat
[MAX_PATH
+ 1];
566 WCHAR szDSoundName
[MAX_PATH
+ 1];
567 DWORD iDefaultDevice
= -1;
569 IFilterMapper2
* pMapper
= NULL
;
572 WCHAR path
[MAX_PATH
];
575 if (DEVENUM_populate_handle
)
577 DEVENUM_populate_handle
= CreateEventW(NULL
, TRUE
, FALSE
, DEVENUM_populate_handle_nameW
);
578 if (GetLastError() == ERROR_ALREADY_EXISTS
)
580 /* Webcams can take some time to scan if the driver is badly written and it enables them,
581 * so have a 10 s timeout here
583 if (WaitForSingleObject(DEVENUM_populate_handle
, 10000) == WAIT_TIMEOUT
)
584 WARN("Waiting for object timed out\n");
585 TRACE("No need to rescan\n");
588 TRACE("Scanning for devices\n");
590 /* Since devices can change between session, for example because you just plugged in a webcam
591 * or switched from pulseaudio to alsa, delete all old devices first
593 if (SUCCEEDED(DEVENUM_GetCategoryKey(&CLSID_AudioRendererCategory
, &basekey
, path
, MAX_PATH
)))
594 RegDeleteTreeW(basekey
, path
);
595 if (SUCCEEDED(DEVENUM_GetCategoryKey(&CLSID_AudioInputDeviceCategory
, &basekey
, path
, MAX_PATH
)))
596 RegDeleteTreeW(basekey
, path
);
597 if (SUCCEEDED(DEVENUM_GetCategoryKey(&CLSID_VideoInputDeviceCategory
, &basekey
, path
, MAX_PATH
)))
598 RegDeleteTreeW(basekey
, path
);
599 if (SUCCEEDED(DEVENUM_GetCategoryKey(&CLSID_MidiRendererCategory
, &basekey
, path
, MAX_PATH
)))
600 RegDeleteTreeW(basekey
, path
);
603 rf2
.dwMerit
= MERIT_PREFERRED
;
605 rf2
.u
.s2
.rgPins2
= &rfp2
;
608 rfp2
.lpMedium
= NULL
;
609 rfp2
.clsPinCategory
= &IID_NULL
;
611 if (!LoadStringW(DEVENUM_hInstance
, IDS_DEVENUM_DS
, szDSoundNameFormat
, sizeof(szDSoundNameFormat
)/sizeof(szDSoundNameFormat
[0])-1))
613 ERR("Couldn't get string resource (GetLastError() is %d)\n", GetLastError());
614 return HRESULT_FROM_WIN32(GetLastError());
617 res
= CoCreateInstance(&CLSID_FilterMapper2
, NULL
, CLSCTX_INPROC
,
618 &IID_IFilterMapper2
, (void **) &pMapper
);
620 * Fill in info for devices
628 REGPINTYPES
* pTypes
;
629 IPropertyBag
* pPropBag
= NULL
;
631 numDevs
= waveOutGetNumDevs();
633 res
= DEVENUM_CreateAMCategoryKey(&CLSID_AudioRendererCategory
);
634 if (FAILED(res
)) /* can't register any devices in this category */
637 rfp2
.dwFlags
= REG_PINFLAG_B_RENDERER
;
638 for (i
= 0; i
< numDevs
; i
++)
640 if (waveOutGetDevCapsW(i
, &wocaps
, sizeof(WAVEOUTCAPSW
))
643 IMoniker
* pMoniker
= NULL
;
645 rfp2
.nMediaTypes
= 1;
646 pTypes
= CoTaskMemAlloc(rfp2
.nMediaTypes
* sizeof(REGPINTYPES
));
649 IFilterMapper2_Release(pMapper
);
650 return E_OUTOFMEMORY
;
652 /* FIXME: Native devenum seems to register a lot more types for
653 * DSound than we do. Not sure what purpose they serve */
654 pTypes
[0].clsMajorType
= &MEDIATYPE_Audio
;
655 pTypes
[0].clsMinorType
= &MEDIASUBTYPE_PCM
;
657 rfp2
.lpMediaType
= pTypes
;
659 res
= IFilterMapper2_RegisterFilter(pMapper
,
663 &CLSID_AudioRendererCategory
,
672 V_UNION(&var
, ulVal
) = i
;
673 res
= IMoniker_BindToStorage(pMoniker
, NULL
, NULL
, &IID_IPropertyBag
, (LPVOID
)&pPropBag
);
675 res
= IPropertyBag_Write(pPropBag
, wszWaveOutID
, &var
);
679 V_VT(&var
) = VT_LPWSTR
;
680 V_UNION(&var
, bstrVal
) = wocaps
.szPname
;
682 res
= IPropertyBag_Write(pPropBag
, wszFriendlyName
, &var
);
684 IPropertyBag_Release(pPropBag
);
685 IMoniker_Release(pMoniker
);
689 wsprintfW(szDSoundName
, szDSoundNameFormat
, wocaps
.szPname
);
690 res
= IFilterMapper2_RegisterFilter(pMapper
,
694 &CLSID_AudioRendererCategory
,
698 /* FIXME: do additional stuff with IMoniker here, depending on what RegisterFilter does */
701 IMoniker_Release(pMoniker
);
703 if (i
== iDefaultDevice
)
705 FIXME("Default device\n");
708 CoTaskMemFree(pTypes
);
712 numDevs
= waveInGetNumDevs();
714 res
= DEVENUM_CreateAMCategoryKey(&CLSID_AudioInputDeviceCategory
);
715 if (FAILED(res
)) /* can't register any devices in this category */
718 rfp2
.dwFlags
= REG_PINFLAG_B_OUTPUT
;
719 for (i
= 0; i
< numDevs
; i
++)
721 if (waveInGetDevCapsW(i
, &wicaps
, sizeof(WAVEINCAPSW
))
724 IMoniker
* pMoniker
= NULL
;
726 rfp2
.nMediaTypes
= 1;
727 pTypes
= CoTaskMemAlloc(rfp2
.nMediaTypes
* sizeof(REGPINTYPES
));
730 IFilterMapper2_Release(pMapper
);
731 return E_OUTOFMEMORY
;
734 /* FIXME: Not sure if these are correct */
735 pTypes
[0].clsMajorType
= &MEDIATYPE_Audio
;
736 pTypes
[0].clsMinorType
= &MEDIASUBTYPE_PCM
;
738 rfp2
.lpMediaType
= pTypes
;
740 res
= IFilterMapper2_RegisterFilter(pMapper
,
744 &CLSID_AudioInputDeviceCategory
,
753 V_UNION(&var
, ulVal
) = i
;
754 res
= IMoniker_BindToStorage(pMoniker
, NULL
, NULL
, &IID_IPropertyBag
, (LPVOID
)&pPropBag
);
756 res
= IPropertyBag_Write(pPropBag
, wszWaveInID
, &var
);
760 V_VT(&var
) = VT_LPWSTR
;
761 V_UNION(&var
, bstrVal
) = wicaps
.szPname
;
763 res
= IPropertyBag_Write(pPropBag
, wszFriendlyName
, &var
);
766 IPropertyBag_Release(pPropBag
);
767 IMoniker_Release(pMoniker
);
770 CoTaskMemFree(pTypes
);
774 numDevs
= midiOutGetNumDevs();
776 res
= DEVENUM_CreateAMCategoryKey(&CLSID_MidiRendererCategory
);
777 if (FAILED(res
)) /* can't register any devices in this category */
780 rfp2
.dwFlags
= REG_PINFLAG_B_RENDERER
;
781 for (i
= 0; i
< numDevs
; i
++)
783 if (midiOutGetDevCapsW(i
, &mocaps
, sizeof(MIDIOUTCAPSW
))
786 IMoniker
* pMoniker
= NULL
;
788 rfp2
.nMediaTypes
= 1;
789 pTypes
= CoTaskMemAlloc(rfp2
.nMediaTypes
* sizeof(REGPINTYPES
));
792 IFilterMapper2_Release(pMapper
);
793 return E_OUTOFMEMORY
;
796 /* FIXME: Not sure if these are correct */
797 pTypes
[0].clsMajorType
= &MEDIATYPE_Midi
;
798 pTypes
[0].clsMinorType
= &MEDIASUBTYPE_None
;
800 rfp2
.lpMediaType
= pTypes
;
802 res
= IFilterMapper2_RegisterFilter(pMapper
,
803 &CLSID_AVIMIDIRender
,
806 &CLSID_MidiRendererCategory
,
810 /* FIXME: do additional stuff with IMoniker here, depending on what RegisterFilter does */
811 /* Native version sets MidiOutId */
814 IMoniker_Release(pMoniker
);
816 if (i
== iDefaultDevice
)
818 FIXME("Default device\n");
821 CoTaskMemFree(pTypes
);
824 res
= DEVENUM_CreateAMCategoryKey(&CLSID_VideoInputDeviceCategory
);
826 for (i
= 0; i
< 10; i
++)
828 WCHAR szDeviceName
[32], szDeviceVersion
[32], szDevicePath
[10];
830 if (capGetDriverDescriptionW ((WORD
) i
,
831 szDeviceName
, sizeof(szDeviceName
)/sizeof(WCHAR
),
832 szDeviceVersion
, sizeof(szDeviceVersion
)/sizeof(WCHAR
)))
834 IMoniker
* pMoniker
= NULL
;
835 WCHAR dprintf
[] = { 'v','i','d','e','o','%','d',0 };
836 snprintfW(szDevicePath
, sizeof(szDevicePath
)/sizeof(WCHAR
), dprintf
, i
);
837 /* The above code prevents 1 device with a different ID overwriting another */
839 rfp2
.nMediaTypes
= 1;
840 pTypes
= CoTaskMemAlloc(rfp2
.nMediaTypes
* sizeof(REGPINTYPES
));
842 IFilterMapper2_Release(pMapper
);
843 return E_OUTOFMEMORY
;
846 pTypes
[0].clsMajorType
= &MEDIATYPE_Video
;
847 pTypes
[0].clsMinorType
= &MEDIASUBTYPE_None
;
849 rfp2
.lpMediaType
= pTypes
;
851 res
= IFilterMapper2_RegisterFilter(pMapper
,
855 &CLSID_VideoInputDeviceCategory
,
860 OLECHAR wszVfwIndex
[] = { 'V','F','W','I','n','d','e','x',0 };
863 V_UNION(&var
, ulVal
) = i
;
864 res
= IMoniker_BindToStorage(pMoniker
, NULL
, NULL
, &IID_IPropertyBag
, (LPVOID
)&pPropBag
);
865 if (SUCCEEDED(res
)) {
866 res
= IPropertyBag_Write(pPropBag
, wszVfwIndex
, &var
);
867 IPropertyBag_Release(pPropBag
);
869 IMoniker_Release(pMoniker
);
872 if (i
== iDefaultDevice
) FIXME("Default device\n");
873 CoTaskMemFree(pTypes
);
879 IFilterMapper2_Release(pMapper
);
880 SetEvent(DEVENUM_populate_handle
);