Change messages about config file to registry.
[wine/multimedia.git] / dlls / devenum / mediacatenum.c
blobddd8401fa4e94b2590c44846935f6d4b17c328ad
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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"
33 /* #define ICOM_THIS_From_IROTData(class, name) class* This = (class*)(((char*)name)-sizeof(void*)) */
35 WINE_DEFAULT_DEBUG_CHANNEL(devenum);
37 static ULONG WINAPI DEVENUM_IEnumMoniker_AddRef(LPENUMMONIKER iface);
38 static ULONG WINAPI DEVENUM_IMediaCatMoniker_AddRef(LPMONIKER iface);
39 static ULONG WINAPI DEVENUM_IPropertyBag_AddRef(LPPROPERTYBAG iface);
41 typedef struct
43 const IPropertyBagVtbl *lpVtbl;
44 DWORD ref;
45 HKEY hkey;
46 } RegPropBagImpl;
49 static HRESULT WINAPI DEVENUM_IPropertyBag_QueryInterface(
50 LPPROPERTYBAG iface,
51 REFIID riid,
52 LPVOID *ppvObj)
54 RegPropBagImpl *This = (RegPropBagImpl *)iface;
55 TRACE("\n\tIID:\t%s\n",debugstr_guid(riid));
57 if (This == NULL || ppvObj == NULL) return E_POINTER;
59 if (IsEqualGUID(riid, &IID_IUnknown) ||
60 IsEqualGUID(riid, &IID_IPropertyBag))
62 *ppvObj = (LPVOID)iface;
63 DEVENUM_IPropertyBag_AddRef(iface);
64 return S_OK;
67 FIXME("- no interface\n\tIID:\t%s\n", debugstr_guid(riid));
68 return E_NOINTERFACE;
71 /**********************************************************************
72 * DEVENUM_IPropertyBag_AddRef (also IUnknown)
74 static ULONG WINAPI DEVENUM_IPropertyBag_AddRef(LPPROPERTYBAG iface)
76 RegPropBagImpl *This = (RegPropBagImpl *)iface;
77 TRACE("\n");
79 return InterlockedIncrement(&This->ref);
82 /**********************************************************************
83 * DEVENUM_IPropertyBag_Release (also IUnknown)
85 static ULONG WINAPI DEVENUM_IPropertyBag_Release(LPPROPERTYBAG iface)
87 RegPropBagImpl *This = (RegPropBagImpl *)iface;
88 ULONG ref;
90 TRACE("\n");
92 ref = InterlockedDecrement(&This->ref);
93 if (ref == 0) {
94 RegCloseKey(This->hkey);
95 CoTaskMemFree(This);
96 DEVENUM_UnlockModule();
98 return ref;
101 static HRESULT WINAPI DEVENUM_IPropertyBag_Read(
102 LPPROPERTYBAG iface,
103 LPCOLESTR pszPropName,
104 VARIANT* pVar,
105 IErrorLog* pErrorLog)
107 LPVOID pData = NULL;
108 LONG received;
109 DWORD type = 0;
110 RegPropBagImpl *This = (RegPropBagImpl *)iface;
111 HRESULT res = S_OK;
112 LONG reswin32;
114 TRACE("(%p)->(%s, %p, %p)\n", This, debugstr_w(pszPropName), pVar, pErrorLog);
116 if (!pszPropName || !pVar)
117 return E_POINTER;
119 reswin32 = RegQueryValueExW(This->hkey, pszPropName, NULL, NULL, NULL, &received);
120 res = HRESULT_FROM_WIN32(reswin32);
122 if (SUCCEEDED(res))
124 pData = HeapAlloc(GetProcessHeap(), 0, received);
126 /* work around a GCC bug that occurs here unless we use the reswin32 variable as well */
127 reswin32 = RegQueryValueExW(This->hkey, pszPropName, NULL, &type, pData, &received);
128 res = HRESULT_FROM_WIN32(reswin32);
131 if (SUCCEEDED(res))
133 res = E_INVALIDARG; /* assume we cannot coerce into right type */
135 TRACE("Read %ld bytes (%s)\n", received, type == REG_SZ ? debugstr_w((LPWSTR)pData) : "binary data");
137 switch (type)
139 case REG_SZ:
140 switch (V_VT(pVar))
142 case VT_LPWSTR:
143 V_UNION(pVar, bstrVal) = CoTaskMemAlloc(received);
144 memcpy(V_UNION(pVar, bstrVal), (LPWSTR)pData, received);
145 res = S_OK;
146 break;
147 case VT_EMPTY:
148 V_VT(pVar) = VT_BSTR;
149 /* fall through */
150 case VT_BSTR:
151 V_UNION(pVar, bstrVal) = SysAllocStringLen((LPWSTR)pData, received/sizeof(WCHAR) - 1);
152 res = S_OK;
153 break;
155 break;
156 case REG_DWORD:
157 TRACE("REG_DWORD: %lx\n", *(DWORD *)pData);
158 switch (V_VT(pVar))
160 case VT_EMPTY:
161 V_VT(pVar) = VT_I4;
162 /* fall through */
163 case VT_I4:
164 case VT_UI4:
165 V_UNION(pVar, ulVal) = *(DWORD *)pData;
166 res = S_OK;
167 break;
169 break;
170 case REG_BINARY:
172 SAFEARRAYBOUND bound;
173 void * pArrayElements;
174 bound.lLbound = 0;
175 bound.cElements = received;
176 TRACE("REG_BINARY: len = %ld\n", received);
177 switch (V_VT(pVar))
179 case VT_EMPTY:
180 case VT_ARRAY | VT_UI1:
181 if (!(V_UNION(pVar, parray) = SafeArrayCreate(VT_UI1, 1, &bound)))
182 res = E_OUTOFMEMORY;
183 res = S_OK;
184 break;
187 if (res == E_INVALIDARG)
188 break;
190 res = SafeArrayAccessData(V_UNION(pVar, parray), &pArrayElements);
191 if (FAILED(res))
192 break;
194 CopyMemory(pArrayElements, pData, received);
195 res = SafeArrayUnaccessData(V_UNION(pVar, parray));
196 break;
199 if (res == E_INVALIDARG)
200 FIXME("Variant type %x not supported for regtype %lx\n", V_VT(pVar), type);
203 HeapFree(GetProcessHeap(), 0, pData);
205 TRACE("<- %lx\n", res);
206 return res;
209 static HRESULT WINAPI DEVENUM_IPropertyBag_Write(
210 LPPROPERTYBAG iface,
211 LPCOLESTR pszPropName,
212 VARIANT* pVar)
214 RegPropBagImpl *This = (RegPropBagImpl *)iface;
215 LPVOID lpData = NULL;
216 DWORD cbData = 0;
217 DWORD dwType = 0;
218 HRESULT res = S_OK;
220 TRACE("(%p)->(%s, %p)\n", This, debugstr_w(pszPropName), pVar);
222 switch (V_VT(pVar))
224 case VT_BSTR:
225 TRACE("writing %s\n", debugstr_w(V_UNION(pVar, bstrVal)));
226 lpData = (LPVOID)V_UNION(pVar, bstrVal);
227 dwType = REG_SZ;
228 cbData = (lstrlenW(V_UNION(pVar, bstrVal)) + 1) * sizeof(WCHAR);
229 break;
230 case VT_I4:
231 case VT_UI4:
232 TRACE("writing %lu\n", V_UNION(pVar, ulVal));
233 lpData = (LPVOID)&V_UNION(pVar, ulVal);
234 dwType = REG_DWORD;
235 cbData = sizeof(DWORD);
236 break;
237 case VT_ARRAY | VT_UI1:
239 LONG lUbound = 0;
240 LONG lLbound = 0;
241 dwType = REG_BINARY;
242 res = SafeArrayGetLBound(V_UNION(pVar, parray), 1, &lLbound);
243 res = SafeArrayGetUBound(V_UNION(pVar, parray), 1, &lUbound);
244 cbData = (lUbound - lLbound + 1) /* * sizeof(BYTE)*/;
245 TRACE("cbData: %ld\n", cbData);
246 res = SafeArrayAccessData(V_UNION(pVar, parray), &lpData);
247 break;
249 default:
250 FIXME("Variant type %d not handled\n", V_VT(pVar));
251 return E_FAIL;
254 if (RegSetValueExW(This->hkey,
255 pszPropName, 0,
256 dwType, lpData, cbData) != ERROR_SUCCESS)
257 res = E_FAIL;
259 if (V_VT(pVar) & VT_ARRAY)
260 res = SafeArrayUnaccessData(V_UNION(pVar, parray));
262 return res;
265 static const IPropertyBagVtbl IPropertyBag_Vtbl =
267 DEVENUM_IPropertyBag_QueryInterface,
268 DEVENUM_IPropertyBag_AddRef,
269 DEVENUM_IPropertyBag_Release,
270 DEVENUM_IPropertyBag_Read,
271 DEVENUM_IPropertyBag_Write
274 static HRESULT DEVENUM_IPropertyBag_Construct(HANDLE hkey, IPropertyBag **ppBag)
276 RegPropBagImpl * rpb = CoTaskMemAlloc(sizeof(RegPropBagImpl));
277 if (!rpb)
278 return E_OUTOFMEMORY;
279 rpb->lpVtbl = &IPropertyBag_Vtbl;
280 rpb->ref = 1;
281 rpb->hkey = hkey;
282 *ppBag = (IPropertyBag*)rpb;
283 DEVENUM_LockModule();
284 return S_OK;
288 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_QueryInterface(
289 LPMONIKER iface,
290 REFIID riid,
291 LPVOID *ppvObj)
293 MediaCatMoniker *This = (MediaCatMoniker *)iface;
294 TRACE("\n\tIID:\t%s\n",debugstr_guid(riid));
296 if (This == NULL || ppvObj == NULL) return E_POINTER;
298 *ppvObj = NULL;
300 if (IsEqualGUID(riid, &IID_IUnknown) ||
301 IsEqualGUID(riid, &IID_IPersist) ||
302 IsEqualGUID(riid, &IID_IPersistStream) ||
303 IsEqualGUID(riid, &IID_IMoniker))
305 *ppvObj = (LPVOID)iface;
306 DEVENUM_IMediaCatMoniker_AddRef(iface);
307 return S_OK;
310 FIXME("- no interface\n\tIID:\t%s\n", debugstr_guid(riid));
311 return E_NOINTERFACE;
314 /**********************************************************************
315 * DEVENUM_IMediaCatMoniker_AddRef (also IUnknown)
317 static ULONG WINAPI DEVENUM_IMediaCatMoniker_AddRef(LPMONIKER iface)
319 MediaCatMoniker *This = (MediaCatMoniker *)iface;
320 TRACE("\n");
322 return InterlockedIncrement(&This->ref);
325 /**********************************************************************
326 * DEVENUM_IMediaCatMoniker_Release (also IUnknown)
328 static ULONG WINAPI DEVENUM_IMediaCatMoniker_Release(LPMONIKER iface)
330 MediaCatMoniker *This = (MediaCatMoniker *)iface;
331 ULONG ref;
332 TRACE("\n");
334 ref = InterlockedDecrement(&This->ref);
335 if (ref == 0) {
336 RegCloseKey(This->hkey);
337 CoTaskMemFree(This);
338 DEVENUM_UnlockModule();
340 return ref;
343 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_GetClassID(
344 LPMONIKER iface,
345 CLSID* pClassID)
347 MediaCatMoniker *This = (MediaCatMoniker *)iface;
348 FIXME("(%p)->(%p)\n", This, pClassID);
350 if (pClassID == NULL)
351 return E_POINTER;
353 return E_NOTIMPL;
356 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_IsDirty(LPMONIKER iface)
358 FIXME("()\n");
360 return S_FALSE;
363 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_Load(LPMONIKER iface, IStream* pStm)
365 FIXME("(%p)\n", pStm);
367 return E_NOTIMPL;
370 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_Save(LPMONIKER iface, IStream* pStm, BOOL fClearDirty)
372 FIXME("(%p, %s)\n", pStm, fClearDirty ? "true" : "false");
374 return STG_E_CANTSAVE;
377 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_GetSizeMax(
378 LPMONIKER iface,
379 ULARGE_INTEGER* pcbSize)
381 FIXME("(%p)\n", pcbSize);
383 ZeroMemory(pcbSize, sizeof(*pcbSize));
385 return S_OK;
388 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_BindToObject(
389 LPMONIKER iface,
390 IBindCtx* pbc,
391 IMoniker* pmkToLeft,
392 REFIID riidResult,
393 void** ppvResult)
395 IUnknown * pObj = NULL;
396 IPropertyBag * pProp = NULL;
397 CLSID clsID;
398 VARIANT var;
399 HRESULT res = E_FAIL;
401 MediaCatMoniker *This = (MediaCatMoniker *)iface;
403 VariantClear(&var);
405 TRACE("(%p)->(%p, %p, %s, %p)\n", This, pbc, pmkToLeft, debugstr_guid(riidResult), ppvResult);
407 *ppvResult = NULL;
409 if(pmkToLeft==NULL)
411 /* first activation of this class */
412 LPVOID pvptr;
413 res=IMoniker_BindToStorage(iface, NULL, NULL, &IID_IPropertyBag, &pvptr);
414 pProp = (IPropertyBag*)pvptr;
415 if (SUCCEEDED(res))
417 V_VT(&var) = VT_LPWSTR;
418 res = IPropertyBag_Read(pProp, clsid_keyname, &var, NULL);
420 if (SUCCEEDED(res))
422 res = CLSIDFromString(V_UNION(&var,bstrVal), &clsID);
423 CoTaskMemFree(V_UNION(&var, bstrVal));
425 if (SUCCEEDED(res))
427 res=CoCreateInstance(&clsID,NULL,CLSCTX_ALL,&IID_IUnknown,&pvptr);
428 pObj = (IUnknown*)pvptr;
432 if (pObj!=NULL)
434 /* get the requested interface from the loaded class */
435 res = S_OK;
436 if (pProp) {
437 HRESULT res2;
438 LPVOID ppv = NULL;
439 res2 = IUnknown_QueryInterface(pObj, &IID_IPersistPropertyBag, &ppv);
440 if (SUCCEEDED(res2)) {
441 res = IPersistPropertyBag_Load((IPersistPropertyBag *) ppv, pProp, NULL);
442 IPersistPropertyBag_Release((IPersistPropertyBag *) ppv);
445 if (SUCCEEDED(res))
446 res= IUnknown_QueryInterface(pObj,riidResult,ppvResult);
447 IUnknown_Release(pObj);
450 if (pProp)
452 IPropertyBag_Release(pProp);
455 TRACE("<- 0x%lx\n", res);
457 return res;
460 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_BindToStorage(
461 LPMONIKER iface,
462 IBindCtx* pbc,
463 IMoniker* pmkToLeft,
464 REFIID riid,
465 void** ppvObj)
467 MediaCatMoniker *This = (MediaCatMoniker *)iface;
468 TRACE("(%p)->(%p, %p, %s, %p)\n", This, pbc, pmkToLeft, debugstr_guid(riid), ppvObj);
470 *ppvObj = NULL;
472 if (pbc || pmkToLeft)
473 return MK_E_NOSTORAGE;
475 if (IsEqualGUID(riid, &IID_IPropertyBag))
477 HANDLE hkey;
478 DuplicateHandle(GetCurrentProcess(), This->hkey, GetCurrentProcess(), &hkey, 0, 0, DUPLICATE_SAME_ACCESS);
479 return DEVENUM_IPropertyBag_Construct(hkey, (IPropertyBag**)ppvObj);
482 return MK_E_NOSTORAGE;
485 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_Reduce(
486 LPMONIKER iface,
487 IBindCtx* pbc,
488 DWORD dwReduceHowFar,
489 IMoniker** ppmkToLeft,
490 IMoniker** ppmkReduced)
492 TRACE("(%p, %ld, %p, %p)\n", pbc, dwReduceHowFar, ppmkToLeft, ppmkReduced);
494 if (ppmkToLeft)
495 *ppmkToLeft = NULL;
496 *ppmkReduced = iface;
498 return MK_S_REDUCED_TO_SELF;
501 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_ComposeWith(
502 LPMONIKER iface,
503 IMoniker* pmkRight,
504 BOOL fOnlyIfNotGeneric,
505 IMoniker** ppmkComposite)
507 FIXME("(%p, %s, %p): stub\n", pmkRight, fOnlyIfNotGeneric ? "true" : "false", ppmkComposite);
509 /* FIXME: use CreateGenericComposite? */
510 *ppmkComposite = NULL;
512 return E_NOTIMPL;
515 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_Enum(
516 LPMONIKER iface,
517 BOOL fForward,
518 IEnumMoniker** ppenumMoniker)
520 FIXME("(%s, %p): stub\n", fForward ? "true" : "false", ppenumMoniker);
522 *ppenumMoniker = NULL;
524 return S_OK;
527 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_IsEqual(
528 LPMONIKER iface,
529 IMoniker* pmkOtherMoniker)
531 FIXME("(%p)\n", pmkOtherMoniker);
533 return E_NOTIMPL;
536 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_Hash(
537 LPMONIKER iface,
538 DWORD* pdwHash)
540 TRACE("(%p)\n", pdwHash);
542 *pdwHash = 0;
544 return S_OK;
547 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_IsRunning(
548 LPMONIKER iface,
549 IBindCtx* pbc,
550 IMoniker* pmkToLeft,
551 IMoniker* pmkNewlyRunning)
553 FIXME("(%p, %p, %p)\n", pbc, pmkToLeft, pmkNewlyRunning);
555 return S_FALSE;
558 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_GetTimeOfLastChange(
559 LPMONIKER iface,
560 IBindCtx* pbc,
561 IMoniker* pmkToLeft,
562 FILETIME* pFileTime)
564 TRACE("(%p, %p, %p)\n", pbc, pmkToLeft, pFileTime);
566 pFileTime->dwLowDateTime = 0xFFFFFFFF;
567 pFileTime->dwHighDateTime = 0x7FFFFFFF;
569 return MK_E_UNAVAILABLE;
572 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_Inverse(
573 LPMONIKER iface,
574 IMoniker** ppmk)
576 TRACE("(%p)\n", ppmk);
578 *ppmk = NULL;
580 return MK_E_NOINVERSE;
583 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_CommonPrefixWith(
584 LPMONIKER iface,
585 IMoniker* pmkOtherMoniker,
586 IMoniker** ppmkPrefix)
588 TRACE("(%p, %p)\n", pmkOtherMoniker, ppmkPrefix);
590 *ppmkPrefix = NULL;
592 return MK_E_NOPREFIX;
595 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_RelativePathTo(
596 LPMONIKER iface,
597 IMoniker* pmkOther,
598 IMoniker** ppmkRelPath)
600 TRACE("(%p, %p)\n", pmkOther, ppmkRelPath);
602 *ppmkRelPath = pmkOther;
604 return MK_S_HIM;
607 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_GetDisplayName(
608 LPMONIKER iface,
609 IBindCtx* pbc,
610 IMoniker* pmkToLeft,
611 LPOLESTR* ppszDisplayName)
613 MediaCatMoniker *This = (MediaCatMoniker *)iface;
614 WCHAR wszBuffer[MAX_PATH];
615 static const WCHAR wszFriendlyName[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
616 LONG received = sizeof(wszFriendlyName);
618 TRACE("(%p, %p, %p)\n", pbc, pmkToLeft, ppszDisplayName);
620 *ppszDisplayName = NULL;
622 /* FIXME: should this be the weird stuff we have to parse in IParseDisplayName? */
623 if (RegQueryValueW(This->hkey, wszFriendlyName, wszBuffer, &received) == ERROR_SUCCESS)
625 *ppszDisplayName = CoTaskMemAlloc(received);
626 strcpyW(*ppszDisplayName, wszBuffer);
627 return S_OK;
630 return E_FAIL;
633 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_ParseDisplayName(
634 LPMONIKER iface,
635 IBindCtx* pbc,
636 IMoniker* pmkToLeft,
637 LPOLESTR pszDisplayName,
638 ULONG* pchEaten,
639 IMoniker** ppmkOut)
641 FIXME("(%p, %p, %s, %p, %p)\n", pbc, pmkToLeft, debugstr_w(pszDisplayName), pchEaten, ppmkOut);
643 *pchEaten = 0;
644 *ppmkOut = NULL;
646 return MK_E_SYNTAX;
649 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_IsSystemMoniker(
650 LPMONIKER iface,
651 DWORD* pdwMksys)
653 TRACE("(%p)\n", pdwMksys);
655 return S_FALSE;
658 static const IMonikerVtbl IMoniker_Vtbl =
660 DEVENUM_IMediaCatMoniker_QueryInterface,
661 DEVENUM_IMediaCatMoniker_AddRef,
662 DEVENUM_IMediaCatMoniker_Release,
663 DEVENUM_IMediaCatMoniker_GetClassID,
664 DEVENUM_IMediaCatMoniker_IsDirty,
665 DEVENUM_IMediaCatMoniker_Load,
666 DEVENUM_IMediaCatMoniker_Save,
667 DEVENUM_IMediaCatMoniker_GetSizeMax,
668 DEVENUM_IMediaCatMoniker_BindToObject,
669 DEVENUM_IMediaCatMoniker_BindToStorage,
670 DEVENUM_IMediaCatMoniker_Reduce,
671 DEVENUM_IMediaCatMoniker_ComposeWith,
672 DEVENUM_IMediaCatMoniker_Enum,
673 DEVENUM_IMediaCatMoniker_IsEqual,
674 DEVENUM_IMediaCatMoniker_Hash,
675 DEVENUM_IMediaCatMoniker_IsRunning,
676 DEVENUM_IMediaCatMoniker_GetTimeOfLastChange,
677 DEVENUM_IMediaCatMoniker_Inverse,
678 DEVENUM_IMediaCatMoniker_CommonPrefixWith,
679 DEVENUM_IMediaCatMoniker_RelativePathTo,
680 DEVENUM_IMediaCatMoniker_GetDisplayName,
681 DEVENUM_IMediaCatMoniker_ParseDisplayName,
682 DEVENUM_IMediaCatMoniker_IsSystemMoniker
685 MediaCatMoniker * DEVENUM_IMediaCatMoniker_Construct()
687 MediaCatMoniker * pMoniker = NULL;
688 pMoniker = CoTaskMemAlloc(sizeof(MediaCatMoniker));
689 if (!pMoniker)
690 return NULL;
692 pMoniker->lpVtbl = &IMoniker_Vtbl;
693 pMoniker->ref = 0;
694 pMoniker->hkey = NULL;
696 DEVENUM_IMediaCatMoniker_AddRef((LPMONIKER)pMoniker);
698 DEVENUM_LockModule();
700 return pMoniker;
703 /**********************************************************************
704 * DEVENUM_IEnumMoniker_QueryInterface (also IUnknown)
706 static HRESULT WINAPI DEVENUM_IEnumMoniker_QueryInterface(
707 LPENUMMONIKER iface,
708 REFIID riid,
709 LPVOID *ppvObj)
711 EnumMonikerImpl *This = (EnumMonikerImpl *)iface;
712 TRACE("\n\tIID:\t%s\n",debugstr_guid(riid));
714 if (This == NULL || ppvObj == NULL) return E_POINTER;
716 if (IsEqualGUID(riid, &IID_IUnknown) ||
717 IsEqualGUID(riid, &IID_IEnumMoniker))
719 *ppvObj = (LPVOID)iface;
720 DEVENUM_IEnumMoniker_AddRef(iface);
721 return S_OK;
724 FIXME("- no interface\n\tIID:\t%s\n", debugstr_guid(riid));
725 return E_NOINTERFACE;
728 /**********************************************************************
729 * DEVENUM_IEnumMoniker_AddRef (also IUnknown)
731 static ULONG WINAPI DEVENUM_IEnumMoniker_AddRef(LPENUMMONIKER iface)
733 EnumMonikerImpl *This = (EnumMonikerImpl *)iface;
734 ULONG ref = InterlockedIncrement(&This->ref);
736 TRACE("(%p)->() AddRef from %ld\n", iface, ref - 1);
738 return ref;
741 /**********************************************************************
742 * DEVENUM_IEnumMoniker_Release (also IUnknown)
744 static ULONG WINAPI DEVENUM_IEnumMoniker_Release(LPENUMMONIKER iface)
746 EnumMonikerImpl *This = (EnumMonikerImpl *)iface;
747 ULONG ref = InterlockedDecrement(&This->ref);
749 TRACE("(%p)->() Release from %ld\n", iface, ref + 1);
751 if (!ref)
753 RegCloseKey(This->hkey);
754 CoTaskMemFree(This);
755 DEVENUM_UnlockModule();
756 return 0;
758 return ref;
761 static HRESULT WINAPI DEVENUM_IEnumMoniker_Next(LPENUMMONIKER iface, ULONG celt, IMoniker ** rgelt, ULONG * pceltFetched)
763 WCHAR buffer[MAX_PATH + 1];
764 LONG res;
765 ULONG fetched = 0;
766 MediaCatMoniker * pMoniker;
767 EnumMonikerImpl *This = (EnumMonikerImpl *)iface;
769 TRACE("(%p)->(%ld, %p, %p)\n", iface, celt, rgelt, pceltFetched);
771 while (fetched < celt)
773 res = RegEnumKeyW(This->hkey, This->index, buffer, sizeof(buffer) / sizeof(WCHAR));
774 if (res != ERROR_SUCCESS)
776 break;
778 pMoniker = DEVENUM_IMediaCatMoniker_Construct();
779 if (!pMoniker)
780 return E_OUTOFMEMORY;
782 if (RegOpenKeyW(This->hkey, buffer, &pMoniker->hkey) != ERROR_SUCCESS)
784 DEVENUM_IMediaCatMoniker_Release((LPMONIKER)pMoniker);
785 break;
787 rgelt[fetched] = (LPMONIKER)pMoniker;
788 fetched++;
791 This->index += fetched;
793 TRACE("-- fetched %ld\n", fetched);
795 if (pceltFetched)
796 *pceltFetched = fetched;
798 if (fetched != celt)
799 return S_FALSE;
800 else
801 return S_OK;
804 static HRESULT WINAPI DEVENUM_IEnumMoniker_Skip(LPENUMMONIKER iface, ULONG celt)
806 EnumMonikerImpl *This = (EnumMonikerImpl *)iface;
808 TRACE("(%p)->(%ld)\n", iface, celt);
810 This->index += celt;
812 return S_OK;
815 static HRESULT WINAPI DEVENUM_IEnumMoniker_Reset(LPENUMMONIKER iface)
817 EnumMonikerImpl *This = (EnumMonikerImpl *)iface;
819 TRACE("(%p)->()\n", iface);
821 This->index = 0;
823 return S_OK;
826 static HRESULT WINAPI DEVENUM_IEnumMoniker_Clone(LPENUMMONIKER iface, IEnumMoniker ** ppenum)
828 FIXME("(%p)->(%p): stub\n", iface, ppenum);
830 return E_NOTIMPL;
833 /**********************************************************************
834 * IEnumMoniker_Vtbl
836 static const IEnumMonikerVtbl IEnumMoniker_Vtbl =
838 DEVENUM_IEnumMoniker_QueryInterface,
839 DEVENUM_IEnumMoniker_AddRef,
840 DEVENUM_IEnumMoniker_Release,
841 DEVENUM_IEnumMoniker_Next,
842 DEVENUM_IEnumMoniker_Skip,
843 DEVENUM_IEnumMoniker_Reset,
844 DEVENUM_IEnumMoniker_Clone
847 HRESULT DEVENUM_IEnumMoniker_Construct(HKEY hkey, IEnumMoniker ** ppEnumMoniker)
849 EnumMonikerImpl * pEnumMoniker = CoTaskMemAlloc(sizeof(EnumMonikerImpl));
850 if (!pEnumMoniker)
851 return E_OUTOFMEMORY;
853 pEnumMoniker->lpVtbl = &IEnumMoniker_Vtbl;
854 pEnumMoniker->ref = 1;
855 pEnumMoniker->index = 0;
856 pEnumMoniker->hkey = hkey;
858 *ppEnumMoniker = (IEnumMoniker *)pEnumMoniker;
860 DEVENUM_LockModule();
862 return S_OK;