Assorted spelling fixes.
[wine/hacks.git] / dlls / devenum / createdevenum.c
blob3891dece47e0350f5b9f86b88448168706b4a236
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"
32 #include "wine/debug.h"
33 #include "wine/unicode.h"
34 #include "mmddk.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};
56 static ULONG WINAPI DEVENUM_ICreateDevEnum_AddRef(ICreateDevEnum * iface);
57 static HRESULT DEVENUM_CreateSpecialCategories(void);
59 /**********************************************************************
60 * DEVENUM_ICreateDevEnum_QueryInterface (also IUnknown)
62 static HRESULT WINAPI DEVENUM_ICreateDevEnum_QueryInterface(
63 ICreateDevEnum * iface,
64 REFIID riid,
65 LPVOID *ppvObj)
67 TRACE("\n\tIID:\t%s\n",debugstr_guid(riid));
69 if (ppvObj == NULL) return E_POINTER;
71 if (IsEqualGUID(riid, &IID_IUnknown) ||
72 IsEqualGUID(riid, &IID_ICreateDevEnum))
74 *ppvObj = iface;
75 DEVENUM_ICreateDevEnum_AddRef(iface);
76 return S_OK;
79 FIXME("- no interface\n\tIID:\t%s\n", debugstr_guid(riid));
80 return E_NOINTERFACE;
83 /**********************************************************************
84 * DEVENUM_ICreateDevEnum_AddRef (also IUnknown)
86 static ULONG WINAPI DEVENUM_ICreateDevEnum_AddRef(ICreateDevEnum * iface)
88 TRACE("\n");
90 DEVENUM_LockModule();
92 return 2; /* non-heap based object */
95 /**********************************************************************
96 * DEVENUM_ICreateDevEnum_Release (also IUnknown)
98 static ULONG WINAPI DEVENUM_ICreateDevEnum_Release(ICreateDevEnum * iface)
100 TRACE("\n");
102 DEVENUM_UnlockModule();
104 return 1; /* non-heap based object */
107 HRESULT DEVENUM_GetCategoryKey(REFCLSID clsidDeviceClass, HKEY *pBaseKey, WCHAR *wszRegKeyName, UINT maxLen)
109 if (IsEqualGUID(clsidDeviceClass, &CLSID_AudioRendererCategory) ||
110 IsEqualGUID(clsidDeviceClass, &CLSID_AudioInputDeviceCategory) ||
111 IsEqualGUID(clsidDeviceClass, &CLSID_VideoInputDeviceCategory) ||
112 IsEqualGUID(clsidDeviceClass, &CLSID_MidiRendererCategory))
114 *pBaseKey = HKEY_CURRENT_USER;
115 strcpyW(wszRegKeyName, wszActiveMovieKey);
117 if (!StringFromGUID2(clsidDeviceClass, wszRegKeyName + strlenW(wszRegKeyName), maxLen - strlenW(wszRegKeyName)))
118 return E_OUTOFMEMORY;
120 else
122 *pBaseKey = HKEY_CLASSES_ROOT;
123 strcpyW(wszRegKeyName, clsid_keyname);
124 strcatW(wszRegKeyName, wszRegSeparator);
126 if (!StringFromGUID2(clsidDeviceClass, wszRegKeyName + CLSID_STR_LEN, maxLen - CLSID_STR_LEN))
127 return E_OUTOFMEMORY;
129 strcatW(wszRegKeyName, wszRegSeparator);
130 strcatW(wszRegKeyName, wszInstanceKeyName);
133 return S_OK;
136 static void DEVENUM_ReadPinTypes(HKEY hkeyPinKey, REGFILTERPINS *rgPin)
138 HKEY hkeyTypes = NULL;
139 DWORD dwMajorTypes, i;
140 REGPINTYPES *lpMediaType = NULL;
141 DWORD dwMediaTypeSize = 0;
143 if (RegOpenKeyExW(hkeyPinKey, wszTypes, 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 = sizeof(wszMajorTypeName) / sizeof(WCHAR);
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 DWORD cName = sizeof(wszMinorTypeName) / sizeof(WCHAR);
175 CLSID *clsMajorType = NULL, *clsMinorType = NULL;
176 HRESULT hr;
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 if (clsMajorType) CoTaskMemFree(clsMajorType);
212 if (clsMinorType) 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 REGFILTERPINS *rgPins = NULL;
235 if (RegOpenKeyExW(hkeyFilterClass, wszPins, 0, KEY_READ, &hkeyPins) != ERROR_SUCCESS)
236 return ;
238 if (RegQueryInfoKeyW(hkeyPins, NULL, NULL, NULL, &dwPinsSubkeys, NULL, NULL, NULL, NULL, NULL, NULL, NULL)
239 != ERROR_SUCCESS)
241 RegCloseKey(hkeyPins);
242 return ;
245 if (dwPinsSubkeys)
247 rgPins = CoTaskMemAlloc(sizeof(REGFILTERPINS) * dwPinsSubkeys);
248 if (!rgPins)
250 RegCloseKey(hkeyPins);
251 return ;
255 for (i = 0; i < dwPinsSubkeys; i++)
257 HKEY hkeyPinKey = NULL;
258 WCHAR wszPinName[MAX_PATH];
259 DWORD cName = sizeof(wszPinName) / sizeof(WCHAR);
260 DWORD Type, cbData;
261 REGFILTERPINS *rgPin = &rgPins[rgf2->u.s.cPins];
262 LONG lRet;
264 rgPin->strName = NULL;
265 rgPin->clsConnectsToFilter = &GUID_NULL;
266 rgPin->strConnectsToPin = NULL;
267 rgPin->nMediaTypes = 0;
268 rgPin->lpMediaType = NULL;
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 rgPin->strName = CoTaskMemAlloc((strlenW(wszPinName) + 1) * sizeof(WCHAR));
275 if (!rgPin->strName) goto error_cleanup;
277 strcpyW(rgPin->strName, wszPinName);
279 cbData = sizeof(rgPin->bMany);
280 lRet = RegQueryValueExW(hkeyPinKey, wszAllowedMany, NULL, &Type, (LPBYTE)&rgPin->bMany, &cbData);
281 if (lRet != ERROR_SUCCESS || Type != REG_DWORD)
282 goto error_cleanup;
284 cbData = sizeof(rgPin->bZero);
285 lRet = RegQueryValueExW(hkeyPinKey, wszAllowedZero, NULL, &Type, (LPBYTE)&rgPin->bZero, &cbData);
286 if (lRet != ERROR_SUCCESS || Type != REG_DWORD)
287 goto error_cleanup;
289 cbData = sizeof(rgPin->bOutput);
290 lRet = RegQueryValueExW(hkeyPinKey, wszDirection, NULL, &Type, (LPBYTE)&rgPin->bOutput, &cbData);
291 if (lRet != ERROR_SUCCESS || Type != REG_DWORD)
292 goto error_cleanup;
294 cbData = sizeof(rgPin->bRendered);
295 lRet = RegQueryValueExW(hkeyPinKey, wszIsRendered, NULL, &Type, (LPBYTE)&rgPin->bRendered, &cbData);
296 if (lRet != ERROR_SUCCESS || Type != REG_DWORD)
297 goto error_cleanup;
299 DEVENUM_ReadPinTypes(hkeyPinKey, rgPin);
301 ++rgf2->u.s.cPins;
302 continue;
304 error_cleanup:
306 RegCloseKey(hkeyPinKey);
307 if (rgPin->strName) CoTaskMemFree(rgPin->strName);
310 RegCloseKey(hkeyPins);
312 if (rgPins && !rgf2->u.s.cPins)
314 CoTaskMemFree(rgPins);
315 rgPins = NULL;
318 rgf2->u.s.rgPins = rgPins;
321 static HRESULT DEVENUM_RegisterLegacyAmFilters(void)
323 HKEY hkeyFilter = NULL;
324 DWORD dwFilterSubkeys, i;
325 LONG lRet;
326 IFilterMapper2 *pMapper = NULL;
327 HRESULT hr;
329 hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC,
330 &IID_IFilterMapper2, (void **) &pMapper);
331 if (SUCCEEDED(hr))
333 lRet = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszFilterKeyName, 0, KEY_READ, &hkeyFilter);
334 hr = HRESULT_FROM_WIN32(lRet);
337 if (SUCCEEDED(hr))
339 lRet = RegQueryInfoKeyW(hkeyFilter, NULL, NULL, NULL, &dwFilterSubkeys, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
340 hr = HRESULT_FROM_WIN32(lRet);
343 if (SUCCEEDED(hr))
345 for (i = 0; i < dwFilterSubkeys; i++)
347 WCHAR wszFilterSubkeyName[64];
348 DWORD cName = sizeof(wszFilterSubkeyName) / sizeof(WCHAR);
349 HKEY hkeyCategoryBaseKey;
350 WCHAR wszRegKey[MAX_PATH];
351 HKEY hkeyInstance = NULL;
352 HRESULT hr;
354 if (RegEnumKeyExW(hkeyFilter, i, wszFilterSubkeyName, &cName, NULL, NULL, NULL, NULL) != ERROR_SUCCESS) continue;
356 hr = DEVENUM_GetCategoryKey(&CLSID_LegacyAmFilterCategory, &hkeyCategoryBaseKey, wszRegKey, MAX_PATH);
357 if (FAILED(hr)) continue;
359 strcatW(wszRegKey, wszRegSeparator);
360 strcatW(wszRegKey, wszFilterSubkeyName);
362 if (RegOpenKeyExW(HKEY_CLASSES_ROOT, wszRegKey, 0, KEY_READ, &hkeyInstance) == ERROR_SUCCESS)
364 RegCloseKey(hkeyInstance);
366 else
368 /* Filter is registered the IFilterMapper(1)-way in HKCR\Filter. Needs to be added to
369 * legacy am filter category. */
370 HKEY hkeyFilterClass = NULL;
371 REGFILTER2 rgf2;
372 CLSID clsidFilter;
373 WCHAR wszFilterName[MAX_PATH];
374 DWORD Type;
375 DWORD cbData;
376 HRESULT res;
377 IMoniker *pMoniker = NULL;
379 TRACE("Registering %s\n", debugstr_w(wszFilterSubkeyName));
381 strcpyW(wszRegKey, clsid_keyname);
382 strcatW(wszRegKey, wszRegSeparator);
383 strcatW(wszRegKey, wszFilterSubkeyName);
385 if (RegOpenKeyExW(HKEY_CLASSES_ROOT, wszRegKey, 0, KEY_READ, &hkeyFilterClass) != ERROR_SUCCESS)
386 continue;
388 rgf2.dwVersion = 1;
389 rgf2.dwMerit = 0;
390 rgf2.u.s.cPins = 0;
391 rgf2.u.s.rgPins = NULL;
393 cbData = sizeof(wszFilterName);
394 if (RegQueryValueExW(hkeyFilterClass, NULL, NULL, &Type, (LPBYTE)wszFilterName, &cbData) != ERROR_SUCCESS ||
395 Type != REG_SZ)
396 goto cleanup;
398 cbData = sizeof(rgf2.dwMerit);
399 if (RegQueryValueExW(hkeyFilterClass, wszMeritName, NULL, &Type, (LPBYTE)&rgf2.dwMerit, &cbData) != ERROR_SUCCESS ||
400 Type != REG_DWORD)
401 goto cleanup;
403 DEVENUM_ReadPins(hkeyFilterClass, &rgf2);
405 res = CLSIDFromString(wszFilterSubkeyName, &clsidFilter);
406 if (FAILED(res)) goto cleanup;
408 IFilterMapper2_RegisterFilter(pMapper, &clsidFilter, wszFilterName, &pMoniker, NULL, NULL, &rgf2);
410 if (pMoniker)
411 IMoniker_Release(pMoniker);
413 cleanup:
415 if (hkeyFilterClass) RegCloseKey(hkeyFilterClass);
417 if (rgf2.u.s.rgPins)
419 UINT iPin;
421 for (iPin = 0; iPin < rgf2.u.s.cPins; iPin++)
423 CoTaskMemFree(rgf2.u.s.rgPins[iPin].strName);
425 if (rgf2.u.s.rgPins[iPin].lpMediaType)
427 UINT iType;
429 for (iType = 0; iType < rgf2.u.s.rgPins[iPin].nMediaTypes; iType++)
431 CoTaskMemFree((void*)rgf2.u.s.rgPins[iPin].lpMediaType[iType].clsMajorType);
432 CoTaskMemFree((void*)rgf2.u.s.rgPins[iPin].lpMediaType[iType].clsMinorType);
435 CoTaskMemFree((void*)rgf2.u.s.rgPins[iPin].lpMediaType);
439 CoTaskMemFree((void*)rgf2.u.s.rgPins);
445 if (hkeyFilter) RegCloseKey(hkeyFilter);
447 if (pMapper)
448 IFilterMapper2_Release(pMapper);
450 return S_OK;
453 /**********************************************************************
454 * DEVENUM_ICreateDevEnum_CreateClassEnumerator
456 static HRESULT WINAPI DEVENUM_ICreateDevEnum_CreateClassEnumerator(
457 ICreateDevEnum * iface,
458 REFCLSID clsidDeviceClass,
459 IEnumMoniker **ppEnumMoniker,
460 DWORD dwFlags)
462 WCHAR wszRegKey[MAX_PATH];
463 HKEY hkey;
464 HKEY hbasekey;
465 HRESULT hr;
466 CreateDevEnumImpl *This = (CreateDevEnumImpl *)iface;
468 TRACE("(%p)->(%s, %p, %x)\n\tDeviceClass:\t%s\n", This, debugstr_guid(clsidDeviceClass), ppEnumMoniker, dwFlags, debugstr_guid(clsidDeviceClass));
470 if (!ppEnumMoniker)
471 return E_POINTER;
473 *ppEnumMoniker = NULL;
475 if (IsEqualGUID(clsidDeviceClass, &CLSID_LegacyAmFilterCategory))
477 DEVENUM_RegisterLegacyAmFilters();
480 hr = DEVENUM_GetCategoryKey(clsidDeviceClass, &hbasekey, wszRegKey, MAX_PATH);
481 if (FAILED(hr))
482 return hr;
484 if (RegOpenKeyW(hbasekey, wszRegKey, &hkey) != ERROR_SUCCESS)
486 if (IsEqualGUID(clsidDeviceClass, &CLSID_AudioRendererCategory) ||
487 IsEqualGUID(clsidDeviceClass, &CLSID_AudioInputDeviceCategory) ||
488 IsEqualGUID(clsidDeviceClass, &CLSID_VideoInputDeviceCategory) ||
489 IsEqualGUID(clsidDeviceClass, &CLSID_MidiRendererCategory))
491 hr = DEVENUM_CreateSpecialCategories();
492 if (FAILED(hr))
493 return hr;
494 if (RegOpenKeyW(hbasekey, wszRegKey, &hkey) != ERROR_SUCCESS)
496 ERR("Couldn't open registry key for special device: %s\n",
497 debugstr_guid(clsidDeviceClass));
498 return S_FALSE;
501 else
503 FIXME("Category %s not found\n", debugstr_guid(clsidDeviceClass));
504 return S_FALSE;
508 return DEVENUM_IEnumMoniker_Construct(hkey, ppEnumMoniker);
511 /**********************************************************************
512 * ICreateDevEnum_Vtbl
514 static const ICreateDevEnumVtbl ICreateDevEnum_Vtbl =
516 DEVENUM_ICreateDevEnum_QueryInterface,
517 DEVENUM_ICreateDevEnum_AddRef,
518 DEVENUM_ICreateDevEnum_Release,
519 DEVENUM_ICreateDevEnum_CreateClassEnumerator,
522 /**********************************************************************
523 * static CreateDevEnum instance
525 CreateDevEnumImpl DEVENUM_CreateDevEnum = { &ICreateDevEnum_Vtbl };
527 /**********************************************************************
528 * DEVENUM_CreateAMCategoryKey (INTERNAL)
530 * Creates a registry key for a category at HKEY_CURRENT_USER\Software\
531 * Microsoft\ActiveMovie\devenum\{clsid}
533 static HRESULT DEVENUM_CreateAMCategoryKey(const CLSID * clsidCategory)
535 WCHAR wszRegKey[MAX_PATH];
536 HRESULT res = S_OK;
537 HKEY hkeyDummy = NULL;
539 strcpyW(wszRegKey, wszActiveMovieKey);
541 if (!StringFromGUID2(clsidCategory, wszRegKey + strlenW(wszRegKey), sizeof(wszRegKey)/sizeof(wszRegKey[0]) - strlenW(wszRegKey)))
542 res = E_INVALIDARG;
544 if (SUCCEEDED(res))
546 LONG lRes = RegCreateKeyW(HKEY_CURRENT_USER, wszRegKey, &hkeyDummy);
547 res = HRESULT_FROM_WIN32(lRes);
550 if (hkeyDummy)
551 RegCloseKey(hkeyDummy);
553 if (FAILED(res))
554 ERR("Failed to create key HKEY_CURRENT_USER\\%s\n", debugstr_w(wszRegKey));
556 return res;
559 /**********************************************************************
560 * DEVENUM_CreateSpecialCategories (INTERNAL)
562 * Creates the keys in the registry for the dynamic categories
564 static HRESULT DEVENUM_CreateSpecialCategories(void)
566 HRESULT res;
567 WCHAR szDSoundNameFormat[MAX_PATH + 1];
568 WCHAR szDSoundName[MAX_PATH + 1];
569 DWORD iDefaultDevice = -1;
570 UINT numDevs;
571 IFilterMapper2 * pMapper = NULL;
572 REGFILTER2 rf2;
573 REGFILTERPINS2 rfp2;
575 rf2.dwVersion = 2;
576 rf2.dwMerit = MERIT_PREFERRED;
577 rf2.u.s1.cPins2 = 1;
578 rf2.u.s1.rgPins2 = &rfp2;
579 rfp2.cInstances = 1;
580 rfp2.nMediums = 0;
581 rfp2.lpMedium = NULL;
582 rfp2.clsPinCategory = &IID_NULL;
584 if (!LoadStringW(DEVENUM_hInstance, IDS_DEVENUM_DS, szDSoundNameFormat, sizeof(szDSoundNameFormat)/sizeof(szDSoundNameFormat[0])-1))
586 ERR("Couldn't get string resource (GetLastError() is %d)\n", GetLastError());
587 return HRESULT_FROM_WIN32(GetLastError());
590 res = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC,
591 &IID_IFilterMapper2, (void **) &pMapper);
593 * Fill in info for devices
595 if (SUCCEEDED(res))
597 UINT i;
598 WAVEOUTCAPSW wocaps;
599 WAVEINCAPSW wicaps;
600 MIDIOUTCAPSW mocaps;
601 REGPINTYPES * pTypes;
603 numDevs = waveOutGetNumDevs();
605 res = DEVENUM_CreateAMCategoryKey(&CLSID_AudioRendererCategory);
606 if (FAILED(res)) /* can't register any devices in this category */
607 numDevs = 0;
609 rfp2.dwFlags = REG_PINFLAG_B_RENDERER;
610 for (i = 0; i < numDevs; i++)
612 if (waveOutGetDevCapsW(i, &wocaps, sizeof(WAVEOUTCAPSW))
613 == MMSYSERR_NOERROR)
615 IMoniker * pMoniker = NULL;
617 rfp2.nMediaTypes = 1;
618 pTypes = CoTaskMemAlloc(rfp2.nMediaTypes * sizeof(REGPINTYPES));
619 if (!pTypes)
621 IFilterMapper2_Release(pMapper);
622 return E_OUTOFMEMORY;
624 /* FIXME: Native devenum seems to register a lot more types for
625 * DSound than we do. Not sure what purpose they serve */
626 pTypes[0].clsMajorType = &MEDIATYPE_Audio;
627 pTypes[0].clsMinorType = &MEDIASUBTYPE_PCM;
629 rfp2.lpMediaType = pTypes;
631 res = IFilterMapper2_RegisterFilter(pMapper,
632 &CLSID_AudioRender,
633 wocaps.szPname,
634 &pMoniker,
635 &CLSID_AudioRendererCategory,
636 wocaps.szPname,
637 &rf2);
639 /* FIXME: do additional stuff with IMoniker here, depending on what RegisterFilter does */
641 if (pMoniker)
642 IMoniker_Release(pMoniker);
644 wsprintfW(szDSoundName, szDSoundNameFormat, wocaps.szPname);
645 res = IFilterMapper2_RegisterFilter(pMapper,
646 &CLSID_DSoundRender,
647 szDSoundName,
648 &pMoniker,
649 &CLSID_AudioRendererCategory,
650 szDSoundName,
651 &rf2);
653 /* FIXME: do additional stuff with IMoniker here, depending on what RegisterFilter does */
655 if (pMoniker)
656 IMoniker_Release(pMoniker);
658 if (i == iDefaultDevice)
660 FIXME("Default device\n");
663 CoTaskMemFree(pTypes);
667 numDevs = waveInGetNumDevs();
669 res = DEVENUM_CreateAMCategoryKey(&CLSID_AudioInputDeviceCategory);
670 if (FAILED(res)) /* can't register any devices in this category */
671 numDevs = 0;
673 rfp2.dwFlags = REG_PINFLAG_B_OUTPUT;
674 for (i = 0; i < numDevs; i++)
676 if (waveInGetDevCapsW(i, &wicaps, sizeof(WAVEINCAPSW))
677 == MMSYSERR_NOERROR)
679 IMoniker * pMoniker = NULL;
681 rfp2.nMediaTypes = 1;
682 pTypes = CoTaskMemAlloc(rfp2.nMediaTypes * sizeof(REGPINTYPES));
683 if (!pTypes)
685 IFilterMapper2_Release(pMapper);
686 return E_OUTOFMEMORY;
689 /* FIXME: Not sure if these are correct */
690 pTypes[0].clsMajorType = &MEDIATYPE_Audio;
691 pTypes[0].clsMinorType = &MEDIASUBTYPE_PCM;
693 rfp2.lpMediaType = pTypes;
695 res = IFilterMapper2_RegisterFilter(pMapper,
696 &CLSID_AudioRecord,
697 wicaps.szPname,
698 &pMoniker,
699 &CLSID_AudioInputDeviceCategory,
700 wicaps.szPname,
701 &rf2);
703 /* FIXME: do additional stuff with IMoniker here, depending on what RegisterFilter does */
705 if (pMoniker)
706 IMoniker_Release(pMoniker);
708 CoTaskMemFree(pTypes);
712 numDevs = midiOutGetNumDevs();
714 res = DEVENUM_CreateAMCategoryKey(&CLSID_MidiRendererCategory);
715 if (FAILED(res)) /* can't register any devices in this category */
716 numDevs = 0;
718 rfp2.dwFlags = REG_PINFLAG_B_RENDERER;
719 for (i = 0; i < numDevs; i++)
721 if (midiOutGetDevCapsW(i, &mocaps, sizeof(MIDIOUTCAPSW))
722 == MMSYSERR_NOERROR)
724 IMoniker * pMoniker = NULL;
726 rfp2.nMediaTypes = 1;
727 pTypes = CoTaskMemAlloc(rfp2.nMediaTypes * sizeof(REGPINTYPES));
728 if (!pTypes)
730 IFilterMapper2_Release(pMapper);
731 return E_OUTOFMEMORY;
734 /* FIXME: Not sure if these are correct */
735 pTypes[0].clsMajorType = &MEDIATYPE_Midi;
736 pTypes[0].clsMinorType = &MEDIASUBTYPE_None;
738 rfp2.lpMediaType = pTypes;
740 res = IFilterMapper2_RegisterFilter(pMapper,
741 &CLSID_AVIMIDIRender,
742 mocaps.szPname,
743 &pMoniker,
744 &CLSID_MidiRendererCategory,
745 mocaps.szPname,
746 &rf2);
748 /* FIXME: do additional stuff with IMoniker here, depending on what RegisterFilter does */
749 /* Native version sets MidiOutId */
751 if (pMoniker)
752 IMoniker_Release(pMoniker);
754 if (i == iDefaultDevice)
756 FIXME("Default device\n");
759 CoTaskMemFree(pTypes);
762 res = DEVENUM_CreateAMCategoryKey(&CLSID_VideoInputDeviceCategory);
763 if (SUCCEEDED(res))
764 for (i = 0; i < 10; i++)
766 WCHAR szDeviceName[32], szDeviceVersion[32], szDevicePath[10];
768 if (capGetDriverDescriptionW ((WORD) i,
769 szDeviceName, sizeof(szDeviceName)/sizeof(WCHAR),
770 szDeviceVersion, sizeof(szDeviceVersion)/sizeof(WCHAR)))
772 IMoniker * pMoniker = NULL;
773 IPropertyBag * pPropBag = NULL;
774 WCHAR dprintf[] = { 'v','i','d','e','o','%','d',0 };
775 snprintfW(szDevicePath, sizeof(szDevicePath)/sizeof(WCHAR), dprintf, i);
776 /* The above code prevents 1 device with a different ID overwriting another */
778 rfp2.nMediaTypes = 1;
779 pTypes = CoTaskMemAlloc(rfp2.nMediaTypes * sizeof(REGPINTYPES));
780 if (!pTypes) {
781 IFilterMapper2_Release(pMapper);
782 return E_OUTOFMEMORY;
785 pTypes[0].clsMajorType = &MEDIATYPE_Video;
786 pTypes[0].clsMinorType = &MEDIASUBTYPE_None;
788 rfp2.lpMediaType = pTypes;
790 res = IFilterMapper2_RegisterFilter(pMapper,
791 &CLSID_VfwCapture,
792 szDeviceName,
793 &pMoniker,
794 &CLSID_VideoInputDeviceCategory,
795 szDevicePath,
796 &rf2);
798 if (pMoniker) {
799 OLECHAR wszVfwIndex[] = { 'V','F','W','I','n','d','e','x',0 };
800 VARIANT var;
801 V_VT(&var) = VT_I4;
802 V_UNION(&var, ulVal) = i;
803 res = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (LPVOID)&pPropBag);
804 if (SUCCEEDED(res))
805 res = IPropertyBag_Write(pPropBag, wszVfwIndex, &var);
806 IMoniker_Release(pMoniker);
809 if (i == iDefaultDevice) FIXME("Default device\n");
810 CoTaskMemFree(pTypes);
815 if (pMapper)
816 IFilterMapper2_Release(pMapper);
817 return res;