winecoreaudio: Use mmdevapi's session_wrapper_create.
[wine.git] / dlls / devenum / createdevenum.c
blob8d59d6b385dfa010fe71af026fca060e740023a2
1 /*
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
20 * NOTES ON THIS FILE:
21 * - Implements ICreateDevEnum interface which creates an IEnumMoniker
22 * implementation
23 * - Also creates the special registry keys created at run-time
26 #define NONAMELESSSTRUCT
27 #define NONAMELESSUNION
29 #include "devenum_private.h"
30 #include "vfw.h"
31 #include "aviriff.h"
32 #include "dsound.h"
34 #include "wine/debug.h"
35 #include "wine/heap.h"
36 #include "mmddk.h"
38 #include "initguid.h"
39 #include "wine/fil_data.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(devenum);
43 static HRESULT WINAPI devenum_factory_QueryInterface(ICreateDevEnum *iface, REFIID riid, void **ppv)
45 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv);
47 if (!ppv)
48 return E_POINTER;
50 if (IsEqualGUID(riid, &IID_IUnknown) ||
51 IsEqualGUID(riid, &IID_ICreateDevEnum))
53 *ppv = iface;
54 ICreateDevEnum_AddRef(iface);
55 return S_OK;
58 FIXME("- no interface IID: %s\n", debugstr_guid(riid));
59 *ppv = NULL;
60 return E_NOINTERFACE;
63 static ULONG WINAPI devenum_factory_AddRef(ICreateDevEnum *iface)
65 TRACE("\n");
67 return 2; /* non-heap based object */
70 static ULONG WINAPI devenum_factory_Release(ICreateDevEnum *iface)
72 TRACE("\n");
74 return 1; /* non-heap based object */
77 static HRESULT register_codec(const GUID *class, const WCHAR *name,
78 const GUID *clsid, const WCHAR *friendly_name, IPropertyBag **ret)
80 WCHAR guidstr[CHARS_IN_GUID];
81 IParseDisplayName *parser;
82 IPropertyBag *propbag;
83 IMoniker *mon;
84 WCHAR *buffer;
85 VARIANT var;
86 ULONG eaten;
87 HRESULT hr;
89 hr = CoCreateInstance(&CLSID_CDeviceMoniker, NULL, CLSCTX_INPROC, &IID_IParseDisplayName, (void **)&parser);
90 if (FAILED(hr))
91 return hr;
93 if (!(buffer = heap_alloc((wcslen(L"@device:cm:") + CHARS_IN_GUID + wcslen(name) + 1) * sizeof(WCHAR))))
95 IParseDisplayName_Release(parser);
96 return E_OUTOFMEMORY;
99 wcscpy(buffer, L"@device:cm:");
100 StringFromGUID2(class, buffer + wcslen(buffer), CHARS_IN_GUID);
101 wcscat(buffer, L"\\");
102 wcscat(buffer, name);
104 IParseDisplayName_ParseDisplayName(parser, NULL, buffer, &eaten, &mon);
105 IParseDisplayName_Release(parser);
106 heap_free(buffer);
108 IMoniker_BindToStorage(mon, NULL, NULL, &IID_IPropertyBag, (void **)&propbag);
109 IMoniker_Release(mon);
111 V_VT(&var) = VT_BSTR;
112 V_BSTR(&var) = SysAllocString(friendly_name);
113 hr = IPropertyBag_Write(propbag, L"FriendlyName", &var);
114 VariantClear(&var);
115 if (FAILED(hr))
117 IPropertyBag_Release(propbag);
118 return hr;
121 V_VT(&var) = VT_BSTR;
122 StringFromGUID2(clsid, guidstr, ARRAY_SIZE(guidstr));
123 V_BSTR(&var) = SysAllocString(guidstr);
124 hr = IPropertyBag_Write(propbag, L"CLSID", &var);
125 VariantClear(&var);
126 if (FAILED(hr))
128 IPropertyBag_Release(propbag);
129 return hr;
132 *ret = propbag;
133 return S_OK;
136 static void DEVENUM_ReadPinTypes(HKEY hkeyPinKey, REGFILTERPINS2 *rgPin)
138 HKEY hkeyTypes = NULL;
139 DWORD dwMajorTypes, i;
140 REGPINTYPES *lpMediaType = NULL;
141 DWORD dwMediaTypeSize = 0;
143 if (RegOpenKeyExW(hkeyPinKey, L"Types", 0, KEY_READ, &hkeyTypes) != ERROR_SUCCESS)
144 return ;
146 if (RegQueryInfoKeyW(hkeyTypes, NULL, NULL, NULL, &dwMajorTypes, NULL, NULL, NULL, NULL, NULL, NULL, NULL)
147 != ERROR_SUCCESS)
149 RegCloseKey(hkeyTypes);
150 return ;
153 for (i = 0; i < dwMajorTypes; i++)
155 HKEY hkeyMajorType = NULL;
156 WCHAR wszMajorTypeName[64];
157 DWORD cName = ARRAY_SIZE(wszMajorTypeName);
158 DWORD dwMinorTypes, i1;
160 if (RegEnumKeyExW(hkeyTypes, i, wszMajorTypeName, &cName, NULL, NULL, NULL, NULL) != ERROR_SUCCESS) continue;
162 if (RegOpenKeyExW(hkeyTypes, wszMajorTypeName, 0, KEY_READ, &hkeyMajorType) != ERROR_SUCCESS) continue;
164 if (RegQueryInfoKeyW(hkeyMajorType, NULL, NULL, NULL, &dwMinorTypes, NULL, NULL, NULL, NULL, NULL, NULL, NULL)
165 != ERROR_SUCCESS)
167 RegCloseKey(hkeyMajorType);
168 continue;
171 for (i1 = 0; i1 < dwMinorTypes; i1++)
173 WCHAR wszMinorTypeName[64];
174 CLSID *clsMajorType = NULL, *clsMinorType = NULL;
175 HRESULT hr;
177 cName = ARRAY_SIZE(wszMinorTypeName);
178 if (RegEnumKeyExW(hkeyMajorType, i1, wszMinorTypeName, &cName, NULL, NULL, NULL, NULL) != ERROR_SUCCESS) continue;
180 clsMinorType = CoTaskMemAlloc(sizeof(CLSID));
181 if (!clsMinorType) continue;
183 clsMajorType = CoTaskMemAlloc(sizeof(CLSID));
184 if (!clsMajorType) goto error_cleanup_types;
186 hr = CLSIDFromString(wszMinorTypeName, clsMinorType);
187 if (FAILED(hr)) goto error_cleanup_types;
189 hr = CLSIDFromString(wszMajorTypeName, clsMajorType);
190 if (FAILED(hr)) goto error_cleanup_types;
192 if (rgPin->nMediaTypes == dwMediaTypeSize)
194 DWORD dwNewSize = dwMediaTypeSize + (dwMediaTypeSize < 2 ? 1 : dwMediaTypeSize / 2);
195 REGPINTYPES *lpNewMediaType;
197 lpNewMediaType = CoTaskMemRealloc(lpMediaType, sizeof(REGPINTYPES) * dwNewSize);
198 if (!lpNewMediaType) goto error_cleanup_types;
200 lpMediaType = lpNewMediaType;
201 dwMediaTypeSize = dwNewSize;
204 lpMediaType[rgPin->nMediaTypes].clsMajorType = clsMajorType;
205 lpMediaType[rgPin->nMediaTypes].clsMinorType = clsMinorType;
206 rgPin->nMediaTypes++;
207 continue;
209 error_cleanup_types:
211 CoTaskMemFree(clsMajorType);
212 CoTaskMemFree(clsMinorType);
215 RegCloseKey(hkeyMajorType);
218 RegCloseKey(hkeyTypes);
220 if (lpMediaType && !rgPin->nMediaTypes)
222 CoTaskMemFree(lpMediaType);
223 lpMediaType = NULL;
226 rgPin->lpMediaType = lpMediaType;
229 static void DEVENUM_ReadPins(HKEY hkeyFilterClass, REGFILTER2 *rgf2)
231 HKEY hkeyPins = NULL;
232 DWORD dwPinsSubkeys, i;
233 REGFILTERPINS2 *rgPins = NULL;
235 rgf2->dwVersion = 2;
236 rgf2->cPins2 = 0;
237 rgf2->rgPins2 = NULL;
239 if (RegOpenKeyExW(hkeyFilterClass, L"Pins", 0, KEY_READ, &hkeyPins) != ERROR_SUCCESS)
240 return ;
242 if (RegQueryInfoKeyW(hkeyPins, NULL, NULL, NULL, &dwPinsSubkeys, NULL, NULL, NULL, NULL, NULL, NULL, NULL)
243 != ERROR_SUCCESS)
245 RegCloseKey(hkeyPins);
246 return ;
249 if (dwPinsSubkeys)
251 rgPins = CoTaskMemAlloc(sizeof(REGFILTERPINS2) * dwPinsSubkeys);
252 if (!rgPins)
254 RegCloseKey(hkeyPins);
255 return ;
259 for (i = 0; i < dwPinsSubkeys; i++)
261 HKEY hkeyPinKey = NULL;
262 WCHAR wszPinName[MAX_PATH];
263 DWORD cName = ARRAY_SIZE(wszPinName);
264 REGFILTERPINS2 *rgPin = &rgPins[rgf2->cPins2];
265 DWORD value, size, Type;
266 LONG lRet;
268 memset(rgPin, 0, sizeof(*rgPin));
270 if (RegEnumKeyExW(hkeyPins, i, wszPinName, &cName, NULL, NULL, NULL, NULL) != ERROR_SUCCESS) continue;
272 if (RegOpenKeyExW(hkeyPins, wszPinName, 0, KEY_READ, &hkeyPinKey) != ERROR_SUCCESS) continue;
274 size = sizeof(DWORD);
275 lRet = RegQueryValueExW(hkeyPinKey, L"AllowedMany", NULL, &Type, (BYTE *)&value, &size);
276 if (lRet != ERROR_SUCCESS || Type != REG_DWORD)
277 goto error_cleanup;
278 if (value)
279 rgPin->dwFlags |= REG_PINFLAG_B_MANY;
281 size = sizeof(DWORD);
282 lRet = RegQueryValueExW(hkeyPinKey, L"AllowedZero", NULL, &Type, (BYTE *)&value, &size);
283 if (lRet != ERROR_SUCCESS || Type != REG_DWORD)
284 goto error_cleanup;
285 if (value)
286 rgPin->dwFlags |= REG_PINFLAG_B_ZERO;
288 size = sizeof(DWORD);
289 lRet = RegQueryValueExW(hkeyPinKey, L"Direction", NULL, &Type, (BYTE *)&value, &size);
290 if (lRet != ERROR_SUCCESS || Type != REG_DWORD)
291 goto error_cleanup;
292 if (value)
293 rgPin->dwFlags |= REG_PINFLAG_B_OUTPUT;
296 size = sizeof(DWORD);
297 lRet = RegQueryValueExW(hkeyPinKey, L"IsRendered", NULL, &Type, (BYTE *)&value, &size);
298 if (lRet != ERROR_SUCCESS || Type != REG_DWORD)
299 goto error_cleanup;
300 if (value)
301 rgPin->dwFlags |= REG_PINFLAG_B_RENDERER;
303 DEVENUM_ReadPinTypes(hkeyPinKey, rgPin);
305 ++rgf2->cPins2;
306 continue;
308 error_cleanup:
310 RegCloseKey(hkeyPinKey);
313 RegCloseKey(hkeyPins);
315 if (rgPins && !rgf2->cPins2)
317 CoTaskMemFree(rgPins);
318 rgPins = NULL;
321 rgf2->rgPins2 = rgPins;
324 static void free_regfilter2(REGFILTER2 *rgf)
326 if (rgf->rgPins2)
328 UINT iPin;
330 for (iPin = 0; iPin < rgf->cPins2; iPin++)
332 if (rgf->rgPins2[iPin].lpMediaType)
334 UINT iType;
336 for (iType = 0; iType < rgf->rgPins2[iPin].nMediaTypes; iType++)
338 CoTaskMemFree((void *)rgf->rgPins2[iPin].lpMediaType[iType].clsMajorType);
339 CoTaskMemFree((void *)rgf->rgPins2[iPin].lpMediaType[iType].clsMinorType);
342 CoTaskMemFree((void *)rgf->rgPins2[iPin].lpMediaType);
346 CoTaskMemFree((void *)rgf->rgPins2);
350 HRESULT create_filter_data(VARIANT *var, REGFILTER2 *rgf)
352 IAMFilterData *fildata;
353 BYTE *data = NULL;
354 ULONG size;
355 HRESULT hr;
357 hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC, &IID_IAMFilterData, (void **)&fildata);
358 if (FAILED(hr))
359 return hr;
361 hr = IAMFilterData_CreateFilterData(fildata, rgf, &data, &size);
362 IAMFilterData_Release(fildata);
363 if (FAILED(hr))
364 return hr;
366 V_VT(var) = VT_ARRAY | VT_UI1;
367 if (!(V_ARRAY(var) = SafeArrayCreateVector(VT_UI1, 1, size)))
369 VariantClear(var);
370 CoTaskMemFree(data);
371 return E_OUTOFMEMORY;
374 memcpy(V_ARRAY(var)->pvData, data, size);
375 CoTaskMemFree(data);
376 return S_OK;
379 static void write_filter_data(IPropertyBag *prop_bag, REGFILTER2 *rgf)
381 VARIANT var;
383 if (SUCCEEDED(create_filter_data(&var, rgf)))
385 IPropertyBag_Write(prop_bag, L"FilterData", &var);
386 VariantClear(&var);
390 static void register_legacy_filters(void)
392 HKEY hkeyFilter = NULL;
393 DWORD dwFilterSubkeys, i;
394 LONG lRet;
395 HRESULT hr;
397 lRet = RegOpenKeyExW(HKEY_CLASSES_ROOT, L"Filter", 0, KEY_READ, &hkeyFilter);
398 hr = HRESULT_FROM_WIN32(lRet);
400 if (SUCCEEDED(hr))
402 lRet = RegQueryInfoKeyW(hkeyFilter, NULL, NULL, NULL, &dwFilterSubkeys, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
403 hr = HRESULT_FROM_WIN32(lRet);
406 if (SUCCEEDED(hr))
408 for (i = 0; i < dwFilterSubkeys; i++)
410 WCHAR wszFilterSubkeyName[64];
411 DWORD cName = ARRAY_SIZE(wszFilterSubkeyName);
412 IPropertyBag *prop_bag = NULL;
413 WCHAR wszRegKey[MAX_PATH];
414 HKEY classkey = NULL;
415 REGFILTER2 rgf2;
416 DWORD Type, len;
417 GUID clsid;
419 if (RegEnumKeyExW(hkeyFilter, i, wszFilterSubkeyName, &cName, NULL, NULL, NULL, NULL) != ERROR_SUCCESS) continue;
421 TRACE("Registering %s\n", debugstr_w(wszFilterSubkeyName));
423 hr = CLSIDFromString(wszFilterSubkeyName, &clsid);
424 if (FAILED(hr))
425 continue;
427 swprintf(wszRegKey, ARRAY_SIZE(wszRegKey), L"CLSID\\%s", wszFilterSubkeyName);
428 if (RegOpenKeyExW(HKEY_CLASSES_ROOT, wszRegKey, 0, KEY_READ, &classkey) != ERROR_SUCCESS)
429 continue;
431 len = 0;
432 if (!RegQueryValueExW(classkey, NULL, NULL, &Type, NULL, &len))
434 WCHAR *friendlyname = heap_alloc(len);
435 if (!friendlyname)
437 RegCloseKey(classkey);
438 continue;
440 RegQueryValueExW(classkey, NULL, NULL, &Type, (BYTE *)friendlyname, &len);
442 hr = register_codec(&CLSID_LegacyAmFilterCategory, wszFilterSubkeyName,
443 &clsid, friendlyname, &prop_bag);
445 heap_free(friendlyname);
447 else
448 hr = register_codec(&CLSID_LegacyAmFilterCategory, wszFilterSubkeyName,
449 &clsid, wszFilterSubkeyName, &prop_bag);
450 if (FAILED(hr))
452 RegCloseKey(classkey);
453 continue;
456 /* write filter data */
457 rgf2.dwMerit = MERIT_NORMAL;
459 len = sizeof(rgf2.dwMerit);
460 RegQueryValueExW(classkey, L"Merit", NULL, &Type, (BYTE *)&rgf2.dwMerit, &len);
462 DEVENUM_ReadPins(classkey, &rgf2);
464 write_filter_data(prop_bag, &rgf2);
466 IPropertyBag_Release(prop_bag);
467 RegCloseKey(classkey);
468 free_regfilter2(&rgf2);
472 if (hkeyFilter) RegCloseKey(hkeyFilter);
475 static BOOL CALLBACK register_dsound_devices(GUID *guid, const WCHAR *desc, const WCHAR *module, void *context)
477 static const WCHAR defaultW[] = L"Default DirectSound Device";
478 IPropertyBag *prop_bag = NULL;
479 REGFILTERPINS2 rgpins = {0};
480 REGPINTYPES rgtypes = {0};
481 REGFILTER2 rgf = {0};
482 WCHAR clsid[CHARS_IN_GUID];
483 VARIANT var;
484 HRESULT hr;
486 if (guid)
488 WCHAR *name = heap_alloc(sizeof(defaultW) + wcslen(desc) * sizeof(WCHAR));
489 if (!name)
490 return FALSE;
491 wcscpy(name, L"DirectSound: ");
492 wcscat(name, desc);
494 hr = register_codec(&CLSID_AudioRendererCategory, name,
495 &CLSID_DSoundRender, name, &prop_bag);
496 heap_free(name);
498 else
499 hr = register_codec(&CLSID_AudioRendererCategory, defaultW,
500 &CLSID_DSoundRender, defaultW, &prop_bag);
501 if (FAILED(hr))
502 return FALSE;
504 /* write filter data */
505 rgf.dwVersion = 2;
506 rgf.dwMerit = guid ? MERIT_DO_NOT_USE : MERIT_PREFERRED;
507 rgf.cPins2 = 1;
508 rgf.rgPins2 = &rgpins;
509 rgpins.dwFlags = REG_PINFLAG_B_RENDERER;
510 /* FIXME: native registers many more formats */
511 rgpins.nMediaTypes = 1;
512 rgpins.lpMediaType = &rgtypes;
513 rgtypes.clsMajorType = &MEDIATYPE_Audio;
514 rgtypes.clsMinorType = &MEDIASUBTYPE_PCM;
516 write_filter_data(prop_bag, &rgf);
518 /* write DSound guid */
519 V_VT(&var) = VT_BSTR;
520 StringFromGUID2(guid ? guid : &GUID_NULL, clsid, CHARS_IN_GUID);
521 if ((V_BSTR(&var) = SysAllocString(clsid)))
522 hr = IPropertyBag_Write(prop_bag, L"DSGuid", &var);
524 VariantClear(&var);
525 IPropertyBag_Release(prop_bag);
526 return TRUE;
529 static void register_waveout_devices(void)
531 IPropertyBag *prop_bag = NULL;
532 REGFILTERPINS2 rgpins = {0};
533 REGPINTYPES rgtypes = {0};
534 REGFILTER2 rgf = {0};
535 WAVEOUTCAPSW caps;
536 const WCHAR *name;
537 int i, count;
538 VARIANT var;
539 HRESULT hr;
541 count = waveOutGetNumDevs();
543 for (i = -1; i < count; i++)
545 waveOutGetDevCapsW(i, &caps, sizeof(caps));
547 name = (i == -1) ? L"Default WaveOut Device" : caps.szPname;
549 hr = register_codec(&CLSID_AudioRendererCategory, name,
550 &CLSID_AudioRender, name, &prop_bag);
551 if (FAILED(hr))
552 continue;
554 /* write filter data */
555 rgf.dwVersion = 2;
556 rgf.dwMerit = MERIT_DO_NOT_USE;
557 rgf.cPins2 = 1;
558 rgf.rgPins2 = &rgpins;
559 rgpins.dwFlags = REG_PINFLAG_B_RENDERER;
560 rgpins.nMediaTypes = 1;
561 rgpins.lpMediaType = &rgtypes;
562 rgtypes.clsMajorType = &MEDIATYPE_Audio;
563 rgtypes.clsMinorType = &MEDIASUBTYPE_NULL;
565 write_filter_data(prop_bag, &rgf);
567 /* write WaveOutId */
568 V_VT(&var) = VT_I4;
569 V_I4(&var) = i;
570 IPropertyBag_Write(prop_bag, L"WaveOutId", &var);
572 VariantClear(&var);
573 if (prop_bag) IPropertyBag_Release(prop_bag);
577 static void register_wavein_devices(void)
579 IPropertyBag *prop_bag = NULL;
580 REGFILTER2 rgf = {0};
581 WAVEINCAPSW caps;
582 int i, count;
583 VARIANT var;
584 HRESULT hr;
586 count = waveInGetNumDevs();
588 for (i = 0; i < count; i++)
590 waveInGetDevCapsW(i, &caps, sizeof(caps));
592 hr = register_codec(&CLSID_AudioInputDeviceCategory, caps.szPname,
593 &CLSID_AudioRecord, caps.szPname, &prop_bag);
594 if (FAILED(hr))
595 continue;
597 /* write filter data */
598 rgf.dwVersion = 2;
599 rgf.dwMerit = MERIT_DO_NOT_USE;
601 write_filter_data(prop_bag, &rgf);
603 /* write WaveInId */
604 V_VT(&var) = VT_I4;
605 V_I4(&var) = i;
606 IPropertyBag_Write(prop_bag, L"WaveInId", &var);
608 VariantClear(&var);
609 IPropertyBag_Release(prop_bag);
613 static void register_midiout_devices(void)
615 IPropertyBag *prop_bag = NULL;
616 REGFILTERPINS2 rgpins = {0};
617 REGPINTYPES rgtypes = {0};
618 REGFILTER2 rgf = {0};
619 MIDIOUTCAPSW caps;
620 const WCHAR *name;
621 int i, count;
622 VARIANT var;
623 HRESULT hr;
625 count = midiOutGetNumDevs();
627 for (i = -1; i < count; i++)
629 midiOutGetDevCapsW(i, &caps, sizeof(caps));
631 name = (i == -1) ? L"Default MidiOut Device" : caps.szPname;
633 hr = register_codec(&CLSID_MidiRendererCategory, name,
634 &CLSID_AVIMIDIRender, name, &prop_bag);
635 if (FAILED(hr))
636 continue;
638 /* write filter data */
639 rgf.dwVersion = 2;
640 rgf.dwMerit = (i == -1) ? MERIT_PREFERRED : MERIT_DO_NOT_USE;
641 rgf.cPins2 = 1;
642 rgf.rgPins2 = &rgpins;
643 rgpins.dwFlags = REG_PINFLAG_B_RENDERER;
644 rgpins.nMediaTypes = 1;
645 rgpins.lpMediaType = &rgtypes;
646 rgtypes.clsMajorType = &MEDIATYPE_Midi;
647 rgtypes.clsMinorType = &MEDIASUBTYPE_NULL;
649 write_filter_data(prop_bag, &rgf);
651 /* write MidiOutId */
652 V_VT(&var) = VT_I4;
653 V_I4(&var) = i;
654 IPropertyBag_Write(prop_bag, L"MidiOutId", &var);
656 VariantClear(&var);
657 IPropertyBag_Release(prop_bag);
661 static void register_vfw_codecs(void)
663 REGFILTERPINS2 rgpins[2] = {};
664 IPropertyBag *prop_bag = NULL;
665 REGPINTYPES rgtypes[2];
666 REGFILTER2 rgf;
667 GUID typeguid;
668 ICINFO info;
669 VARIANT var;
670 HRESULT hr;
671 int i = 0;
672 HIC hic;
674 while (ICInfo(ICTYPE_VIDEO, i++, &info))
676 WCHAR name[5] = {LOBYTE(LOWORD(info.fccHandler)), HIBYTE(LOWORD(info.fccHandler)),
677 LOBYTE(HIWORD(info.fccHandler)), HIBYTE(HIWORD(info.fccHandler))};
679 hic = ICOpen(ICTYPE_VIDEO, info.fccHandler, ICMODE_QUERY);
680 ICGetInfo(hic, &info, sizeof(info));
681 ICClose(hic);
683 hr = register_codec(&CLSID_VideoCompressorCategory, name,
684 &CLSID_AVICo, info.szDescription, &prop_bag);
685 if (FAILED(hr))
686 continue;
688 /* write filter data */
689 rgf.dwVersion = 2;
690 rgf.dwMerit = MERIT_DO_NOT_USE;
691 rgf.cPins2 = 2;
692 rgf.rgPins2 = rgpins;
693 rgpins[0].dwFlags = 0;
694 rgpins[0].nMediaTypes = 1;
695 rgpins[0].lpMediaType = &rgtypes[0];
696 rgtypes[0].clsMajorType = &MEDIATYPE_Video;
697 typeguid = MEDIASUBTYPE_PCM;
698 typeguid.Data1 = info.fccHandler;
699 rgtypes[0].clsMinorType = &typeguid;
700 rgpins[1].dwFlags = REG_PINFLAG_B_OUTPUT;
701 rgpins[1].nMediaTypes = 1;
702 rgpins[1].lpMediaType = &rgtypes[1];
703 rgtypes[1].clsMajorType = &MEDIATYPE_Video;
704 rgtypes[1].clsMinorType = &GUID_NULL;
706 write_filter_data(prop_bag, &rgf);
708 /* write WaveInId */
709 V_VT(&var) = VT_BSTR;
710 V_BSTR(&var) = SysAllocString(name);
711 IPropertyBag_Write(prop_bag, L"FccHandler", &var);
713 VariantClear(&var);
714 IPropertyBag_Release(prop_bag);
718 static void register_avicap_devices(void)
720 WCHAR friendlyname[32], version[32];
721 IPropertyBag *prop_bag = NULL;
722 REGFILTERPINS2 rgpins = {0};
723 REGPINTYPES rgtypes;
724 REGFILTER2 rgf;
725 WCHAR name[7];
726 VARIANT var;
727 HRESULT hr;
728 int i = 0;
730 for (i = 0; i < 10; ++i)
732 if (!capGetDriverDescriptionW(i, friendlyname, ARRAY_SIZE(friendlyname),
733 version, ARRAY_SIZE(version)))
734 continue;
736 swprintf(name, ARRAY_SIZE(name), L"video%d", i);
738 hr = register_codec(&CLSID_VideoInputDeviceCategory, name,
739 &CLSID_VfwCapture, friendlyname, &prop_bag);
740 if (FAILED(hr))
741 continue;
743 rgf.dwVersion = 2;
744 rgf.dwMerit = MERIT_DO_NOT_USE;
745 rgf.cPins2 = 1;
746 rgf.rgPins2 = &rgpins;
747 rgpins.dwFlags = 0;
748 rgpins.nMediaTypes = 1;
749 rgpins.lpMediaType = &rgtypes;
750 rgtypes.clsMajorType = &MEDIATYPE_Video;
751 rgtypes.clsMinorType = &MEDIASUBTYPE_None;
753 write_filter_data(prop_bag, &rgf);
755 /* write VFWIndex */
756 V_VT(&var) = VT_I4;
757 V_I4(&var) = i;
758 IPropertyBag_Write(prop_bag, L"VFWIndex", &var);
760 VariantClear(&var);
761 IPropertyBag_Release(prop_bag);
765 static HRESULT WINAPI devenum_factory_CreateClassEnumerator(ICreateDevEnum *iface,
766 REFCLSID class, IEnumMoniker **out, DWORD flags)
768 WCHAR guidstr[CHARS_IN_GUID];
769 HRESULT hr;
770 HKEY key;
772 TRACE("iface %p, class %s, out %p, flags %#lx.\n", iface, debugstr_guid(class), out, flags);
774 if (!out)
775 return E_POINTER;
777 *out = NULL;
779 if (!RegOpenKeyW(HKEY_CURRENT_USER, L"Software\\Microsoft\\ActiveMovie\\devenum", &key))
781 StringFromGUID2(class, guidstr, ARRAY_SIZE(guidstr));
782 RegDeleteTreeW(key, guidstr);
785 if (IsEqualGUID(class, &CLSID_LegacyAmFilterCategory))
786 register_legacy_filters();
787 else if (IsEqualGUID(class, &CLSID_AudioRendererCategory))
789 hr = DirectSoundEnumerateW(&register_dsound_devices, NULL);
790 if (FAILED(hr)) return hr;
791 register_waveout_devices();
792 register_midiout_devices();
794 else if (IsEqualGUID(class, &CLSID_AudioInputDeviceCategory))
795 register_wavein_devices();
796 else if (IsEqualGUID(class, &CLSID_VideoCompressorCategory))
797 register_vfw_codecs();
798 else if (IsEqualGUID(class, &CLSID_VideoInputDeviceCategory))
799 register_avicap_devices();
801 if (SUCCEEDED(hr = enum_moniker_create(class, out)))
803 IMoniker *mon;
804 hr = IEnumMoniker_Next(*out, 1, &mon, NULL);
805 if (hr == S_OK)
807 IMoniker_Release(mon);
808 IEnumMoniker_Reset(*out);
810 else
812 IEnumMoniker_Release(*out);
813 *out = NULL;
817 return hr;
820 /**********************************************************************
821 * ICreateDevEnum_Vtbl
823 static const ICreateDevEnumVtbl ICreateDevEnum_Vtbl =
825 devenum_factory_QueryInterface,
826 devenum_factory_AddRef,
827 devenum_factory_Release,
828 devenum_factory_CreateClassEnumerator,
831 /**********************************************************************
832 * static CreateDevEnum instance
834 ICreateDevEnum devenum_factory = { &ICreateDevEnum_Vtbl };