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"
32 #include "wine/debug.h"
33 #include "wine/unicode.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(devenum
);
38 extern HINSTANCE DEVENUM_hInstance
;
40 const WCHAR wszInstanceKeyName
[] ={'I','n','s','t','a','n','c','e',0};
42 static const WCHAR wszRegSeparator
[] = {'\\', 0 };
43 static const WCHAR wszActiveMovieKey
[] = {'S','o','f','t','w','a','r','e','\\',
44 'M','i','c','r','o','s','o','f','t','\\',
45 'A','c','t','i','v','e','M','o','v','i','e','\\',
46 'd','e','v','e','n','u','m','\\',0};
47 static const WCHAR wszFilterKeyName
[] = {'F','i','l','t','e','r',0};
48 static const WCHAR wszMeritName
[] = {'M','e','r','i','t',0};
49 static const WCHAR wszPins
[] = {'P','i','n','s',0};
50 static const WCHAR wszAllowedMany
[] = {'A','l','l','o','w','e','d','M','a','n','y',0};
51 static const WCHAR wszAllowedZero
[] = {'A','l','l','o','w','e','d','Z','e','r','o',0};
52 static const WCHAR wszDirection
[] = {'D','i','r','e','c','t','i','o','n',0};
53 static const WCHAR wszIsRendered
[] = {'I','s','R','e','n','d','e','r','e','d',0};
54 static const WCHAR wszTypes
[] = {'T','y','p','e','s',0};
55 static const WCHAR wszFriendlyName
[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
56 static const WCHAR wszWaveInID
[] = {'W','a','v','e','I','n','I','D',0};
57 static const WCHAR wszWaveOutID
[] = {'W','a','v','e','O','u','t','I','D',0};
59 static ULONG WINAPI
DEVENUM_ICreateDevEnum_AddRef(ICreateDevEnum
* iface
);
60 static HRESULT
DEVENUM_CreateSpecialCategories(void);
62 /**********************************************************************
63 * DEVENUM_ICreateDevEnum_QueryInterface (also IUnknown)
65 static HRESULT WINAPI
DEVENUM_ICreateDevEnum_QueryInterface(ICreateDevEnum
*iface
, REFIID riid
,
68 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
73 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
74 IsEqualGUID(riid
, &IID_ICreateDevEnum
))
77 DEVENUM_ICreateDevEnum_AddRef(iface
);
81 FIXME("- no interface IID: %s\n", debugstr_guid(riid
));
86 /**********************************************************************
87 * DEVENUM_ICreateDevEnum_AddRef (also IUnknown)
89 static ULONG WINAPI
DEVENUM_ICreateDevEnum_AddRef(ICreateDevEnum
* iface
)
95 return 2; /* non-heap based object */
98 /**********************************************************************
99 * DEVENUM_ICreateDevEnum_Release (also IUnknown)
101 static ULONG WINAPI
DEVENUM_ICreateDevEnum_Release(ICreateDevEnum
* iface
)
105 DEVENUM_UnlockModule();
107 return 1; /* non-heap based object */
110 HRESULT
DEVENUM_GetCategoryKey(REFCLSID clsidDeviceClass
, HKEY
*pBaseKey
, WCHAR
*wszRegKeyName
, UINT maxLen
)
112 if (IsEqualGUID(clsidDeviceClass
, &CLSID_AudioRendererCategory
) ||
113 IsEqualGUID(clsidDeviceClass
, &CLSID_AudioInputDeviceCategory
) ||
114 IsEqualGUID(clsidDeviceClass
, &CLSID_VideoInputDeviceCategory
) ||
115 IsEqualGUID(clsidDeviceClass
, &CLSID_MidiRendererCategory
))
117 *pBaseKey
= HKEY_CURRENT_USER
;
118 strcpyW(wszRegKeyName
, wszActiveMovieKey
);
120 if (!StringFromGUID2(clsidDeviceClass
, wszRegKeyName
+ strlenW(wszRegKeyName
), maxLen
- strlenW(wszRegKeyName
)))
121 return E_OUTOFMEMORY
;
125 *pBaseKey
= HKEY_CLASSES_ROOT
;
126 strcpyW(wszRegKeyName
, clsid_keyname
);
127 strcatW(wszRegKeyName
, wszRegSeparator
);
129 if (!StringFromGUID2(clsidDeviceClass
, wszRegKeyName
+ CLSID_STR_LEN
, maxLen
- CLSID_STR_LEN
))
130 return E_OUTOFMEMORY
;
132 strcatW(wszRegKeyName
, wszRegSeparator
);
133 strcatW(wszRegKeyName
, wszInstanceKeyName
);
139 static void DEVENUM_ReadPinTypes(HKEY hkeyPinKey
, REGFILTERPINS
*rgPin
)
141 HKEY hkeyTypes
= NULL
;
142 DWORD dwMajorTypes
, i
;
143 REGPINTYPES
*lpMediaType
= NULL
;
144 DWORD dwMediaTypeSize
= 0;
146 if (RegOpenKeyExW(hkeyPinKey
, wszTypes
, 0, KEY_READ
, &hkeyTypes
) != ERROR_SUCCESS
)
149 if (RegQueryInfoKeyW(hkeyTypes
, NULL
, NULL
, NULL
, &dwMajorTypes
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
)
152 RegCloseKey(hkeyTypes
);
156 for (i
= 0; i
< dwMajorTypes
; i
++)
158 HKEY hkeyMajorType
= NULL
;
159 WCHAR wszMajorTypeName
[64];
160 DWORD cName
= sizeof(wszMajorTypeName
) / sizeof(WCHAR
);
161 DWORD dwMinorTypes
, i1
;
163 if (RegEnumKeyExW(hkeyTypes
, i
, wszMajorTypeName
, &cName
, NULL
, NULL
, NULL
, NULL
) != ERROR_SUCCESS
) continue;
165 if (RegOpenKeyExW(hkeyTypes
, wszMajorTypeName
, 0, KEY_READ
, &hkeyMajorType
) != ERROR_SUCCESS
) continue;
167 if (RegQueryInfoKeyW(hkeyMajorType
, NULL
, NULL
, NULL
, &dwMinorTypes
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
)
170 RegCloseKey(hkeyMajorType
);
174 for (i1
= 0; i1
< dwMinorTypes
; i1
++)
176 WCHAR wszMinorTypeName
[64];
177 CLSID
*clsMajorType
= NULL
, *clsMinorType
= NULL
;
180 cName
= sizeof(wszMinorTypeName
) / sizeof(WCHAR
);
181 if (RegEnumKeyExW(hkeyMajorType
, i1
, wszMinorTypeName
, &cName
, NULL
, NULL
, NULL
, NULL
) != ERROR_SUCCESS
) continue;
183 clsMinorType
= CoTaskMemAlloc(sizeof(CLSID
));
184 if (!clsMinorType
) continue;
186 clsMajorType
= CoTaskMemAlloc(sizeof(CLSID
));
187 if (!clsMajorType
) goto error_cleanup_types
;
189 hr
= CLSIDFromString(wszMinorTypeName
, clsMinorType
);
190 if (FAILED(hr
)) goto error_cleanup_types
;
192 hr
= CLSIDFromString(wszMajorTypeName
, clsMajorType
);
193 if (FAILED(hr
)) goto error_cleanup_types
;
195 if (rgPin
->nMediaTypes
== dwMediaTypeSize
)
197 DWORD dwNewSize
= dwMediaTypeSize
+ (dwMediaTypeSize
< 2 ? 1 : dwMediaTypeSize
/ 2);
198 REGPINTYPES
*lpNewMediaType
;
200 lpNewMediaType
= CoTaskMemRealloc(lpMediaType
, sizeof(REGPINTYPES
) * dwNewSize
);
201 if (!lpNewMediaType
) goto error_cleanup_types
;
203 lpMediaType
= lpNewMediaType
;
204 dwMediaTypeSize
= dwNewSize
;
207 lpMediaType
[rgPin
->nMediaTypes
].clsMajorType
= clsMajorType
;
208 lpMediaType
[rgPin
->nMediaTypes
].clsMinorType
= clsMinorType
;
209 rgPin
->nMediaTypes
++;
214 if (clsMajorType
) CoTaskMemFree(clsMajorType
);
215 if (clsMinorType
) CoTaskMemFree(clsMinorType
);
218 RegCloseKey(hkeyMajorType
);
221 RegCloseKey(hkeyTypes
);
223 if (lpMediaType
&& !rgPin
->nMediaTypes
)
225 CoTaskMemFree(lpMediaType
);
229 rgPin
->lpMediaType
= lpMediaType
;
232 static void DEVENUM_ReadPins(HKEY hkeyFilterClass
, REGFILTER2
*rgf2
)
234 HKEY hkeyPins
= NULL
;
235 DWORD dwPinsSubkeys
, i
;
236 REGFILTERPINS
*rgPins
= NULL
;
238 if (RegOpenKeyExW(hkeyFilterClass
, wszPins
, 0, KEY_READ
, &hkeyPins
) != ERROR_SUCCESS
)
241 if (RegQueryInfoKeyW(hkeyPins
, NULL
, NULL
, NULL
, &dwPinsSubkeys
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
)
244 RegCloseKey(hkeyPins
);
250 rgPins
= CoTaskMemAlloc(sizeof(REGFILTERPINS
) * dwPinsSubkeys
);
253 RegCloseKey(hkeyPins
);
258 for (i
= 0; i
< dwPinsSubkeys
; i
++)
260 HKEY hkeyPinKey
= NULL
;
261 WCHAR wszPinName
[MAX_PATH
];
262 DWORD cName
= sizeof(wszPinName
) / sizeof(WCHAR
);
264 REGFILTERPINS
*rgPin
= &rgPins
[rgf2
->u
.s1
.cPins
];
267 rgPin
->strName
= NULL
;
268 rgPin
->clsConnectsToFilter
= &GUID_NULL
;
269 rgPin
->strConnectsToPin
= NULL
;
270 rgPin
->nMediaTypes
= 0;
271 rgPin
->lpMediaType
= NULL
;
273 if (RegEnumKeyExW(hkeyPins
, i
, wszPinName
, &cName
, NULL
, NULL
, NULL
, NULL
) != ERROR_SUCCESS
) continue;
275 if (RegOpenKeyExW(hkeyPins
, wszPinName
, 0, KEY_READ
, &hkeyPinKey
) != ERROR_SUCCESS
) continue;
277 rgPin
->strName
= CoTaskMemAlloc((strlenW(wszPinName
) + 1) * sizeof(WCHAR
));
278 if (!rgPin
->strName
) goto error_cleanup
;
280 strcpyW(rgPin
->strName
, wszPinName
);
282 cbData
= sizeof(rgPin
->bMany
);
283 lRet
= RegQueryValueExW(hkeyPinKey
, wszAllowedMany
, NULL
, &Type
, (LPBYTE
)&rgPin
->bMany
, &cbData
);
284 if (lRet
!= ERROR_SUCCESS
|| Type
!= REG_DWORD
)
287 cbData
= sizeof(rgPin
->bZero
);
288 lRet
= RegQueryValueExW(hkeyPinKey
, wszAllowedZero
, NULL
, &Type
, (LPBYTE
)&rgPin
->bZero
, &cbData
);
289 if (lRet
!= ERROR_SUCCESS
|| Type
!= REG_DWORD
)
292 cbData
= sizeof(rgPin
->bOutput
);
293 lRet
= RegQueryValueExW(hkeyPinKey
, wszDirection
, NULL
, &Type
, (LPBYTE
)&rgPin
->bOutput
, &cbData
);
294 if (lRet
!= ERROR_SUCCESS
|| Type
!= REG_DWORD
)
297 cbData
= sizeof(rgPin
->bRendered
);
298 lRet
= RegQueryValueExW(hkeyPinKey
, wszIsRendered
, NULL
, &Type
, (LPBYTE
)&rgPin
->bRendered
, &cbData
);
299 if (lRet
!= ERROR_SUCCESS
|| Type
!= REG_DWORD
)
302 DEVENUM_ReadPinTypes(hkeyPinKey
, rgPin
);
309 RegCloseKey(hkeyPinKey
);
310 if (rgPin
->strName
) CoTaskMemFree(rgPin
->strName
);
313 RegCloseKey(hkeyPins
);
315 if (rgPins
&& !rgf2
->u
.s1
.cPins
)
317 CoTaskMemFree(rgPins
);
321 rgf2
->u
.s1
.rgPins
= rgPins
;
324 static HRESULT
DEVENUM_RegisterLegacyAmFilters(void)
326 HKEY hkeyFilter
= NULL
;
327 DWORD dwFilterSubkeys
, i
;
329 IFilterMapper2
*pMapper
= NULL
;
332 hr
= CoCreateInstance(&CLSID_FilterMapper2
, NULL
, CLSCTX_INPROC
,
333 &IID_IFilterMapper2
, (void **) &pMapper
);
336 lRet
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszFilterKeyName
, 0, KEY_READ
, &hkeyFilter
);
337 hr
= HRESULT_FROM_WIN32(lRet
);
342 lRet
= RegQueryInfoKeyW(hkeyFilter
, NULL
, NULL
, NULL
, &dwFilterSubkeys
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
343 hr
= HRESULT_FROM_WIN32(lRet
);
348 for (i
= 0; i
< dwFilterSubkeys
; i
++)
350 WCHAR wszFilterSubkeyName
[64];
351 DWORD cName
= sizeof(wszFilterSubkeyName
) / sizeof(WCHAR
);
352 HKEY hkeyCategoryBaseKey
;
353 WCHAR wszRegKey
[MAX_PATH
];
354 HKEY hkeyInstance
= NULL
;
356 if (RegEnumKeyExW(hkeyFilter
, i
, wszFilterSubkeyName
, &cName
, NULL
, NULL
, NULL
, NULL
) != ERROR_SUCCESS
) continue;
358 hr
= DEVENUM_GetCategoryKey(&CLSID_LegacyAmFilterCategory
, &hkeyCategoryBaseKey
, wszRegKey
, MAX_PATH
);
359 if (FAILED(hr
)) continue;
361 strcatW(wszRegKey
, wszRegSeparator
);
362 strcatW(wszRegKey
, wszFilterSubkeyName
);
364 if (RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszRegKey
, 0, KEY_READ
, &hkeyInstance
) == ERROR_SUCCESS
)
366 RegCloseKey(hkeyInstance
);
370 /* Filter is registered the IFilterMapper(1)-way in HKCR\Filter. Needs to be added to
371 * legacy am filter category. */
372 HKEY hkeyFilterClass
= NULL
;
375 WCHAR wszFilterName
[MAX_PATH
];
379 IMoniker
*pMoniker
= NULL
;
381 TRACE("Registering %s\n", debugstr_w(wszFilterSubkeyName
));
383 strcpyW(wszRegKey
, clsid_keyname
);
384 strcatW(wszRegKey
, wszRegSeparator
);
385 strcatW(wszRegKey
, wszFilterSubkeyName
);
387 if (RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszRegKey
, 0, KEY_READ
, &hkeyFilterClass
) != ERROR_SUCCESS
)
393 rgf2
.u
.s1
.rgPins
= NULL
;
395 cbData
= sizeof(wszFilterName
);
396 if (RegQueryValueExW(hkeyFilterClass
, NULL
, NULL
, &Type
, (LPBYTE
)wszFilterName
, &cbData
) != ERROR_SUCCESS
||
400 cbData
= sizeof(rgf2
.dwMerit
);
401 if (RegQueryValueExW(hkeyFilterClass
, wszMeritName
, NULL
, &Type
, (LPBYTE
)&rgf2
.dwMerit
, &cbData
) != ERROR_SUCCESS
||
405 DEVENUM_ReadPins(hkeyFilterClass
, &rgf2
);
407 res
= CLSIDFromString(wszFilterSubkeyName
, &clsidFilter
);
408 if (FAILED(res
)) goto cleanup
;
410 IFilterMapper2_RegisterFilter(pMapper
, &clsidFilter
, wszFilterName
, &pMoniker
, NULL
, NULL
, &rgf2
);
413 IMoniker_Release(pMoniker
);
417 if (hkeyFilterClass
) RegCloseKey(hkeyFilterClass
);
419 if (rgf2
.u
.s1
.rgPins
)
423 for (iPin
= 0; iPin
< rgf2
.u
.s1
.cPins
; iPin
++)
425 CoTaskMemFree(rgf2
.u
.s1
.rgPins
[iPin
].strName
);
427 if (rgf2
.u
.s1
.rgPins
[iPin
].lpMediaType
)
431 for (iType
= 0; iType
< rgf2
.u
.s1
.rgPins
[iPin
].nMediaTypes
; iType
++)
433 CoTaskMemFree((void*)rgf2
.u
.s1
.rgPins
[iPin
].lpMediaType
[iType
].clsMajorType
);
434 CoTaskMemFree((void*)rgf2
.u
.s1
.rgPins
[iPin
].lpMediaType
[iType
].clsMinorType
);
437 CoTaskMemFree((void*)rgf2
.u
.s1
.rgPins
[iPin
].lpMediaType
);
441 CoTaskMemFree((void*)rgf2
.u
.s1
.rgPins
);
447 if (hkeyFilter
) RegCloseKey(hkeyFilter
);
450 IFilterMapper2_Release(pMapper
);
455 /**********************************************************************
456 * DEVENUM_ICreateDevEnum_CreateClassEnumerator
458 static HRESULT WINAPI
DEVENUM_ICreateDevEnum_CreateClassEnumerator(
459 ICreateDevEnum
* iface
,
460 REFCLSID clsidDeviceClass
,
461 IEnumMoniker
**ppEnumMoniker
,
464 WCHAR wszRegKey
[MAX_PATH
];
469 TRACE("(%p)->(%s, %p, %x)\n", iface
, debugstr_guid(clsidDeviceClass
), ppEnumMoniker
, dwFlags
);
474 *ppEnumMoniker
= NULL
;
476 if (IsEqualGUID(clsidDeviceClass
, &CLSID_LegacyAmFilterCategory
))
478 DEVENUM_RegisterLegacyAmFilters();
481 hr
= DEVENUM_GetCategoryKey(clsidDeviceClass
, &hbasekey
, wszRegKey
, MAX_PATH
);
485 if (IsEqualGUID(clsidDeviceClass
, &CLSID_AudioRendererCategory
) ||
486 IsEqualGUID(clsidDeviceClass
, &CLSID_AudioInputDeviceCategory
) ||
487 IsEqualGUID(clsidDeviceClass
, &CLSID_VideoInputDeviceCategory
) ||
488 IsEqualGUID(clsidDeviceClass
, &CLSID_MidiRendererCategory
))
490 hr
= DEVENUM_CreateSpecialCategories();
493 if (RegOpenKeyW(hbasekey
, wszRegKey
, &hkey
) != ERROR_SUCCESS
)
495 ERR("Couldn't open registry key for special device: %s\n",
496 debugstr_guid(clsidDeviceClass
));
500 else if (RegOpenKeyW(hbasekey
, wszRegKey
, &hkey
) != ERROR_SUCCESS
)
502 FIXME("Category %s not found\n", debugstr_guid(clsidDeviceClass
));
506 return DEVENUM_IEnumMoniker_Construct(hkey
, ppEnumMoniker
);
509 /**********************************************************************
510 * ICreateDevEnum_Vtbl
512 static const ICreateDevEnumVtbl ICreateDevEnum_Vtbl
=
514 DEVENUM_ICreateDevEnum_QueryInterface
,
515 DEVENUM_ICreateDevEnum_AddRef
,
516 DEVENUM_ICreateDevEnum_Release
,
517 DEVENUM_ICreateDevEnum_CreateClassEnumerator
,
520 /**********************************************************************
521 * static CreateDevEnum instance
523 ICreateDevEnum DEVENUM_CreateDevEnum
= { &ICreateDevEnum_Vtbl
};
525 /**********************************************************************
526 * DEVENUM_CreateAMCategoryKey (INTERNAL)
528 * Creates a registry key for a category at HKEY_CURRENT_USER\Software\
529 * Microsoft\ActiveMovie\devenum\{clsid}
531 static HRESULT
DEVENUM_CreateAMCategoryKey(const CLSID
* clsidCategory
)
533 WCHAR wszRegKey
[MAX_PATH
];
535 HKEY hkeyDummy
= NULL
;
537 strcpyW(wszRegKey
, wszActiveMovieKey
);
539 if (!StringFromGUID2(clsidCategory
, wszRegKey
+ strlenW(wszRegKey
), sizeof(wszRegKey
)/sizeof(wszRegKey
[0]) - strlenW(wszRegKey
)))
544 LONG lRes
= RegCreateKeyW(HKEY_CURRENT_USER
, wszRegKey
, &hkeyDummy
);
545 res
= HRESULT_FROM_WIN32(lRes
);
549 RegCloseKey(hkeyDummy
);
552 ERR("Failed to create key HKEY_CURRENT_USER\\%s\n", debugstr_w(wszRegKey
));
557 static HANDLE DEVENUM_populate_handle
;
558 static const WCHAR DEVENUM_populate_handle_nameW
[] =
559 {'_','_','W','I','N','E','_',
560 'D','e','v','e','n','u','m','_',
561 'P','o','p','u','l','a','t','e',0};
563 /**********************************************************************
564 * DEVENUM_CreateSpecialCategories (INTERNAL)
566 * Creates the keys in the registry for the dynamic categories
568 static HRESULT
DEVENUM_CreateSpecialCategories(void)
571 WCHAR szDSoundNameFormat
[MAX_PATH
+ 1];
572 WCHAR szDSoundName
[MAX_PATH
+ 1];
573 DWORD iDefaultDevice
= -1;
575 IFilterMapper2
* pMapper
= NULL
;
578 WCHAR path
[MAX_PATH
];
581 if (DEVENUM_populate_handle
)
583 DEVENUM_populate_handle
= CreateEventW(NULL
, TRUE
, FALSE
, DEVENUM_populate_handle_nameW
);
584 if (GetLastError() == ERROR_ALREADY_EXISTS
)
586 /* Webcams can take some time to scan if the driver is badly written and it enables them,
587 * so have a 10 s timeout here
589 if (WaitForSingleObject(DEVENUM_populate_handle
, 10000) == WAIT_TIMEOUT
)
590 WARN("Waiting for object timed out\n");
591 TRACE("No need to rescan\n");
594 TRACE("Scanning for devices\n");
596 /* Since devices can change between session, for example because you just plugged in a webcam
597 * or switched from pulseaudio to alsa, delete all old devices first
599 if (SUCCEEDED(DEVENUM_GetCategoryKey(&CLSID_AudioRendererCategory
, &basekey
, path
, MAX_PATH
)))
600 RegDeleteTreeW(basekey
, path
);
601 if (SUCCEEDED(DEVENUM_GetCategoryKey(&CLSID_AudioInputDeviceCategory
, &basekey
, path
, MAX_PATH
)))
602 RegDeleteTreeW(basekey
, path
);
603 if (SUCCEEDED(DEVENUM_GetCategoryKey(&CLSID_VideoInputDeviceCategory
, &basekey
, path
, MAX_PATH
)))
604 RegDeleteTreeW(basekey
, path
);
605 if (SUCCEEDED(DEVENUM_GetCategoryKey(&CLSID_MidiRendererCategory
, &basekey
, path
, MAX_PATH
)))
606 RegDeleteTreeW(basekey
, path
);
609 rf2
.dwMerit
= MERIT_PREFERRED
;
611 rf2
.u
.s2
.rgPins2
= &rfp2
;
614 rfp2
.lpMedium
= NULL
;
615 rfp2
.clsPinCategory
= &IID_NULL
;
617 if (!LoadStringW(DEVENUM_hInstance
, IDS_DEVENUM_DS
, szDSoundNameFormat
, sizeof(szDSoundNameFormat
)/sizeof(szDSoundNameFormat
[0])-1))
619 ERR("Couldn't get string resource (GetLastError() is %d)\n", GetLastError());
620 return HRESULT_FROM_WIN32(GetLastError());
623 res
= CoCreateInstance(&CLSID_FilterMapper2
, NULL
, CLSCTX_INPROC
,
624 &IID_IFilterMapper2
, (void **) &pMapper
);
626 * Fill in info for devices
634 REGPINTYPES
* pTypes
;
635 IPropertyBag
* pPropBag
= NULL
;
637 numDevs
= waveOutGetNumDevs();
639 res
= DEVENUM_CreateAMCategoryKey(&CLSID_AudioRendererCategory
);
640 if (FAILED(res
)) /* can't register any devices in this category */
643 rfp2
.dwFlags
= REG_PINFLAG_B_RENDERER
;
644 for (i
= 0; i
< numDevs
; i
++)
646 if (waveOutGetDevCapsW(i
, &wocaps
, sizeof(WAVEOUTCAPSW
))
649 IMoniker
* pMoniker
= NULL
;
651 rfp2
.nMediaTypes
= 1;
652 pTypes
= CoTaskMemAlloc(rfp2
.nMediaTypes
* sizeof(REGPINTYPES
));
655 IFilterMapper2_Release(pMapper
);
656 return E_OUTOFMEMORY
;
658 /* FIXME: Native devenum seems to register a lot more types for
659 * DSound than we do. Not sure what purpose they serve */
660 pTypes
[0].clsMajorType
= &MEDIATYPE_Audio
;
661 pTypes
[0].clsMinorType
= &MEDIASUBTYPE_PCM
;
663 rfp2
.lpMediaType
= pTypes
;
665 res
= IFilterMapper2_RegisterFilter(pMapper
,
669 &CLSID_AudioRendererCategory
,
678 V_UNION(&var
, ulVal
) = i
;
679 res
= IMoniker_BindToStorage(pMoniker
, NULL
, NULL
, &IID_IPropertyBag
, (LPVOID
)&pPropBag
);
681 res
= IPropertyBag_Write(pPropBag
, wszWaveOutID
, &var
);
685 V_VT(&var
) = VT_LPWSTR
;
686 V_UNION(&var
, bstrVal
) = wocaps
.szPname
;
688 res
= IPropertyBag_Write(pPropBag
, wszFriendlyName
, &var
);
690 IPropertyBag_Release(pPropBag
);
691 IMoniker_Release(pMoniker
);
695 wsprintfW(szDSoundName
, szDSoundNameFormat
, wocaps
.szPname
);
696 res
= IFilterMapper2_RegisterFilter(pMapper
,
700 &CLSID_AudioRendererCategory
,
704 /* FIXME: do additional stuff with IMoniker here, depending on what RegisterFilter does */
707 IMoniker_Release(pMoniker
);
709 if (i
== iDefaultDevice
)
711 FIXME("Default device\n");
714 CoTaskMemFree(pTypes
);
718 numDevs
= waveInGetNumDevs();
720 res
= DEVENUM_CreateAMCategoryKey(&CLSID_AudioInputDeviceCategory
);
721 if (FAILED(res
)) /* can't register any devices in this category */
724 rfp2
.dwFlags
= REG_PINFLAG_B_OUTPUT
;
725 for (i
= 0; i
< numDevs
; i
++)
727 if (waveInGetDevCapsW(i
, &wicaps
, sizeof(WAVEINCAPSW
))
730 IMoniker
* pMoniker
= NULL
;
732 rfp2
.nMediaTypes
= 1;
733 pTypes
= CoTaskMemAlloc(rfp2
.nMediaTypes
* sizeof(REGPINTYPES
));
736 IFilterMapper2_Release(pMapper
);
737 return E_OUTOFMEMORY
;
740 /* FIXME: Not sure if these are correct */
741 pTypes
[0].clsMajorType
= &MEDIATYPE_Audio
;
742 pTypes
[0].clsMinorType
= &MEDIASUBTYPE_PCM
;
744 rfp2
.lpMediaType
= pTypes
;
746 res
= IFilterMapper2_RegisterFilter(pMapper
,
750 &CLSID_AudioInputDeviceCategory
,
759 V_UNION(&var
, ulVal
) = i
;
760 res
= IMoniker_BindToStorage(pMoniker
, NULL
, NULL
, &IID_IPropertyBag
, (LPVOID
)&pPropBag
);
762 res
= IPropertyBag_Write(pPropBag
, wszWaveInID
, &var
);
766 V_VT(&var
) = VT_LPWSTR
;
767 V_UNION(&var
, bstrVal
) = wicaps
.szPname
;
769 res
= IPropertyBag_Write(pPropBag
, wszFriendlyName
, &var
);
772 IPropertyBag_Release(pPropBag
);
773 IMoniker_Release(pMoniker
);
776 CoTaskMemFree(pTypes
);
780 numDevs
= midiOutGetNumDevs();
782 res
= DEVENUM_CreateAMCategoryKey(&CLSID_MidiRendererCategory
);
783 if (FAILED(res
)) /* can't register any devices in this category */
786 rfp2
.dwFlags
= REG_PINFLAG_B_RENDERER
;
787 for (i
= 0; i
< numDevs
; i
++)
789 if (midiOutGetDevCapsW(i
, &mocaps
, sizeof(MIDIOUTCAPSW
))
792 IMoniker
* pMoniker
= NULL
;
794 rfp2
.nMediaTypes
= 1;
795 pTypes
= CoTaskMemAlloc(rfp2
.nMediaTypes
* sizeof(REGPINTYPES
));
798 IFilterMapper2_Release(pMapper
);
799 return E_OUTOFMEMORY
;
802 /* FIXME: Not sure if these are correct */
803 pTypes
[0].clsMajorType
= &MEDIATYPE_Midi
;
804 pTypes
[0].clsMinorType
= &MEDIASUBTYPE_None
;
806 rfp2
.lpMediaType
= pTypes
;
808 res
= IFilterMapper2_RegisterFilter(pMapper
,
809 &CLSID_AVIMIDIRender
,
812 &CLSID_MidiRendererCategory
,
816 /* FIXME: do additional stuff with IMoniker here, depending on what RegisterFilter does */
817 /* Native version sets MidiOutId */
820 IMoniker_Release(pMoniker
);
822 if (i
== iDefaultDevice
)
824 FIXME("Default device\n");
827 CoTaskMemFree(pTypes
);
830 res
= DEVENUM_CreateAMCategoryKey(&CLSID_VideoInputDeviceCategory
);
832 for (i
= 0; i
< 10; i
++)
834 WCHAR szDeviceName
[32], szDeviceVersion
[32], szDevicePath
[10];
836 if (capGetDriverDescriptionW ((WORD
) i
,
837 szDeviceName
, sizeof(szDeviceName
)/sizeof(WCHAR
),
838 szDeviceVersion
, sizeof(szDeviceVersion
)/sizeof(WCHAR
)))
840 IMoniker
* pMoniker
= NULL
;
841 WCHAR dprintf
[] = { 'v','i','d','e','o','%','d',0 };
842 snprintfW(szDevicePath
, sizeof(szDevicePath
)/sizeof(WCHAR
), dprintf
, i
);
843 /* The above code prevents 1 device with a different ID overwriting another */
845 rfp2
.nMediaTypes
= 1;
846 pTypes
= CoTaskMemAlloc(rfp2
.nMediaTypes
* sizeof(REGPINTYPES
));
848 IFilterMapper2_Release(pMapper
);
849 return E_OUTOFMEMORY
;
852 pTypes
[0].clsMajorType
= &MEDIATYPE_Video
;
853 pTypes
[0].clsMinorType
= &MEDIASUBTYPE_None
;
855 rfp2
.lpMediaType
= pTypes
;
857 res
= IFilterMapper2_RegisterFilter(pMapper
,
861 &CLSID_VideoInputDeviceCategory
,
866 OLECHAR wszVfwIndex
[] = { 'V','F','W','I','n','d','e','x',0 };
869 V_UNION(&var
, ulVal
) = i
;
870 res
= IMoniker_BindToStorage(pMoniker
, NULL
, NULL
, &IID_IPropertyBag
, (LPVOID
)&pPropBag
);
871 if (SUCCEEDED(res
)) {
872 res
= IPropertyBag_Write(pPropBag
, wszVfwIndex
, &var
);
873 IPropertyBag_Release(pPropBag
);
875 IMoniker_Release(pMoniker
);
878 if (i
== iDefaultDevice
) FIXME("Default device\n");
879 CoTaskMemFree(pTypes
);
885 IFilterMapper2_Release(pMapper
);
886 SetEvent(DEVENUM_populate_handle
);