A couple of optimizations to avoid some server calls in WIN_FindWndPtr
[wine/multimedia.git] / dlls / quartz / idevenum.c
blob5c644bebb14765d36db0559acb2ab363b5f0c6b7
1 /*
2 * Implementation of ICreateDevEnum for CLSID_SystemDeviceEnum.
4 * FIXME - stub.
6 * hidenori@a2.ctktv.ne.jp
7 */
9 #include "config.h"
11 #include "windef.h"
12 #include "winbase.h"
13 #include "wingdi.h"
14 #include "winuser.h"
15 #include "winreg.h"
16 #include "winerror.h"
17 #include "wine/obj_base.h"
18 #include "objidl.h"
19 #include "oleidl.h"
20 #include "ocidl.h"
21 #include "strmif.h"
22 #include "control.h"
23 #include "uuids.h"
24 #include "wine/unicode.h"
26 #include "debugtools.h"
27 DEFAULT_DEBUG_CHANNEL(quartz);
29 #include "quartz_private.h"
30 #include "devenum.h"
31 #include "regsvr.h"
32 #include "enumunk.h"
33 #include "complist.h"
34 #include "devmon.h"
37 static HRESULT WINAPI
38 ICreateDevEnum_fnQueryInterface(ICreateDevEnum* iface,REFIID riid,void** ppobj)
40 CSysDevEnum_THIS(iface,createdevenum);
42 TRACE("(%p)->()\n",This);
44 return IUnknown_QueryInterface(This->unk.punkControl,riid,ppobj);
47 static ULONG WINAPI
48 ICreateDevEnum_fnAddRef(ICreateDevEnum* iface)
50 CSysDevEnum_THIS(iface,createdevenum);
52 TRACE("(%p)->()\n",This);
54 return IUnknown_AddRef(This->unk.punkControl);
57 static ULONG WINAPI
58 ICreateDevEnum_fnRelease(ICreateDevEnum* iface)
60 CSysDevEnum_THIS(iface,createdevenum);
62 TRACE("(%p)->()\n",This);
64 return IUnknown_Release(This->unk.punkControl);
67 static HRESULT WINAPI
68 ICreateDevEnum_fnCreateClassEnumerator(ICreateDevEnum* iface,REFCLSID rclsidDeviceClass,IEnumMoniker** ppobj, DWORD dwFlags)
70 CSysDevEnum_THIS(iface,createdevenum);
71 HRESULT hr;
72 HKEY hKey;
73 QUARTZ_CompList* pMonList;
74 IMoniker* pMon;
75 DWORD dwIndex;
76 LONG lr;
77 WCHAR wszPath[ 1024 ];
78 DWORD dwLen;
79 DWORD dwNameMax;
80 DWORD cbName;
81 FILETIME ftLastWrite;
83 TRACE("(%p)->(%s,%p,%08lx)\n",This,
84 debugstr_guid(rclsidDeviceClass),ppobj,dwFlags);
85 if ( dwFlags != 0 )
87 FIXME("unknown flags %08lx\n",dwFlags);
88 return E_NOTIMPL;
91 if ( ppobj == NULL )
92 return E_POINTER;
93 *ppobj = NULL;
95 hr = QUARTZ_CreateCLSIDPath(
96 wszPath, sizeof(wszPath)/sizeof(wszPath[0]),
97 rclsidDeviceClass, QUARTZ_wszInstance );
98 if ( FAILED(hr) )
99 return hr;
101 if ( RegOpenKeyExW( HKEY_CLASSES_ROOT, wszPath,
102 0, KEY_READ, &hKey ) != ERROR_SUCCESS )
103 return E_FAIL;
105 dwLen = strlenW(wszPath);
106 wszPath[dwLen++] = '\\'; wszPath[dwLen] = 0;
107 dwNameMax = sizeof(wszPath)/sizeof(wszPath[0]) - dwLen - 8;
109 pMonList = QUARTZ_CompList_Alloc();
110 if ( pMonList == NULL )
112 hr = E_OUTOFMEMORY;
113 goto err;
116 /* enumerate all subkeys. */
117 dwIndex = 0;
118 while ( 1 )
120 cbName = dwNameMax;
121 lr = RegEnumKeyExW(
122 hKey, dwIndex, &wszPath[dwLen], &cbName,
123 NULL, NULL, NULL, &ftLastWrite );
124 if ( lr == ERROR_NO_MORE_ITEMS )
125 break;
126 if ( lr != ERROR_SUCCESS )
128 hr = E_FAIL;
129 goto err;
132 hr = QUARTZ_CreateDeviceMoniker(
133 HKEY_CLASSES_ROOT, wszPath, &pMon );
134 if ( FAILED(hr) )
135 goto err;
137 hr = QUARTZ_CompList_AddComp(
138 pMonList, (IUnknown*)pMon, NULL, 0 );
139 IMoniker_Release( pMon );
141 if ( FAILED(hr) )
142 goto err;
144 dwIndex ++;
147 /* create an enumerator. */
148 hr = QUARTZ_CreateEnumUnknown(
149 &IID_IEnumMoniker, (void**)ppobj, pMonList );
150 if ( FAILED(hr) )
151 goto err;
153 hr = S_OK;
154 err:
155 if ( pMonList != NULL )
156 QUARTZ_CompList_Free( pMonList );
157 RegCloseKey( hKey );
159 return hr;
162 static ICOM_VTABLE(ICreateDevEnum) icreatedevenum =
164 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
165 /* IUnknown fields */
166 ICreateDevEnum_fnQueryInterface,
167 ICreateDevEnum_fnAddRef,
168 ICreateDevEnum_fnRelease,
169 /* ICreateDevEnum fields */
170 ICreateDevEnum_fnCreateClassEnumerator,
173 HRESULT CSysDevEnum_InitICreateDevEnum( CSysDevEnum* psde )
175 TRACE("(%p)\n",psde);
176 ICOM_VTBL(&psde->createdevenum) = &icreatedevenum;
178 return NOERROR;
181 void CSysDevEnum_UninitICreateDevEnum( CSysDevEnum* psde )
183 TRACE("(%p)\n",psde);