Make WINE_GET_SONAME work on NetBSD.
[wine/wine64.git] / dlls / devenum / createdevenum.c
blobc84857c990986e4cb51656baad1e6fa567a24b38
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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
24 * - ...
27 #include "devenum_private.h"
29 #include "wine/debug.h"
30 #include "mmddk.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,
53 REFIID riid,
54 LPVOID *ppvObj)
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);
66 return S_OK;
69 FIXME("- no interface\n\tIID:\t%s\n", debugstr_guid(riid));
70 return E_NOINTERFACE;
73 /**********************************************************************
74 * DEVENUM_ICreateDevEnum_AddRef (also IUnknown)
76 static ULONG WINAPI DEVENUM_ICreateDevEnum_AddRef(ICreateDevEnum * iface)
78 ICOM_THIS(CreateDevEnumImpl, iface);
79 TRACE("\n");
81 if (This == NULL) return E_POINTER;
83 if (InterlockedIncrement(&This->ref) == 1) {
84 InterlockedIncrement(&dll_ref);
86 return This->ref;
89 /**********************************************************************
90 * DEVENUM_ICreateDevEnum_Release (also IUnknown)
92 static ULONG WINAPI DEVENUM_ICreateDevEnum_Release(ICreateDevEnum * iface)
94 ICOM_THIS(CreateDevEnumImpl, iface);
95 TRACE("\n");
97 if (This == NULL) return E_POINTER;
99 if (InterlockedDecrement(&This->ref) == 0) {
100 InterlockedDecrement(&dll_ref);
102 return This->ref;
105 /**********************************************************************
106 * DEVENUM_ICreateDevEnum_CreateClassEnumerator
108 HRESULT WINAPI DEVENUM_ICreateDevEnum_CreateClassEnumerator(
109 ICreateDevEnum * iface,
110 REFCLSID clsidDeviceClass,
111 IEnumMoniker **ppEnumMoniker,
112 DWORD dwFlags)
114 WCHAR wszRegKey[MAX_PATH];
115 EnumMonikerImpl * pEnumMoniker;
116 HKEY hkey;
117 HKEY hbasekey;
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));
122 if (!ppEnumMoniker)
123 return E_POINTER;
125 *ppEnumMoniker = NULL;
127 if (IsEqualGUID(clsidDeviceClass, &CLSID_AudioRendererCategory) ||
128 IsEqualGUID(clsidDeviceClass, &CLSID_MidiRendererCategory))
130 if (FAILED(DEVENUM_CreateSpecialCategories()))
131 return E_FAIL;
133 hbasekey = HKEY_CURRENT_USER;
134 strcpyW(wszRegKey, wszActiveMovieKey);
136 if (!StringFromGUID2(clsidDeviceClass, wszRegKey + strlenW(wszRegKey), MAX_PATH - strlenW(wszRegKey)))
137 return E_OUTOFMEMORY;
139 else
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));
155 return S_FALSE;
158 pEnumMoniker = (EnumMonikerImpl *)CoTaskMemAlloc(sizeof(EnumMonikerImpl));
159 if (!pEnumMoniker)
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;
169 return S_OK;
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()
197 HRESULT res = S_OK;
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.
202 #if 0
203 IMoniker * pMoniker = NULL;
204 WCHAR szAltNameFormat[MAX_PATH + 1];
205 WCHAR szAltName[MAX_PATH + 1];
206 DWORD iDefaultDevice = -1;
207 UINT numDevs;
208 IFilterMapper2 * pMapper = NULL;
209 REGFILTER2 rf2;
210 REGFILTERPINS2 rfp2;
212 rf2.dwVersion = 2;
213 rf2.dwMerit = MERIT_PREFERRED;
214 rf2.u.s1.cPins2 = 1;
215 rf2.u.s1.rgPins2 = &rfp2;
216 rfp2.dwFlags = REG_PINFLAG_B_RENDERER;
217 rfp2.cInstances = 1;
218 rfp2.nMediums = 0;
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
227 if (SUCCEEDED(res))
229 UINT i;
230 WAVEOUTCAPSW wocaps;
231 WAVEINCAPSW wicaps;
232 MIDIOUTCAPSW mocaps;
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))
240 == MMSYSERR_NOERROR)
242 rfp2.nMediaTypes = 1;
243 pTypes = CoTaskMemAlloc(rfp2.nMediaTypes * sizeof(REGPINTYPES));
244 if (!pTypes)
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,
257 &CLSID_AudioRender,
258 wocaps.szPname,
259 &pMoniker,
260 &CLSID_AudioRendererCategory,
261 wocaps.szPname,
262 &rf2);
264 /* FIXME: do additional stuff with IMoniker here, depending on what RegisterFilter does */
266 if (pMoniker)
267 IMoniker_Release(pMoniker);
269 wsprintfW(szAltName, szAltNameFormat, wocaps.szPname);
270 IFilterMapper2_RegisterFilter(pMapper,
271 &CLSID_DSoundRender,
272 szAltName,
273 &pMoniker,
274 &CLSID_AudioRendererCategory,
275 szAltName,
276 &rf2);
278 /* FIXME: do additional stuff with IMoniker here, depending on what RegisterFilter does */
280 if (pMoniker)
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))
297 == MMSYSERR_NOERROR)
299 rfp2.nMediaTypes = 1;
300 pTypes = CoTaskMemAlloc(rfp2.nMediaTypes * sizeof(REGPINTYPES));
301 if (!pTypes)
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,
314 &CLSID_AudioRecord,
315 wicaps.szPname,
316 &pMoniker,
317 &CLSID_AudioInputDeviceCategory,
318 wicaps.szPname,
319 &rf2);
321 /* FIXME: do additional stuff with IMoniker here, depending on what RegisterFilter does */
323 if (pMoniker)
324 IMoniker_Release(pMoniker);
326 CoTaskMemFree(pTypes);
329 numDevs = midiOutGetNumDevs();
331 for (i = 0; i < numDevs; i++)
333 if (midiOutGetDevCapsW(i, &mocaps, sizeof(MIDIOUTCAPSW))
334 == MMSYSERR_NOERROR)
336 rfp2.nMediaTypes = 1;
337 pTypes = CoTaskMemAlloc(rfp2.nMediaTypes * sizeof(REGPINTYPES));
338 if (!pTypes)
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,
352 mocaps.szPname,
353 &pMoniker,
354 &CLSID_MidiRendererCategory,
355 mocaps.szPname,
356 &rf2);
358 /* FIXME: do additional stuff with IMoniker here, depending on what RegisterFilter does */
359 /* Native version sets MidiOutId */
361 if (pMoniker)
362 IMoniker_Release(pMoniker);
364 if (i == iDefaultDevice)
366 FIXME("Default device\n");
369 CoTaskMemFree(pTypes);
374 if (pMapper)
375 IFilterMapper2_Release(pMapper);
376 #endif
377 return res;