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
30 #define DUMMYSTRUCTNAME s
31 #define DUMMYSTRUCTNAME1 s1
32 #define DUMMYSTRUCTNAME2 s2
33 #define DUMMYSTRUCTNAME3 s3
34 #define DUMMYSTRUCTNAME4 s4
35 #define DUMMYSTRUCTNAME5 s5
37 #define DUMMYUNIONNAME u
38 #define DUMMYUNIONNAME1 u1
39 #define DUMMYUNIONNAME2 u2
40 #define DUMMYUNIONNAME3 u3
41 #define DUMMYUNIONNAME4 u4
42 #define DUMMYUNIONNAME5 u5
43 #define DUMMYUNIONNAME6 u6
44 #define DUMMYUNIONNAME7 u7
45 #define DUMMYUNIONNAME8 u8
47 #include "devenum_private.h"
49 #include "wine/debug.h"
52 WINE_DEFAULT_DEBUG_CHANNEL(devenum
);
54 extern HINSTANCE DEVENUM_hInstance
;
56 const WCHAR wszInstanceKeyName
[] ={'I','n','s','t','a','n','c','e',0};
58 static const WCHAR wszRegSeparator
[] = {'\\', 0 };
59 static const WCHAR wszActiveMovieKey
[] = {'S','o','f','t','w','a','r','e','\\',
60 'M','i','c','r','o','s','o','f','t','\\',
61 'A','c','t','i','v','e','M','o','v','i','e','\\',
62 'd','e','v','e','n','u','m','\\',0};
64 static ULONG WINAPI
DEVENUM_ICreateDevEnum_AddRef(ICreateDevEnum
* iface
);
65 static HRESULT
DEVENUM_CreateSpecialCategories(void);
67 /**********************************************************************
68 * DEVENUM_ICreateDevEnum_QueryInterface (also IUnknown)
70 static HRESULT WINAPI
DEVENUM_ICreateDevEnum_QueryInterface(
71 ICreateDevEnum
* iface
,
75 TRACE("\n\tIID:\t%s\n",debugstr_guid(riid
));
77 if (ppvObj
== NULL
) return E_POINTER
;
79 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
80 IsEqualGUID(riid
, &IID_ICreateDevEnum
))
82 *ppvObj
= (LPVOID
)iface
;
83 DEVENUM_ICreateDevEnum_AddRef(iface
);
87 FIXME("- no interface\n\tIID:\t%s\n", debugstr_guid(riid
));
91 /**********************************************************************
92 * DEVENUM_ICreateDevEnum_AddRef (also IUnknown)
94 static ULONG WINAPI
DEVENUM_ICreateDevEnum_AddRef(ICreateDevEnum
* iface
)
100 return 2; /* non-heap based object */
103 /**********************************************************************
104 * DEVENUM_ICreateDevEnum_Release (also IUnknown)
106 static ULONG WINAPI
DEVENUM_ICreateDevEnum_Release(ICreateDevEnum
* iface
)
110 DEVENUM_UnlockModule();
112 return 1; /* non-heap based object */
115 /**********************************************************************
116 * DEVENUM_ICreateDevEnum_CreateClassEnumerator
118 HRESULT WINAPI
DEVENUM_ICreateDevEnum_CreateClassEnumerator(
119 ICreateDevEnum
* iface
,
120 REFCLSID clsidDeviceClass
,
121 IEnumMoniker
**ppEnumMoniker
,
124 WCHAR wszRegKey
[MAX_PATH
];
127 CreateDevEnumImpl
*This
= (CreateDevEnumImpl
*)iface
;
129 TRACE("(%p)->(%s, %p, %lx)\n\tDeviceClass:\t%s\n", This
, debugstr_guid(clsidDeviceClass
), ppEnumMoniker
, dwFlags
, debugstr_guid(clsidDeviceClass
));
134 *ppEnumMoniker
= NULL
;
136 if (IsEqualGUID(clsidDeviceClass
, &CLSID_AudioRendererCategory
) ||
137 IsEqualGUID(clsidDeviceClass
, &CLSID_AudioInputDeviceCategory
) ||
138 IsEqualGUID(clsidDeviceClass
, &CLSID_MidiRendererCategory
))
140 hbasekey
= HKEY_CURRENT_USER
;
141 strcpyW(wszRegKey
, wszActiveMovieKey
);
143 if (!StringFromGUID2(clsidDeviceClass
, wszRegKey
+ strlenW(wszRegKey
), MAX_PATH
- strlenW(wszRegKey
)))
144 return E_OUTOFMEMORY
;
148 hbasekey
= HKEY_CLASSES_ROOT
;
149 strcpyW(wszRegKey
, clsid_keyname
);
150 strcatW(wszRegKey
, wszRegSeparator
);
152 if (!StringFromGUID2(clsidDeviceClass
, wszRegKey
+ CLSID_STR_LEN
, MAX_PATH
- CLSID_STR_LEN
))
153 return E_OUTOFMEMORY
;
155 strcatW(wszRegKey
, wszRegSeparator
);
156 strcatW(wszRegKey
, wszInstanceKeyName
);
159 if (RegOpenKeyW(hbasekey
, wszRegKey
, &hkey
) != ERROR_SUCCESS
)
161 if (IsEqualGUID(clsidDeviceClass
, &CLSID_AudioRendererCategory
) ||
162 IsEqualGUID(clsidDeviceClass
, &CLSID_AudioInputDeviceCategory
) ||
163 IsEqualGUID(clsidDeviceClass
, &CLSID_MidiRendererCategory
))
165 HRESULT hr
= DEVENUM_CreateSpecialCategories();
168 if (RegOpenKeyW(hbasekey
, wszRegKey
, &hkey
) != ERROR_SUCCESS
)
170 ERR("Couldn't open registry key for special device: %s\n",
171 debugstr_guid(clsidDeviceClass
));
177 FIXME("Category %s not found\n", debugstr_guid(clsidDeviceClass
));
182 return DEVENUM_IEnumMoniker_Construct(hkey
, ppEnumMoniker
);
185 /**********************************************************************
186 * ICreateDevEnum_Vtbl
188 static ICreateDevEnumVtbl ICreateDevEnum_Vtbl
=
190 DEVENUM_ICreateDevEnum_QueryInterface
,
191 DEVENUM_ICreateDevEnum_AddRef
,
192 DEVENUM_ICreateDevEnum_Release
,
193 DEVENUM_ICreateDevEnum_CreateClassEnumerator
,
196 /**********************************************************************
197 * static CreateDevEnum instance
199 CreateDevEnumImpl DEVENUM_CreateDevEnum
= { &ICreateDevEnum_Vtbl
};
201 /**********************************************************************
202 * DEVENUM_CreateAMCategoryKey (INTERNAL)
204 * Creates a registry key for a category at HKEY_CURRENT_USER\Software\
205 * Microsoft\ActiveMovie\devenum\{clsid}
207 static HRESULT
DEVENUM_CreateAMCategoryKey(const CLSID
* clsidCategory
)
209 WCHAR wszRegKey
[MAX_PATH
];
211 HKEY hkeyDummy
= NULL
;
213 strcpyW(wszRegKey
, wszActiveMovieKey
);
215 if (!StringFromGUID2(clsidCategory
, wszRegKey
+ strlenW(wszRegKey
), sizeof(wszRegKey
)/sizeof(wszRegKey
[0]) - strlenW(wszRegKey
)))
219 res
= HRESULT_FROM_WIN32(
220 RegCreateKeyW(HKEY_CURRENT_USER
, wszRegKey
, &hkeyDummy
));
223 RegCloseKey(hkeyDummy
);
226 ERR("Failed to create key HKEY_CURRENT_USER\\%s\n", debugstr_w(wszRegKey
));
231 /**********************************************************************
232 * DEVENUM_CreateSpecialCategories (INTERNAL)
234 * Creates the keys in the registry for the dynamic categories
236 static HRESULT
DEVENUM_CreateSpecialCategories()
239 WCHAR szDSoundNameFormat
[MAX_PATH
+ 1];
240 WCHAR szDSoundName
[MAX_PATH
+ 1];
241 DWORD iDefaultDevice
= -1;
243 IFilterMapper2
* pMapper
= NULL
;
248 rf2
.dwMerit
= MERIT_PREFERRED
;
250 rf2
.u
.s1
.rgPins2
= &rfp2
;
251 rfp2
.dwFlags
= REG_PINFLAG_B_RENDERER
;
254 rfp2
.lpMedium
= NULL
;
255 rfp2
.clsPinCategory
= &IID_NULL
;
257 if (!LoadStringW(DEVENUM_hInstance
, IDS_DEVENUM_DS
, szDSoundNameFormat
, sizeof(szDSoundNameFormat
)/sizeof(szDSoundNameFormat
[0])-1))
259 ERR("Couldn't get string resource (GetLastError() is %ld)\n", GetLastError());
260 return HRESULT_FROM_WIN32(GetLastError());
263 res
= CoCreateInstance(&CLSID_FilterMapper2
, NULL
, CLSCTX_INPROC
,
264 &IID_IFilterMapper2
, (void **) &pMapper
);
266 * Fill in info for devices
274 REGPINTYPES
* pTypes
;
276 numDevs
= waveOutGetNumDevs();
278 res
= DEVENUM_CreateAMCategoryKey(&CLSID_AudioRendererCategory
);
279 if (FAILED(res
)) /* can't register any devices in this category */
282 for (i
= 0; i
< numDevs
; i
++)
284 if (waveOutGetDevCapsW(i
, &wocaps
, sizeof(WAVEOUTCAPSW
))
287 IMoniker
* pMoniker
= NULL
;
289 rfp2
.nMediaTypes
= 1;
290 pTypes
= CoTaskMemAlloc(rfp2
.nMediaTypes
* sizeof(REGPINTYPES
));
293 IFilterMapper2_Release(pMapper
);
294 return E_OUTOFMEMORY
;
296 /* FIXME: Native devenum seems to register a lot more types for
297 * DSound than we do. Not sure what purpose they serve */
298 pTypes
[0].clsMajorType
= &MEDIATYPE_Audio
;
299 pTypes
[0].clsMinorType
= &MEDIASUBTYPE_PCM
;
301 rfp2
.lpMediaType
= pTypes
;
303 res
= IFilterMapper2_RegisterFilter(pMapper
,
307 &CLSID_AudioRendererCategory
,
311 /* FIXME: do additional stuff with IMoniker here, depending on what RegisterFilter does */
314 IMoniker_Release(pMoniker
);
316 wsprintfW(szDSoundName
, szDSoundNameFormat
, wocaps
.szPname
);
317 res
= IFilterMapper2_RegisterFilter(pMapper
,
321 &CLSID_AudioRendererCategory
,
325 /* FIXME: do additional stuff with IMoniker here, depending on what RegisterFilter does */
328 IMoniker_Release(pMoniker
);
330 if (i
== iDefaultDevice
)
332 FIXME("Default device\n");
335 CoTaskMemFree(pTypes
);
339 numDevs
= waveInGetNumDevs();
341 res
= DEVENUM_CreateAMCategoryKey(&CLSID_AudioInputDeviceCategory
);
342 if (FAILED(res
)) /* can't register any devices in this category */
345 for (i
= 0; i
< numDevs
; i
++)
347 if (waveInGetDevCapsW(i
, &wicaps
, sizeof(WAVEINCAPSW
))
350 IMoniker
* pMoniker
= NULL
;
352 rfp2
.nMediaTypes
= 1;
353 pTypes
= CoTaskMemAlloc(rfp2
.nMediaTypes
* sizeof(REGPINTYPES
));
356 IFilterMapper2_Release(pMapper
);
357 return E_OUTOFMEMORY
;
360 /* FIXME: Not sure if these are correct */
361 pTypes
[0].clsMajorType
= &MEDIATYPE_Audio
;
362 pTypes
[0].clsMinorType
= &MEDIASUBTYPE_PCM
;
364 rfp2
.lpMediaType
= pTypes
;
366 res
= IFilterMapper2_RegisterFilter(pMapper
,
370 &CLSID_AudioInputDeviceCategory
,
374 /* FIXME: do additional stuff with IMoniker here, depending on what RegisterFilter does */
377 IMoniker_Release(pMoniker
);
379 CoTaskMemFree(pTypes
);
383 numDevs
= midiOutGetNumDevs();
385 res
= DEVENUM_CreateAMCategoryKey(&CLSID_MidiRendererCategory
);
386 if (FAILED(res
)) /* can't register any devices in this category */
389 for (i
= 0; i
< numDevs
; i
++)
391 if (midiOutGetDevCapsW(i
, &mocaps
, sizeof(MIDIOUTCAPSW
))
394 IMoniker
* pMoniker
= NULL
;
396 rfp2
.nMediaTypes
= 1;
397 pTypes
= CoTaskMemAlloc(rfp2
.nMediaTypes
* sizeof(REGPINTYPES
));
400 IFilterMapper2_Release(pMapper
);
401 return E_OUTOFMEMORY
;
404 /* FIXME: Not sure if these are correct */
405 pTypes
[0].clsMajorType
= &MEDIATYPE_Midi
;
406 pTypes
[0].clsMinorType
= &MEDIASUBTYPE_None
;
408 rfp2
.lpMediaType
= pTypes
;
410 res
= IFilterMapper2_RegisterFilter(pMapper
,
411 &CLSID_AVIMIDIRender
,
414 &CLSID_MidiRendererCategory
,
418 /* FIXME: do additional stuff with IMoniker here, depending on what RegisterFilter does */
419 /* Native version sets MidiOutId */
422 IMoniker_Release(pMoniker
);
424 if (i
== iDefaultDevice
)
426 FIXME("Default device\n");
429 CoTaskMemFree(pTypes
);
435 IFilterMapper2_Release(pMapper
);