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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * - Implements ICreateDevEnum interface which creates an IEnumMoniker
23 * - Also creates the special registry keys created at run-time
27 #include "devenum_private.h"
29 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(devenum);
34 extern ICOM_VTABLE(IEnumMoniker) IEnumMoniker_Vtbl;
36 extern HINSTANCE DEVENUM_hInstance;
38 const WCHAR wszInstanceKeyName[] ={'I','n','s','t','a','n','c','e',0};
39 const WCHAR wszRegSeperator[] = {'\\', 0 };
40 const WCHAR wszActiveMovieKey[] = {'S','o','f','t','w','a','r','e','\\',
41 'M','i','c','r','o','s','o','f','t','\\',
42 'A','c','t','i','v','e','M','o','v','i','e','\\',
43 'd','e','v','e','n','u','m','\\',0};
45 static ULONG WINAPI DEVENUM_ICreateDevEnum_AddRef(ICreateDevEnum * iface);
46 static HRESULT DEVENUM_CreateSpecialCategories();
48 /**********************************************************************
49 * DEVENUM_ICreateDevEnum_QueryInterface (also IUnknown)
51 static HRESULT WINAPI DEVENUM_ICreateDevEnum_QueryInterface(
52 ICreateDevEnum * iface,
56 ICOM_THIS(CreateDevEnumImpl, iface);
57 TRACE("\n\tIID:\t%s\n",debugstr_guid(riid));
59 if (This == NULL || ppvObj == NULL) return E_POINTER;
61 if (IsEqualGUID(riid, &IID_IUnknown) ||
62 IsEqualGUID(riid, &IID_ICreateDevEnum))
64 *ppvObj = (LPVOID)iface;
65 DEVENUM_ICreateDevEnum_AddRef(iface);
69 FIXME("- no interface\n\tIID:\t%s\n", debugstr_guid(riid));
73 /**********************************************************************
74 * DEVENUM_ICreateDevEnum_AddRef (also IUnknown)
76 static ULONG WINAPI DEVENUM_ICreateDevEnum_AddRef(ICreateDevEnum * iface)
78 ICOM_THIS(CreateDevEnumImpl, iface);
81 if (This == NULL) return E_POINTER;
83 if (InterlockedIncrement(&This->ref) == 1) {
84 InterlockedIncrement(&dll_ref);
89 /**********************************************************************
90 * DEVENUM_ICreateDevEnum_Release (also IUnknown)
92 static ULONG WINAPI DEVENUM_ICreateDevEnum_Release(ICreateDevEnum * iface)
94 ICOM_THIS(CreateDevEnumImpl, iface);
97 if (This == NULL) return E_POINTER;
99 if (InterlockedDecrement(&This->ref) == 0) {
100 InterlockedDecrement(&dll_ref);
105 /**********************************************************************
106 * DEVENUM_ICreateDevEnum_CreateClassEnumerator
108 HRESULT WINAPI DEVENUM_ICreateDevEnum_CreateClassEnumerator(
109 ICreateDevEnum * iface,
110 REFCLSID clsidDeviceClass,
111 IEnumMoniker **ppEnumMoniker,
114 WCHAR wszRegKey[MAX_PATH];
115 EnumMonikerImpl * pEnumMoniker;
118 ICOM_THIS(CreateDevEnumImpl, iface);
120 TRACE("(%p)->(%s, %p, %lx)\n\tDeviceClass:\t%s\n", This, debugstr_guid(clsidDeviceClass), ppEnumMoniker, dwFlags, debugstr_guid(clsidDeviceClass));
125 *ppEnumMoniker = NULL;
127 if (IsEqualGUID(clsidDeviceClass, &CLSID_AudioRendererCategory) ||
128 IsEqualGUID(clsidDeviceClass, &CLSID_MidiRendererCategory))
130 if (FAILED(DEVENUM_CreateSpecialCategories()))
133 hbasekey = HKEY_CURRENT_USER;
134 strcpyW(wszRegKey, wszActiveMovieKey);
136 if (!StringFromGUID2(clsidDeviceClass, wszRegKey + strlenW(wszRegKey), MAX_PATH - strlenW(wszRegKey)))
137 return E_OUTOFMEMORY;
141 hbasekey = HKEY_CLASSES_ROOT;
142 strcpyW(wszRegKey, clsid_keyname);
143 strcatW(wszRegKey, wszRegSeperator);
145 if (!StringFromGUID2(clsidDeviceClass, wszRegKey + CLSID_STR_LEN, MAX_PATH - CLSID_STR_LEN))
146 return E_OUTOFMEMORY;
148 strcatW(wszRegKey, wszRegSeperator);
149 strcatW(wszRegKey, wszInstanceKeyName);
152 if (RegOpenKeyW(hbasekey, wszRegKey, &hkey) != ERROR_SUCCESS)
154 FIXME("Category %s not found\n", debugstr_guid(clsidDeviceClass));
158 pEnumMoniker = (EnumMonikerImpl *)CoTaskMemAlloc(sizeof(EnumMonikerImpl));
160 return E_OUTOFMEMORY;
162 pEnumMoniker->lpVtbl = &IEnumMoniker_Vtbl;
163 pEnumMoniker->ref = 1;
164 pEnumMoniker->index = 0;
165 pEnumMoniker->hkey = hkey;
167 *ppEnumMoniker = (IEnumMoniker *)pEnumMoniker;
172 /**********************************************************************
173 * ICreateDevEnum_Vtbl
175 static ICOM_VTABLE(ICreateDevEnum) ICreateDevEnum_Vtbl =
177 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
178 DEVENUM_ICreateDevEnum_QueryInterface,
179 DEVENUM_ICreateDevEnum_AddRef,
180 DEVENUM_ICreateDevEnum_Release,
181 DEVENUM_ICreateDevEnum_CreateClassEnumerator,
184 /**********************************************************************
185 * static CreateDevEnum instance
187 CreateDevEnumImpl DEVENUM_CreateDevEnum = { &ICreateDevEnum_Vtbl, 0 };
190 /**********************************************************************
191 * CreateSpecialCategories (INTERNAL)
193 * Creates the keys in the registry for the dynamic categories
195 static HRESULT DEVENUM_CreateSpecialCategories()
198 /* this section below needs some attention - when it is enabled it appears to create
199 * a circular dependency. IE IFilterMapper2_RegisterFilter calls back into this library
200 * which again calls RegisterFilter.
203 IMoniker * pMoniker = NULL;
204 WCHAR szAltNameFormat[MAX_PATH + 1];
205 WCHAR szAltName[MAX_PATH + 1];
206 DWORD iDefaultDevice = -1;
208 IFilterMapper2 * pMapper = NULL;
213 rf2.dwMerit = MERIT_PREFERRED;
215 rf2.u.s1.rgPins2 = &rfp2;
216 rfp2.dwFlags = REG_PINFLAG_B_RENDERER;
219 rfp2.lpMedium = NULL;
220 rfp2.clsPinCategory = &IID_NULL;
222 res = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC,
223 &IID_IFilterMapper2, (void **) &pMapper);
225 * Fill in info for out devices
233 REGPINTYPES * pTypes;
234 numDevs = waveOutGetNumDevs();
236 for (i = 0; i < numDevs; i++)
238 LoadStringW(DEVENUM_hInstance, IDS_DEVENUM_DS, szAltNameFormat, MAX_PATH);
239 if (waveOutGetDevCapsW(i, &wocaps, sizeof(WAVEOUTCAPSW))
242 rfp2.nMediaTypes = 1;
243 pTypes = CoTaskMemAlloc(rfp2.nMediaTypes * sizeof(REGPINTYPES));
246 IFilterMapper2_Release(pMapper);
247 return E_OUTOFMEMORY;
249 /* FIXME: Native devenum seems to register a lot more types for
250 * DSound than we do. Not sure what purpose they serve */
251 pTypes[0].clsMajorType = &MEDIATYPE_Audio;
252 pTypes[0].clsMinorType = &MEDIASUBTYPE_PCM;
254 rfp2.lpMediaType = pTypes;
256 IFilterMapper2_RegisterFilter(pMapper,
260 &CLSID_AudioRendererCategory,
264 /* FIXME: do additional stuff with IMoniker here, depending on what RegisterFilter does */
267 IMoniker_Release(pMoniker);
269 wsprintfW(szAltName, szAltNameFormat, wocaps.szPname);
270 IFilterMapper2_RegisterFilter(pMapper,
274 &CLSID_AudioRendererCategory,
278 /* FIXME: do additional stuff with IMoniker here, depending on what RegisterFilter does */
281 IMoniker_Release(pMoniker);
283 if (i == iDefaultDevice)
285 FIXME("Default device\n");
288 CoTaskMemFree(pTypes);
292 numDevs = waveInGetNumDevs();
294 for (i = 0; i < numDevs; i++)
296 if (waveInGetDevCapsW(i, &wicaps, sizeof(WAVEINCAPSW))
299 rfp2.nMediaTypes = 1;
300 pTypes = CoTaskMemAlloc(rfp2.nMediaTypes * sizeof(REGPINTYPES));
303 IFilterMapper2_Release(pMapper);
304 return E_OUTOFMEMORY;
307 /* FIXME: Not sure if these are correct */
308 pTypes[0].clsMajorType = &MEDIATYPE_Audio;
309 pTypes[0].clsMinorType = &MEDIASUBTYPE_PCM;
311 rfp2.lpMediaType = pTypes;
313 IFilterMapper2_RegisterFilter(pMapper,
317 &CLSID_AudioInputDeviceCategory,
321 /* FIXME: do additional stuff with IMoniker here, depending on what RegisterFilter does */
324 IMoniker_Release(pMoniker);
326 CoTaskMemFree(pTypes);
329 numDevs = midiOutGetNumDevs();
331 for (i = 0; i < numDevs; i++)
333 if (midiOutGetDevCapsW(i, &mocaps, sizeof(MIDIOUTCAPSW))
336 rfp2.nMediaTypes = 1;
337 pTypes = CoTaskMemAlloc(rfp2.nMediaTypes * sizeof(REGPINTYPES));
340 IFilterMapper2_Release(pMapper);
341 return E_OUTOFMEMORY;
344 /* FIXME: Not sure if these are correct */
345 pTypes[0].clsMajorType = &MEDIATYPE_Midi;
346 pTypes[0].clsMinorType = &MEDIASUBTYPE_None;
348 rfp2.lpMediaType = pTypes;
350 IFilterMapper2_RegisterFilter(pMapper,
351 &CLSID_AVIMIDIRender,
354 &CLSID_MidiRendererCategory,
358 /* FIXME: do additional stuff with IMoniker here, depending on what RegisterFilter does */
359 /* Native version sets MidiOutId */
362 IMoniker_Release(pMoniker);
364 if (i == iDefaultDevice)
366 FIXME("Default device\n");
369 CoTaskMemFree(pTypes);
375 IFilterMapper2_Release(pMapper);