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
26 #define NONAMELESSSTRUCT
27 #define NONAMELESSUNION
29 #include "devenum_private.h"
31 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(devenum
);
36 extern ICOM_VTABLE(IEnumMoniker
) IEnumMoniker_Vtbl
;
38 extern HINSTANCE DEVENUM_hInstance
;
40 const WCHAR wszInstanceKeyName
[] ={'I','n','s','t','a','n','c','e',0};
42 static const WCHAR wszRegSeperator
[] = {'\\', 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};
48 static ULONG WINAPI
DEVENUM_ICreateDevEnum_AddRef(ICreateDevEnum
* iface
);
49 static HRESULT
DEVENUM_CreateSpecialCategories();
51 /**********************************************************************
52 * DEVENUM_ICreateDevEnum_QueryInterface (also IUnknown)
54 static HRESULT WINAPI
DEVENUM_ICreateDevEnum_QueryInterface(
55 ICreateDevEnum
* iface
,
59 ICOM_THIS(CreateDevEnumImpl
, iface
);
60 TRACE("\n\tIID:\t%s\n",debugstr_guid(riid
));
62 if (This
== NULL
|| ppvObj
== NULL
) return E_POINTER
;
64 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
65 IsEqualGUID(riid
, &IID_ICreateDevEnum
))
67 *ppvObj
= (LPVOID
)iface
;
68 DEVENUM_ICreateDevEnum_AddRef(iface
);
72 FIXME("- no interface\n\tIID:\t%s\n", debugstr_guid(riid
));
76 /**********************************************************************
77 * DEVENUM_ICreateDevEnum_AddRef (also IUnknown)
79 static ULONG WINAPI
DEVENUM_ICreateDevEnum_AddRef(ICreateDevEnum
* iface
)
81 ICOM_THIS(CreateDevEnumImpl
, iface
);
84 if (This
== NULL
) return E_POINTER
;
86 if (InterlockedIncrement(&This
->ref
) == 1) {
87 InterlockedIncrement(&dll_ref
);
92 /**********************************************************************
93 * DEVENUM_ICreateDevEnum_Release (also IUnknown)
95 static ULONG WINAPI
DEVENUM_ICreateDevEnum_Release(ICreateDevEnum
* iface
)
97 ICOM_THIS(CreateDevEnumImpl
, iface
);
100 if (This
== NULL
) return E_POINTER
;
102 if (InterlockedDecrement(&This
->ref
) == 0) {
103 InterlockedDecrement(&dll_ref
);
108 /**********************************************************************
109 * DEVENUM_ICreateDevEnum_CreateClassEnumerator
111 HRESULT WINAPI
DEVENUM_ICreateDevEnum_CreateClassEnumerator(
112 ICreateDevEnum
* iface
,
113 REFCLSID clsidDeviceClass
,
114 IEnumMoniker
**ppEnumMoniker
,
117 WCHAR wszRegKey
[MAX_PATH
];
118 EnumMonikerImpl
* pEnumMoniker
;
121 ICOM_THIS(CreateDevEnumImpl
, iface
);
123 TRACE("(%p)->(%s, %p, %lx)\n\tDeviceClass:\t%s\n", This
, debugstr_guid(clsidDeviceClass
), ppEnumMoniker
, dwFlags
, debugstr_guid(clsidDeviceClass
));
128 *ppEnumMoniker
= NULL
;
130 if (IsEqualGUID(clsidDeviceClass
, &CLSID_AudioRendererCategory
) ||
131 IsEqualGUID(clsidDeviceClass
, &CLSID_AudioInputDeviceCategory
) ||
132 IsEqualGUID(clsidDeviceClass
, &CLSID_MidiRendererCategory
))
134 hbasekey
= HKEY_CURRENT_USER
;
135 strcpyW(wszRegKey
, wszActiveMovieKey
);
137 if (!StringFromGUID2(clsidDeviceClass
, wszRegKey
+ strlenW(wszRegKey
), MAX_PATH
- strlenW(wszRegKey
)))
138 return E_OUTOFMEMORY
;
142 hbasekey
= HKEY_CLASSES_ROOT
;
143 strcpyW(wszRegKey
, clsid_keyname
);
144 strcatW(wszRegKey
, wszRegSeperator
);
146 if (!StringFromGUID2(clsidDeviceClass
, wszRegKey
+ CLSID_STR_LEN
, MAX_PATH
- CLSID_STR_LEN
))
147 return E_OUTOFMEMORY
;
149 strcatW(wszRegKey
, wszRegSeperator
);
150 strcatW(wszRegKey
, wszInstanceKeyName
);
153 if (RegOpenKeyW(hbasekey
, wszRegKey
, &hkey
) != ERROR_SUCCESS
)
155 if (IsEqualGUID(clsidDeviceClass
, &CLSID_AudioRendererCategory
) ||
156 IsEqualGUID(clsidDeviceClass
, &CLSID_AudioInputDeviceCategory
) ||
157 IsEqualGUID(clsidDeviceClass
, &CLSID_MidiRendererCategory
))
159 HRESULT hr
= DEVENUM_CreateSpecialCategories();
162 if (RegOpenKeyW(hbasekey
, wszRegKey
, &hkey
) != ERROR_SUCCESS
)
164 ERR("Couldn't open registry key for special device: %s\n",
165 debugstr_guid(clsidDeviceClass
));
171 FIXME("Category %s not found\n", debugstr_guid(clsidDeviceClass
));
176 pEnumMoniker
= (EnumMonikerImpl
*)CoTaskMemAlloc(sizeof(EnumMonikerImpl
));
178 return E_OUTOFMEMORY
;
180 pEnumMoniker
->lpVtbl
= &IEnumMoniker_Vtbl
;
181 pEnumMoniker
->ref
= 1;
182 pEnumMoniker
->index
= 0;
183 pEnumMoniker
->hkey
= hkey
;
185 *ppEnumMoniker
= (IEnumMoniker
*)pEnumMoniker
;
190 /**********************************************************************
191 * ICreateDevEnum_Vtbl
193 static ICOM_VTABLE(ICreateDevEnum
) ICreateDevEnum_Vtbl
=
195 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
196 DEVENUM_ICreateDevEnum_QueryInterface
,
197 DEVENUM_ICreateDevEnum_AddRef
,
198 DEVENUM_ICreateDevEnum_Release
,
199 DEVENUM_ICreateDevEnum_CreateClassEnumerator
,
202 /**********************************************************************
203 * static CreateDevEnum instance
205 CreateDevEnumImpl DEVENUM_CreateDevEnum
= { &ICreateDevEnum_Vtbl
, 0 };
207 /**********************************************************************
208 * DEVENUM_CreateAMCategoryKey (INTERNAL)
210 * Creates a registry key for a category at HKEY_CURRENT_USER\Software\
211 * Microsoft\ActiveMovie\devenum\{clsid}
213 static HRESULT
DEVENUM_CreateAMCategoryKey(const CLSID
* clsidCategory
)
215 WCHAR wszRegKey
[MAX_PATH
];
217 HKEY hkeyDummy
= NULL
;
219 strcpyW(wszRegKey
, wszActiveMovieKey
);
221 if (!StringFromGUID2(clsidCategory
, wszRegKey
+ strlenW(wszRegKey
), sizeof(wszRegKey
)/sizeof(wszRegKey
[0]) - strlenW(wszRegKey
)))
225 res
= HRESULT_FROM_WIN32(
226 RegCreateKeyW(HKEY_CURRENT_USER
, wszRegKey
, &hkeyDummy
));
229 RegCloseKey(hkeyDummy
);
232 ERR("Failed to create key HKEY_CURRENT_USER\\%s\n", debugstr_w(wszRegKey
));
237 /**********************************************************************
238 * DEVENUM_CreateSpecialCategories (INTERNAL)
240 * Creates the keys in the registry for the dynamic categories
242 static HRESULT
DEVENUM_CreateSpecialCategories()
245 WCHAR szDSoundNameFormat
[MAX_PATH
+ 1];
246 WCHAR szDSoundName
[MAX_PATH
+ 1];
247 DWORD iDefaultDevice
= -1;
249 IFilterMapper2
* pMapper
= NULL
;
254 rf2
.dwMerit
= MERIT_PREFERRED
;
256 rf2
.u
.s1
.rgPins2
= &rfp2
;
257 rfp2
.dwFlags
= REG_PINFLAG_B_RENDERER
;
260 rfp2
.lpMedium
= NULL
;
261 rfp2
.clsPinCategory
= &IID_NULL
;
263 if (!LoadStringW(DEVENUM_hInstance
, IDS_DEVENUM_DS
, szDSoundNameFormat
, sizeof(szDSoundNameFormat
)/sizeof(szDSoundNameFormat
[0])-1))
265 ERR("Couldn't get string resource (GetLastError() is %ld)\n", GetLastError());
266 return HRESULT_FROM_WIN32(GetLastError());
269 res
= CoCreateInstance(&CLSID_FilterMapper2
, NULL
, CLSCTX_INPROC
,
270 &IID_IFilterMapper2
, (void **) &pMapper
);
272 * Fill in info for devices
280 REGPINTYPES
* pTypes
;
282 numDevs
= waveOutGetNumDevs();
284 res
= DEVENUM_CreateAMCategoryKey(&CLSID_AudioRendererCategory
);
285 if (FAILED(res
)) /* can't register any devices in this category */
288 for (i
= 0; i
< numDevs
; i
++)
290 if (waveOutGetDevCapsW(i
, &wocaps
, sizeof(WAVEOUTCAPSW
))
293 IMoniker
* pMoniker
= NULL
;
295 rfp2
.nMediaTypes
= 1;
296 pTypes
= CoTaskMemAlloc(rfp2
.nMediaTypes
* sizeof(REGPINTYPES
));
299 IFilterMapper2_Release(pMapper
);
300 return E_OUTOFMEMORY
;
302 /* FIXME: Native devenum seems to register a lot more types for
303 * DSound than we do. Not sure what purpose they serve */
304 pTypes
[0].clsMajorType
= &MEDIATYPE_Audio
;
305 pTypes
[0].clsMinorType
= &MEDIASUBTYPE_PCM
;
307 rfp2
.lpMediaType
= pTypes
;
309 res
= IFilterMapper2_RegisterFilter(pMapper
,
313 &CLSID_AudioRendererCategory
,
317 /* FIXME: do additional stuff with IMoniker here, depending on what RegisterFilter does */
320 IMoniker_Release(pMoniker
);
322 wsprintfW(szDSoundName
, szDSoundNameFormat
, wocaps
.szPname
);
323 res
= IFilterMapper2_RegisterFilter(pMapper
,
327 &CLSID_AudioRendererCategory
,
331 /* FIXME: do additional stuff with IMoniker here, depending on what RegisterFilter does */
334 IMoniker_Release(pMoniker
);
336 if (i
== iDefaultDevice
)
338 FIXME("Default device\n");
341 CoTaskMemFree(pTypes
);
345 numDevs
= waveInGetNumDevs();
347 res
= DEVENUM_CreateAMCategoryKey(&CLSID_AudioInputDeviceCategory
);
348 if (FAILED(res
)) /* can't register any devices in this category */
351 for (i
= 0; i
< numDevs
; i
++)
353 if (waveInGetDevCapsW(i
, &wicaps
, sizeof(WAVEINCAPSW
))
356 IMoniker
* pMoniker
= NULL
;
358 rfp2
.nMediaTypes
= 1;
359 pTypes
= CoTaskMemAlloc(rfp2
.nMediaTypes
* sizeof(REGPINTYPES
));
362 IFilterMapper2_Release(pMapper
);
363 return E_OUTOFMEMORY
;
366 /* FIXME: Not sure if these are correct */
367 pTypes
[0].clsMajorType
= &MEDIATYPE_Audio
;
368 pTypes
[0].clsMinorType
= &MEDIASUBTYPE_PCM
;
370 rfp2
.lpMediaType
= pTypes
;
372 res
= IFilterMapper2_RegisterFilter(pMapper
,
376 &CLSID_AudioInputDeviceCategory
,
380 /* FIXME: do additional stuff with IMoniker here, depending on what RegisterFilter does */
383 IMoniker_Release(pMoniker
);
385 CoTaskMemFree(pTypes
);
389 numDevs
= midiOutGetNumDevs();
391 res
= DEVENUM_CreateAMCategoryKey(&CLSID_MidiRendererCategory
);
392 if (FAILED(res
)) /* can't register any devices in this category */
395 for (i
= 0; i
< numDevs
; i
++)
397 if (midiOutGetDevCapsW(i
, &mocaps
, sizeof(MIDIOUTCAPSW
))
400 IMoniker
* pMoniker
= NULL
;
402 rfp2
.nMediaTypes
= 1;
403 pTypes
= CoTaskMemAlloc(rfp2
.nMediaTypes
* sizeof(REGPINTYPES
));
406 IFilterMapper2_Release(pMapper
);
407 return E_OUTOFMEMORY
;
410 /* FIXME: Not sure if these are correct */
411 pTypes
[0].clsMajorType
= &MEDIATYPE_Midi
;
412 pTypes
[0].clsMinorType
= &MEDIASUBTYPE_None
;
414 rfp2
.lpMediaType
= pTypes
;
416 res
= IFilterMapper2_RegisterFilter(pMapper
,
417 &CLSID_AVIMIDIRender
,
420 &CLSID_MidiRendererCategory
,
424 /* FIXME: do additional stuff with IMoniker here, depending on what RegisterFilter does */
425 /* Native version sets MidiOutId */
428 IMoniker_Release(pMoniker
);
430 if (i
== iDefaultDevice
)
432 FIXME("Default device\n");
435 CoTaskMemFree(pTypes
);
441 IFilterMapper2_Release(pMapper
);