winex11: Introduce a function to retrieve the glx drawable and have
[wine.git] / dlls / devenum / mediacatenum.c
blobefe08c19c7d3c369ba1ea5f07101bad060df725d
1 /*
2 * IEnumMoniker 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 * NOTES ON THIS FILE:
21 * - Implements IEnumMoniker interface which enumerates through moniker
22 * objects created from HKEY_CLASSES/CLSID/{DEVICE_CLSID}/Instance
25 #include "devenum_private.h"
26 #include "vfwmsgs.h"
27 #include "oleauto.h"
28 #include "ocidl.h"
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(devenum);
34 static ULONG WINAPI DEVENUM_IEnumMoniker_AddRef(LPENUMMONIKER iface);
35 static ULONG WINAPI DEVENUM_IMediaCatMoniker_AddRef(LPMONIKER iface);
36 static ULONG WINAPI DEVENUM_IPropertyBag_AddRef(LPPROPERTYBAG iface);
38 typedef struct
40 const IPropertyBagVtbl *lpVtbl;
41 LONG ref;
42 HKEY hkey;
43 } RegPropBagImpl;
46 static HRESULT WINAPI DEVENUM_IPropertyBag_QueryInterface(
47 LPPROPERTYBAG iface,
48 REFIID riid,
49 LPVOID *ppvObj)
51 RegPropBagImpl *This = (RegPropBagImpl *)iface;
52 TRACE("\n\tIID:\t%s\n",debugstr_guid(riid));
54 if (This == NULL || ppvObj == NULL) return E_POINTER;
56 if (IsEqualGUID(riid, &IID_IUnknown) ||
57 IsEqualGUID(riid, &IID_IPropertyBag))
59 *ppvObj = (LPVOID)iface;
60 DEVENUM_IPropertyBag_AddRef(iface);
61 return S_OK;
64 FIXME("- no interface\n\tIID:\t%s\n", debugstr_guid(riid));
65 return E_NOINTERFACE;
68 /**********************************************************************
69 * DEVENUM_IPropertyBag_AddRef (also IUnknown)
71 static ULONG WINAPI DEVENUM_IPropertyBag_AddRef(LPPROPERTYBAG iface)
73 RegPropBagImpl *This = (RegPropBagImpl *)iface;
74 TRACE("\n");
76 return InterlockedIncrement(&This->ref);
79 /**********************************************************************
80 * DEVENUM_IPropertyBag_Release (also IUnknown)
82 static ULONG WINAPI DEVENUM_IPropertyBag_Release(LPPROPERTYBAG iface)
84 RegPropBagImpl *This = (RegPropBagImpl *)iface;
85 ULONG ref;
87 TRACE("\n");
89 ref = InterlockedDecrement(&This->ref);
90 if (ref == 0) {
91 RegCloseKey(This->hkey);
92 CoTaskMemFree(This);
93 DEVENUM_UnlockModule();
95 return ref;
98 static HRESULT WINAPI DEVENUM_IPropertyBag_Read(
99 LPPROPERTYBAG iface,
100 LPCOLESTR pszPropName,
101 VARIANT* pVar,
102 IErrorLog* pErrorLog)
104 LPVOID pData = NULL;
105 DWORD received;
106 DWORD type = 0;
107 RegPropBagImpl *This = (RegPropBagImpl *)iface;
108 HRESULT res = S_OK;
109 LONG reswin32;
111 TRACE("(%p)->(%s, %p, %p)\n", This, debugstr_w(pszPropName), pVar, pErrorLog);
113 if (!pszPropName || !pVar)
114 return E_POINTER;
116 reswin32 = RegQueryValueExW(This->hkey, pszPropName, NULL, NULL, NULL, &received);
117 res = HRESULT_FROM_WIN32(reswin32);
119 if (SUCCEEDED(res))
121 pData = HeapAlloc(GetProcessHeap(), 0, received);
123 /* work around a GCC bug that occurs here unless we use the reswin32 variable as well */
124 reswin32 = RegQueryValueExW(This->hkey, pszPropName, NULL, &type, (LPBYTE)pData, &received);
125 res = HRESULT_FROM_WIN32(reswin32);
128 if (SUCCEEDED(res))
130 res = E_INVALIDARG; /* assume we cannot coerce into right type */
132 TRACE("Read %ld bytes (%s)\n", received, type == REG_SZ ? debugstr_w((LPWSTR)pData) : "binary data");
134 switch (type)
136 case REG_SZ:
137 switch (V_VT(pVar))
139 case VT_LPWSTR:
140 V_UNION(pVar, bstrVal) = CoTaskMemAlloc(received);
141 memcpy(V_UNION(pVar, bstrVal), (LPWSTR)pData, received);
142 res = S_OK;
143 break;
144 case VT_EMPTY:
145 V_VT(pVar) = VT_BSTR;
146 /* fall through */
147 case VT_BSTR:
148 V_UNION(pVar, bstrVal) = SysAllocStringLen((LPWSTR)pData, received/sizeof(WCHAR) - 1);
149 res = S_OK;
150 break;
152 break;
153 case REG_DWORD:
154 TRACE("REG_DWORD: %lx\n", *(DWORD *)pData);
155 switch (V_VT(pVar))
157 case VT_EMPTY:
158 V_VT(pVar) = VT_I4;
159 /* fall through */
160 case VT_I4:
161 case VT_UI4:
162 V_UNION(pVar, ulVal) = *(DWORD *)pData;
163 res = S_OK;
164 break;
166 break;
167 case REG_BINARY:
169 SAFEARRAYBOUND bound;
170 void * pArrayElements;
171 bound.lLbound = 0;
172 bound.cElements = received;
173 TRACE("REG_BINARY: len = %ld\n", received);
174 switch (V_VT(pVar))
176 case VT_EMPTY:
177 case VT_ARRAY | VT_UI1:
178 if (!(V_UNION(pVar, parray) = SafeArrayCreate(VT_UI1, 1, &bound)))
179 res = E_OUTOFMEMORY;
180 res = S_OK;
181 break;
184 if (res == E_INVALIDARG)
185 break;
187 res = SafeArrayAccessData(V_UNION(pVar, parray), &pArrayElements);
188 if (FAILED(res))
189 break;
191 CopyMemory(pArrayElements, pData, received);
192 res = SafeArrayUnaccessData(V_UNION(pVar, parray));
193 break;
196 if (res == E_INVALIDARG)
197 FIXME("Variant type %x not supported for regtype %lx\n", V_VT(pVar), type);
200 HeapFree(GetProcessHeap(), 0, pData);
202 TRACE("<- %lx\n", res);
203 return res;
206 static HRESULT WINAPI DEVENUM_IPropertyBag_Write(
207 LPPROPERTYBAG iface,
208 LPCOLESTR pszPropName,
209 VARIANT* pVar)
211 RegPropBagImpl *This = (RegPropBagImpl *)iface;
212 LPVOID lpData = NULL;
213 DWORD cbData = 0;
214 DWORD dwType = 0;
215 HRESULT res = S_OK;
217 TRACE("(%p)->(%s, %p)\n", This, debugstr_w(pszPropName), pVar);
219 switch (V_VT(pVar))
221 case VT_BSTR:
222 TRACE("writing %s\n", debugstr_w(V_UNION(pVar, bstrVal)));
223 lpData = (LPVOID)V_UNION(pVar, bstrVal);
224 dwType = REG_SZ;
225 cbData = (lstrlenW(V_UNION(pVar, bstrVal)) + 1) * sizeof(WCHAR);
226 break;
227 case VT_I4:
228 case VT_UI4:
229 TRACE("writing %lu\n", V_UNION(pVar, ulVal));
230 lpData = (LPVOID)&V_UNION(pVar, ulVal);
231 dwType = REG_DWORD;
232 cbData = sizeof(DWORD);
233 break;
234 case VT_ARRAY | VT_UI1:
236 LONG lUbound = 0;
237 LONG lLbound = 0;
238 dwType = REG_BINARY;
239 res = SafeArrayGetLBound(V_UNION(pVar, parray), 1, &lLbound);
240 res = SafeArrayGetUBound(V_UNION(pVar, parray), 1, &lUbound);
241 cbData = (lUbound - lLbound + 1) /* * sizeof(BYTE)*/;
242 TRACE("cbData: %ld\n", cbData);
243 res = SafeArrayAccessData(V_UNION(pVar, parray), &lpData);
244 break;
246 default:
247 FIXME("Variant type %d not handled\n", V_VT(pVar));
248 return E_FAIL;
251 if (RegSetValueExW(This->hkey,
252 pszPropName, 0,
253 dwType, lpData, cbData) != ERROR_SUCCESS)
254 res = E_FAIL;
256 if (V_VT(pVar) & VT_ARRAY)
257 res = SafeArrayUnaccessData(V_UNION(pVar, parray));
259 return res;
262 static const IPropertyBagVtbl IPropertyBag_Vtbl =
264 DEVENUM_IPropertyBag_QueryInterface,
265 DEVENUM_IPropertyBag_AddRef,
266 DEVENUM_IPropertyBag_Release,
267 DEVENUM_IPropertyBag_Read,
268 DEVENUM_IPropertyBag_Write
271 static HRESULT DEVENUM_IPropertyBag_Construct(HANDLE hkey, IPropertyBag **ppBag)
273 RegPropBagImpl * rpb = CoTaskMemAlloc(sizeof(RegPropBagImpl));
274 if (!rpb)
275 return E_OUTOFMEMORY;
276 rpb->lpVtbl = &IPropertyBag_Vtbl;
277 rpb->ref = 1;
278 rpb->hkey = hkey;
279 *ppBag = (IPropertyBag*)rpb;
280 DEVENUM_LockModule();
281 return S_OK;
285 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_QueryInterface(
286 LPMONIKER iface,
287 REFIID riid,
288 LPVOID *ppvObj)
290 MediaCatMoniker *This = (MediaCatMoniker *)iface;
291 TRACE("\n\tIID:\t%s\n",debugstr_guid(riid));
293 if (This == NULL || ppvObj == NULL) return E_POINTER;
295 *ppvObj = NULL;
297 if (IsEqualGUID(riid, &IID_IUnknown) ||
298 IsEqualGUID(riid, &IID_IPersist) ||
299 IsEqualGUID(riid, &IID_IPersistStream) ||
300 IsEqualGUID(riid, &IID_IMoniker))
302 *ppvObj = (LPVOID)iface;
303 DEVENUM_IMediaCatMoniker_AddRef(iface);
304 return S_OK;
307 FIXME("- no interface\n\tIID:\t%s\n", debugstr_guid(riid));
308 return E_NOINTERFACE;
311 /**********************************************************************
312 * DEVENUM_IMediaCatMoniker_AddRef (also IUnknown)
314 static ULONG WINAPI DEVENUM_IMediaCatMoniker_AddRef(LPMONIKER iface)
316 MediaCatMoniker *This = (MediaCatMoniker *)iface;
317 TRACE("\n");
319 return InterlockedIncrement(&This->ref);
322 /**********************************************************************
323 * DEVENUM_IMediaCatMoniker_Release (also IUnknown)
325 static ULONG WINAPI DEVENUM_IMediaCatMoniker_Release(LPMONIKER iface)
327 MediaCatMoniker *This = (MediaCatMoniker *)iface;
328 ULONG ref;
329 TRACE("\n");
331 ref = InterlockedDecrement(&This->ref);
332 if (ref == 0) {
333 RegCloseKey(This->hkey);
334 CoTaskMemFree(This);
335 DEVENUM_UnlockModule();
337 return ref;
340 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_GetClassID(
341 LPMONIKER iface,
342 CLSID* pClassID)
344 MediaCatMoniker *This = (MediaCatMoniker *)iface;
345 FIXME("(%p)->(%p)\n", This, pClassID);
347 if (pClassID == NULL)
348 return E_POINTER;
350 return E_NOTIMPL;
353 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_IsDirty(LPMONIKER iface)
355 FIXME("()\n");
357 return S_FALSE;
360 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_Load(LPMONIKER iface, IStream* pStm)
362 FIXME("(%p)\n", pStm);
364 return E_NOTIMPL;
367 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_Save(LPMONIKER iface, IStream* pStm, BOOL fClearDirty)
369 FIXME("(%p, %s)\n", pStm, fClearDirty ? "true" : "false");
371 return STG_E_CANTSAVE;
374 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_GetSizeMax(
375 LPMONIKER iface,
376 ULARGE_INTEGER* pcbSize)
378 FIXME("(%p)\n", pcbSize);
380 ZeroMemory(pcbSize, sizeof(*pcbSize));
382 return S_OK;
385 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_BindToObject(
386 LPMONIKER iface,
387 IBindCtx* pbc,
388 IMoniker* pmkToLeft,
389 REFIID riidResult,
390 void** ppvResult)
392 IUnknown * pObj = NULL;
393 IPropertyBag * pProp = NULL;
394 CLSID clsID;
395 VARIANT var;
396 HRESULT res = E_FAIL;
398 MediaCatMoniker *This = (MediaCatMoniker *)iface;
400 VariantClear(&var);
402 TRACE("(%p)->(%p, %p, %s, %p)\n", This, pbc, pmkToLeft, debugstr_guid(riidResult), ppvResult);
404 *ppvResult = NULL;
406 if(pmkToLeft==NULL)
408 /* first activation of this class */
409 LPVOID pvptr;
410 res=IMoniker_BindToStorage(iface, NULL, NULL, &IID_IPropertyBag, &pvptr);
411 pProp = (IPropertyBag*)pvptr;
412 if (SUCCEEDED(res))
414 V_VT(&var) = VT_LPWSTR;
415 res = IPropertyBag_Read(pProp, clsid_keyname, &var, NULL);
417 if (SUCCEEDED(res))
419 res = CLSIDFromString(V_UNION(&var,bstrVal), &clsID);
420 CoTaskMemFree(V_UNION(&var, bstrVal));
422 if (SUCCEEDED(res))
424 res=CoCreateInstance(&clsID,NULL,CLSCTX_ALL,&IID_IUnknown,&pvptr);
425 pObj = (IUnknown*)pvptr;
429 if (pObj!=NULL)
431 /* get the requested interface from the loaded class */
432 res = S_OK;
433 if (pProp) {
434 HRESULT res2;
435 LPVOID ppv = NULL;
436 res2 = IUnknown_QueryInterface(pObj, &IID_IPersistPropertyBag, &ppv);
437 if (SUCCEEDED(res2)) {
438 res = IPersistPropertyBag_Load((IPersistPropertyBag *) ppv, pProp, NULL);
439 IPersistPropertyBag_Release((IPersistPropertyBag *) ppv);
442 if (SUCCEEDED(res))
443 res= IUnknown_QueryInterface(pObj,riidResult,ppvResult);
444 IUnknown_Release(pObj);
447 if (pProp)
449 IPropertyBag_Release(pProp);
452 TRACE("<- 0x%lx\n", res);
454 return res;
457 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_BindToStorage(
458 LPMONIKER iface,
459 IBindCtx* pbc,
460 IMoniker* pmkToLeft,
461 REFIID riid,
462 void** ppvObj)
464 MediaCatMoniker *This = (MediaCatMoniker *)iface;
465 TRACE("(%p)->(%p, %p, %s, %p)\n", This, pbc, pmkToLeft, debugstr_guid(riid), ppvObj);
467 *ppvObj = NULL;
469 if (pbc || pmkToLeft)
470 return MK_E_NOSTORAGE;
472 if (IsEqualGUID(riid, &IID_IPropertyBag))
474 HANDLE hkey;
475 DuplicateHandle(GetCurrentProcess(), This->hkey, GetCurrentProcess(), &hkey, 0, 0, DUPLICATE_SAME_ACCESS);
476 return DEVENUM_IPropertyBag_Construct(hkey, (IPropertyBag**)ppvObj);
479 return MK_E_NOSTORAGE;
482 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_Reduce(
483 LPMONIKER iface,
484 IBindCtx* pbc,
485 DWORD dwReduceHowFar,
486 IMoniker** ppmkToLeft,
487 IMoniker** ppmkReduced)
489 TRACE("(%p, %ld, %p, %p)\n", pbc, dwReduceHowFar, ppmkToLeft, ppmkReduced);
491 if (ppmkToLeft)
492 *ppmkToLeft = NULL;
493 *ppmkReduced = iface;
495 return MK_S_REDUCED_TO_SELF;
498 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_ComposeWith(
499 LPMONIKER iface,
500 IMoniker* pmkRight,
501 BOOL fOnlyIfNotGeneric,
502 IMoniker** ppmkComposite)
504 FIXME("(%p, %s, %p): stub\n", pmkRight, fOnlyIfNotGeneric ? "true" : "false", ppmkComposite);
506 /* FIXME: use CreateGenericComposite? */
507 *ppmkComposite = NULL;
509 return E_NOTIMPL;
512 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_Enum(
513 LPMONIKER iface,
514 BOOL fForward,
515 IEnumMoniker** ppenumMoniker)
517 FIXME("(%s, %p): stub\n", fForward ? "true" : "false", ppenumMoniker);
519 *ppenumMoniker = NULL;
521 return S_OK;
524 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_IsEqual(
525 LPMONIKER iface,
526 IMoniker* pmkOtherMoniker)
528 FIXME("(%p)\n", pmkOtherMoniker);
530 return E_NOTIMPL;
533 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_Hash(
534 LPMONIKER iface,
535 DWORD* pdwHash)
537 TRACE("(%p)\n", pdwHash);
539 *pdwHash = 0;
541 return S_OK;
544 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_IsRunning(
545 LPMONIKER iface,
546 IBindCtx* pbc,
547 IMoniker* pmkToLeft,
548 IMoniker* pmkNewlyRunning)
550 FIXME("(%p, %p, %p)\n", pbc, pmkToLeft, pmkNewlyRunning);
552 return S_FALSE;
555 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_GetTimeOfLastChange(
556 LPMONIKER iface,
557 IBindCtx* pbc,
558 IMoniker* pmkToLeft,
559 FILETIME* pFileTime)
561 TRACE("(%p, %p, %p)\n", pbc, pmkToLeft, pFileTime);
563 pFileTime->dwLowDateTime = 0xFFFFFFFF;
564 pFileTime->dwHighDateTime = 0x7FFFFFFF;
566 return MK_E_UNAVAILABLE;
569 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_Inverse(
570 LPMONIKER iface,
571 IMoniker** ppmk)
573 TRACE("(%p)\n", ppmk);
575 *ppmk = NULL;
577 return MK_E_NOINVERSE;
580 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_CommonPrefixWith(
581 LPMONIKER iface,
582 IMoniker* pmkOtherMoniker,
583 IMoniker** ppmkPrefix)
585 TRACE("(%p, %p)\n", pmkOtherMoniker, ppmkPrefix);
587 *ppmkPrefix = NULL;
589 return MK_E_NOPREFIX;
592 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_RelativePathTo(
593 LPMONIKER iface,
594 IMoniker* pmkOther,
595 IMoniker** ppmkRelPath)
597 TRACE("(%p, %p)\n", pmkOther, ppmkRelPath);
599 *ppmkRelPath = pmkOther;
601 return MK_S_HIM;
604 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_GetDisplayName(
605 LPMONIKER iface,
606 IBindCtx* pbc,
607 IMoniker* pmkToLeft,
608 LPOLESTR* ppszDisplayName)
610 MediaCatMoniker *This = (MediaCatMoniker *)iface;
611 WCHAR wszBuffer[MAX_PATH];
612 static const WCHAR wszFriendlyName[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
613 LONG received = sizeof(wszFriendlyName);
615 TRACE("(%p, %p, %p)\n", pbc, pmkToLeft, ppszDisplayName);
617 *ppszDisplayName = NULL;
619 /* FIXME: should this be the weird stuff we have to parse in IParseDisplayName? */
620 if (RegQueryValueW(This->hkey, wszFriendlyName, wszBuffer, &received) == ERROR_SUCCESS)
622 *ppszDisplayName = CoTaskMemAlloc(received);
623 strcpyW(*ppszDisplayName, wszBuffer);
624 return S_OK;
627 return E_FAIL;
630 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_ParseDisplayName(
631 LPMONIKER iface,
632 IBindCtx* pbc,
633 IMoniker* pmkToLeft,
634 LPOLESTR pszDisplayName,
635 ULONG* pchEaten,
636 IMoniker** ppmkOut)
638 FIXME("(%p, %p, %s, %p, %p)\n", pbc, pmkToLeft, debugstr_w(pszDisplayName), pchEaten, ppmkOut);
640 *pchEaten = 0;
641 *ppmkOut = NULL;
643 return MK_E_SYNTAX;
646 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_IsSystemMoniker(
647 LPMONIKER iface,
648 DWORD* pdwMksys)
650 TRACE("(%p)\n", pdwMksys);
652 return S_FALSE;
655 static const IMonikerVtbl IMoniker_Vtbl =
657 DEVENUM_IMediaCatMoniker_QueryInterface,
658 DEVENUM_IMediaCatMoniker_AddRef,
659 DEVENUM_IMediaCatMoniker_Release,
660 DEVENUM_IMediaCatMoniker_GetClassID,
661 DEVENUM_IMediaCatMoniker_IsDirty,
662 DEVENUM_IMediaCatMoniker_Load,
663 DEVENUM_IMediaCatMoniker_Save,
664 DEVENUM_IMediaCatMoniker_GetSizeMax,
665 DEVENUM_IMediaCatMoniker_BindToObject,
666 DEVENUM_IMediaCatMoniker_BindToStorage,
667 DEVENUM_IMediaCatMoniker_Reduce,
668 DEVENUM_IMediaCatMoniker_ComposeWith,
669 DEVENUM_IMediaCatMoniker_Enum,
670 DEVENUM_IMediaCatMoniker_IsEqual,
671 DEVENUM_IMediaCatMoniker_Hash,
672 DEVENUM_IMediaCatMoniker_IsRunning,
673 DEVENUM_IMediaCatMoniker_GetTimeOfLastChange,
674 DEVENUM_IMediaCatMoniker_Inverse,
675 DEVENUM_IMediaCatMoniker_CommonPrefixWith,
676 DEVENUM_IMediaCatMoniker_RelativePathTo,
677 DEVENUM_IMediaCatMoniker_GetDisplayName,
678 DEVENUM_IMediaCatMoniker_ParseDisplayName,
679 DEVENUM_IMediaCatMoniker_IsSystemMoniker
682 MediaCatMoniker * DEVENUM_IMediaCatMoniker_Construct()
684 MediaCatMoniker * pMoniker = NULL;
685 pMoniker = CoTaskMemAlloc(sizeof(MediaCatMoniker));
686 if (!pMoniker)
687 return NULL;
689 pMoniker->lpVtbl = &IMoniker_Vtbl;
690 pMoniker->ref = 0;
691 pMoniker->hkey = NULL;
693 DEVENUM_IMediaCatMoniker_AddRef((LPMONIKER)pMoniker);
695 DEVENUM_LockModule();
697 return pMoniker;
700 /**********************************************************************
701 * DEVENUM_IEnumMoniker_QueryInterface (also IUnknown)
703 static HRESULT WINAPI DEVENUM_IEnumMoniker_QueryInterface(
704 LPENUMMONIKER iface,
705 REFIID riid,
706 LPVOID *ppvObj)
708 EnumMonikerImpl *This = (EnumMonikerImpl *)iface;
709 TRACE("\n\tIID:\t%s\n",debugstr_guid(riid));
711 if (This == NULL || ppvObj == NULL) return E_POINTER;
713 if (IsEqualGUID(riid, &IID_IUnknown) ||
714 IsEqualGUID(riid, &IID_IEnumMoniker))
716 *ppvObj = (LPVOID)iface;
717 DEVENUM_IEnumMoniker_AddRef(iface);
718 return S_OK;
721 FIXME("- no interface\n\tIID:\t%s\n", debugstr_guid(riid));
722 return E_NOINTERFACE;
725 /**********************************************************************
726 * DEVENUM_IEnumMoniker_AddRef (also IUnknown)
728 static ULONG WINAPI DEVENUM_IEnumMoniker_AddRef(LPENUMMONIKER iface)
730 EnumMonikerImpl *This = (EnumMonikerImpl *)iface;
731 ULONG ref = InterlockedIncrement(&This->ref);
733 TRACE("(%p)->() AddRef from %ld\n", iface, ref - 1);
735 return ref;
738 /**********************************************************************
739 * DEVENUM_IEnumMoniker_Release (also IUnknown)
741 static ULONG WINAPI DEVENUM_IEnumMoniker_Release(LPENUMMONIKER iface)
743 EnumMonikerImpl *This = (EnumMonikerImpl *)iface;
744 ULONG ref = InterlockedDecrement(&This->ref);
746 TRACE("(%p)->() Release from %ld\n", iface, ref + 1);
748 if (!ref)
750 RegCloseKey(This->hkey);
751 CoTaskMemFree(This);
752 DEVENUM_UnlockModule();
753 return 0;
755 return ref;
758 static HRESULT WINAPI DEVENUM_IEnumMoniker_Next(LPENUMMONIKER iface, ULONG celt, IMoniker ** rgelt, ULONG * pceltFetched)
760 WCHAR buffer[MAX_PATH + 1];
761 LONG res;
762 ULONG fetched = 0;
763 MediaCatMoniker * pMoniker;
764 EnumMonikerImpl *This = (EnumMonikerImpl *)iface;
766 TRACE("(%p)->(%ld, %p, %p)\n", iface, celt, rgelt, pceltFetched);
768 while (fetched < celt)
770 res = RegEnumKeyW(This->hkey, This->index, buffer, sizeof(buffer) / sizeof(WCHAR));
771 if (res != ERROR_SUCCESS)
773 break;
775 pMoniker = DEVENUM_IMediaCatMoniker_Construct();
776 if (!pMoniker)
777 return E_OUTOFMEMORY;
779 if (RegOpenKeyW(This->hkey, buffer, &pMoniker->hkey) != ERROR_SUCCESS)
781 DEVENUM_IMediaCatMoniker_Release((LPMONIKER)pMoniker);
782 break;
784 rgelt[fetched] = (LPMONIKER)pMoniker;
785 fetched++;
788 This->index += fetched;
790 TRACE("-- fetched %ld\n", fetched);
792 if (pceltFetched)
793 *pceltFetched = fetched;
795 if (fetched != celt)
796 return S_FALSE;
797 else
798 return S_OK;
801 static HRESULT WINAPI DEVENUM_IEnumMoniker_Skip(LPENUMMONIKER iface, ULONG celt)
803 EnumMonikerImpl *This = (EnumMonikerImpl *)iface;
805 TRACE("(%p)->(%ld)\n", iface, celt);
807 This->index += celt;
809 return S_OK;
812 static HRESULT WINAPI DEVENUM_IEnumMoniker_Reset(LPENUMMONIKER iface)
814 EnumMonikerImpl *This = (EnumMonikerImpl *)iface;
816 TRACE("(%p)->()\n", iface);
818 This->index = 0;
820 return S_OK;
823 static HRESULT WINAPI DEVENUM_IEnumMoniker_Clone(LPENUMMONIKER iface, IEnumMoniker ** ppenum)
825 FIXME("(%p)->(%p): stub\n", iface, ppenum);
827 return E_NOTIMPL;
830 /**********************************************************************
831 * IEnumMoniker_Vtbl
833 static const IEnumMonikerVtbl IEnumMoniker_Vtbl =
835 DEVENUM_IEnumMoniker_QueryInterface,
836 DEVENUM_IEnumMoniker_AddRef,
837 DEVENUM_IEnumMoniker_Release,
838 DEVENUM_IEnumMoniker_Next,
839 DEVENUM_IEnumMoniker_Skip,
840 DEVENUM_IEnumMoniker_Reset,
841 DEVENUM_IEnumMoniker_Clone
844 HRESULT DEVENUM_IEnumMoniker_Construct(HKEY hkey, IEnumMoniker ** ppEnumMoniker)
846 EnumMonikerImpl * pEnumMoniker = CoTaskMemAlloc(sizeof(EnumMonikerImpl));
847 if (!pEnumMoniker)
848 return E_OUTOFMEMORY;
850 pEnumMoniker->lpVtbl = &IEnumMoniker_Vtbl;
851 pEnumMoniker->ref = 1;
852 pEnumMoniker->index = 0;
853 pEnumMoniker->hkey = hkey;
855 *ppEnumMoniker = (IEnumMoniker *)pEnumMoniker;
857 DEVENUM_LockModule();
859 return S_OK;