msdaps: Add support for remoting IRowsetLocate_GetRowsAt.
[wine.git] / dlls / devenum / mediacatenum.c
blob349ea7d6e43c7644a00d083fac633b56f05c4ffb
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 "oleauto.h"
27 #include "ocidl.h"
29 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(devenum);
33 static ULONG WINAPI DEVENUM_IEnumMoniker_AddRef(LPENUMMONIKER iface);
34 static ULONG WINAPI DEVENUM_IMediaCatMoniker_AddRef(LPMONIKER iface);
35 static ULONG WINAPI DEVENUM_IPropertyBag_AddRef(LPPROPERTYBAG iface);
37 typedef struct
39 const IPropertyBagVtbl *lpVtbl;
40 LONG ref;
41 HKEY hkey;
42 } RegPropBagImpl;
45 static HRESULT WINAPI DEVENUM_IPropertyBag_QueryInterface(
46 LPPROPERTYBAG iface,
47 REFIID riid,
48 LPVOID *ppvObj)
50 RegPropBagImpl *This = (RegPropBagImpl *)iface;
52 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppvObj);
54 if (This == NULL || ppvObj == NULL) return E_POINTER;
56 if (IsEqualGUID(riid, &IID_IUnknown) ||
57 IsEqualGUID(riid, &IID_IPropertyBag))
59 *ppvObj = iface;
60 DEVENUM_IPropertyBag_AddRef(iface);
61 return S_OK;
64 FIXME("- no interface IID: %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;
75 TRACE("(%p)->() AddRef from %d\n", iface, This->ref);
77 return InterlockedIncrement(&This->ref);
80 /**********************************************************************
81 * DEVENUM_IPropertyBag_Release (also IUnknown)
83 static ULONG WINAPI DEVENUM_IPropertyBag_Release(LPPROPERTYBAG iface)
85 RegPropBagImpl *This = (RegPropBagImpl *)iface;
86 ULONG ref;
88 TRACE("(%p)->() ReleaseThis->ref from %d\n", iface, This->ref);
90 ref = InterlockedDecrement(&This->ref);
91 if (ref == 0) {
92 RegCloseKey(This->hkey);
93 CoTaskMemFree(This);
94 DEVENUM_UnlockModule();
96 return ref;
99 static HRESULT WINAPI DEVENUM_IPropertyBag_Read(
100 LPPROPERTYBAG iface,
101 LPCOLESTR pszPropName,
102 VARIANT* pVar,
103 IErrorLog* pErrorLog)
105 LPVOID pData = NULL;
106 DWORD received;
107 DWORD type = 0;
108 RegPropBagImpl *This = (RegPropBagImpl *)iface;
109 HRESULT res = S_OK;
110 LONG reswin32;
112 TRACE("(%p)->(%s, %p, %p)\n", This, debugstr_w(pszPropName), pVar, pErrorLog);
114 if (!pszPropName || !pVar)
115 return E_POINTER;
117 reswin32 = RegQueryValueExW(This->hkey, pszPropName, NULL, NULL, NULL, &received);
118 res = HRESULT_FROM_WIN32(reswin32);
120 if (SUCCEEDED(res))
122 pData = HeapAlloc(GetProcessHeap(), 0, received);
124 /* work around a GCC bug that occurs here unless we use the reswin32 variable as well */
125 reswin32 = RegQueryValueExW(This->hkey, pszPropName, NULL, &type, pData, &received);
126 res = HRESULT_FROM_WIN32(reswin32);
129 if (SUCCEEDED(res))
131 res = E_INVALIDARG; /* assume we cannot coerce into right type */
133 TRACE("Read %d bytes (%s)\n", received, type == REG_SZ ? debugstr_w(pData) : "binary data");
135 switch (type)
137 case REG_SZ:
138 switch (V_VT(pVar))
140 case VT_LPWSTR:
141 V_UNION(pVar, bstrVal) = CoTaskMemAlloc(received);
142 memcpy(V_UNION(pVar, bstrVal), pData, received);
143 res = S_OK;
144 break;
145 case VT_EMPTY:
146 V_VT(pVar) = VT_BSTR;
147 /* fall through */
148 case VT_BSTR:
149 V_UNION(pVar, bstrVal) = SysAllocStringLen(pData, received/sizeof(WCHAR) - 1);
150 res = S_OK;
151 break;
153 break;
154 case REG_DWORD:
155 TRACE("REG_DWORD: %x\n", *(DWORD *)pData);
156 switch (V_VT(pVar))
158 case VT_EMPTY:
159 V_VT(pVar) = VT_I4;
160 /* fall through */
161 case VT_I4:
162 case VT_UI4:
163 V_UNION(pVar, ulVal) = *(DWORD *)pData;
164 res = S_OK;
165 break;
167 break;
168 case REG_BINARY:
170 SAFEARRAYBOUND bound;
171 void * pArrayElements;
172 bound.lLbound = 0;
173 bound.cElements = received;
174 TRACE("REG_BINARY: len = %d\n", received);
175 switch (V_VT(pVar))
177 case VT_EMPTY:
178 V_VT(pVar) = VT_ARRAY | VT_UI1;
179 /* fall through */
180 case VT_ARRAY | VT_UI1:
181 if (!(V_UNION(pVar, parray) = SafeArrayCreate(VT_UI1, 1, &bound)))
182 res = E_OUTOFMEMORY;
183 else
184 res = S_OK;
185 break;
188 if (res == E_INVALIDARG)
189 break;
191 res = SafeArrayAccessData(V_UNION(pVar, parray), &pArrayElements);
192 if (FAILED(res))
193 break;
195 CopyMemory(pArrayElements, pData, received);
196 res = SafeArrayUnaccessData(V_UNION(pVar, parray));
197 break;
200 if (res == E_INVALIDARG)
201 FIXME("Variant type %x not supported for regtype %x\n", V_VT(pVar), type);
204 HeapFree(GetProcessHeap(), 0, pData);
206 TRACE("<- %x\n", res);
207 return res;
210 static HRESULT WINAPI DEVENUM_IPropertyBag_Write(
211 LPPROPERTYBAG iface,
212 LPCOLESTR pszPropName,
213 VARIANT* pVar)
215 RegPropBagImpl *This = (RegPropBagImpl *)iface;
216 LPVOID lpData = NULL;
217 DWORD cbData = 0;
218 DWORD dwType = 0;
219 HRESULT res = S_OK;
221 TRACE("(%p)->(%s, %p)\n", This, debugstr_w(pszPropName), pVar);
223 switch (V_VT(pVar))
225 case VT_BSTR:
226 TRACE("writing %s\n", debugstr_w(V_UNION(pVar, bstrVal)));
227 lpData = V_UNION(pVar, bstrVal);
228 dwType = REG_SZ;
229 cbData = (lstrlenW(V_UNION(pVar, bstrVal)) + 1) * sizeof(WCHAR);
230 break;
231 case VT_I4:
232 case VT_UI4:
233 TRACE("writing %u\n", V_UNION(pVar, ulVal));
234 lpData = &V_UNION(pVar, ulVal);
235 dwType = REG_DWORD;
236 cbData = sizeof(DWORD);
237 break;
238 case VT_ARRAY | VT_UI1:
240 LONG lUbound = 0;
241 LONG lLbound = 0;
242 dwType = REG_BINARY;
243 res = SafeArrayGetLBound(V_UNION(pVar, parray), 1, &lLbound);
244 res = SafeArrayGetUBound(V_UNION(pVar, parray), 1, &lUbound);
245 cbData = (lUbound - lLbound + 1) /* * sizeof(BYTE)*/;
246 TRACE("cbData: %d\n", cbData);
247 res = SafeArrayAccessData(V_UNION(pVar, parray), &lpData);
248 break;
250 default:
251 FIXME("Variant type %d not handled\n", V_VT(pVar));
252 return E_FAIL;
255 if (RegSetValueExW(This->hkey,
256 pszPropName, 0,
257 dwType, lpData, cbData) != ERROR_SUCCESS)
258 res = E_FAIL;
260 if (V_VT(pVar) & VT_ARRAY)
261 res = SafeArrayUnaccessData(V_UNION(pVar, parray));
263 return res;
266 static const IPropertyBagVtbl IPropertyBag_Vtbl =
268 DEVENUM_IPropertyBag_QueryInterface,
269 DEVENUM_IPropertyBag_AddRef,
270 DEVENUM_IPropertyBag_Release,
271 DEVENUM_IPropertyBag_Read,
272 DEVENUM_IPropertyBag_Write
275 static HRESULT DEVENUM_IPropertyBag_Construct(HANDLE hkey, IPropertyBag **ppBag)
277 RegPropBagImpl * rpb = CoTaskMemAlloc(sizeof(RegPropBagImpl));
278 if (!rpb)
279 return E_OUTOFMEMORY;
280 rpb->lpVtbl = &IPropertyBag_Vtbl;
281 rpb->ref = 1;
282 rpb->hkey = hkey;
283 *ppBag = (IPropertyBag*)rpb;
284 DEVENUM_LockModule();
285 return S_OK;
289 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_QueryInterface(
290 LPMONIKER iface,
291 REFIID riid,
292 LPVOID *ppvObj)
294 MediaCatMoniker *This = (MediaCatMoniker *)iface;
295 TRACE("\n\tIID:\t%s\n",debugstr_guid(riid));
297 if (This == NULL || ppvObj == NULL) return E_POINTER;
299 *ppvObj = NULL;
301 if (IsEqualGUID(riid, &IID_IUnknown) ||
302 IsEqualGUID(riid, &IID_IPersist) ||
303 IsEqualGUID(riid, &IID_IPersistStream) ||
304 IsEqualGUID(riid, &IID_IMoniker))
306 *ppvObj = iface;
307 DEVENUM_IMediaCatMoniker_AddRef(iface);
308 return S_OK;
311 FIXME("- no interface IID: %s\n", debugstr_guid(riid));
312 return E_NOINTERFACE;
315 /**********************************************************************
316 * DEVENUM_IMediaCatMoniker_AddRef (also IUnknown)
318 static ULONG WINAPI DEVENUM_IMediaCatMoniker_AddRef(LPMONIKER iface)
320 MediaCatMoniker *This = (MediaCatMoniker *)iface;
321 TRACE("\n");
323 return InterlockedIncrement(&This->ref);
326 /**********************************************************************
327 * DEVENUM_IMediaCatMoniker_Release (also IUnknown)
329 static ULONG WINAPI DEVENUM_IMediaCatMoniker_Release(LPMONIKER iface)
331 MediaCatMoniker *This = (MediaCatMoniker *)iface;
332 ULONG ref;
333 TRACE("\n");
335 ref = InterlockedDecrement(&This->ref);
336 if (ref == 0) {
337 RegCloseKey(This->hkey);
338 CoTaskMemFree(This);
339 DEVENUM_UnlockModule();
341 return ref;
344 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_GetClassID(
345 LPMONIKER iface,
346 CLSID* pClassID)
348 MediaCatMoniker *This = (MediaCatMoniker *)iface;
349 FIXME("(%p)->(%p): stub\n", This, pClassID);
351 if (pClassID == NULL)
352 return E_POINTER;
354 return E_NOTIMPL;
357 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_IsDirty(LPMONIKER iface)
359 FIXME("(%p)->(): stub\n", iface);
361 return S_FALSE;
364 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_Load(LPMONIKER iface, IStream* pStm)
366 FIXME("(%p)->(%p): stub\n", iface, pStm);
368 return E_NOTIMPL;
371 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_Save(LPMONIKER iface, IStream* pStm, BOOL fClearDirty)
373 FIXME("(%p)->(%p, %s): stub\n", iface, pStm, fClearDirty ? "true" : "false");
375 return STG_E_CANTSAVE;
378 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_GetSizeMax(
379 LPMONIKER iface,
380 ULARGE_INTEGER* pcbSize)
382 FIXME("(%p)->(%p): stub\n", iface, pcbSize);
384 ZeroMemory(pcbSize, sizeof(*pcbSize));
386 return S_OK;
389 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_BindToObject(
390 LPMONIKER iface,
391 IBindCtx* pbc,
392 IMoniker* pmkToLeft,
393 REFIID riidResult,
394 void** ppvResult)
396 IUnknown * pObj = NULL;
397 IPropertyBag * pProp = NULL;
398 CLSID clsID;
399 VARIANT var;
400 HRESULT res = E_FAIL;
402 MediaCatMoniker *This = (MediaCatMoniker *)iface;
404 VariantInit(&var);
406 TRACE("(%p)->(%p, %p, %s, %p)\n", This, pbc, pmkToLeft, debugstr_guid(riidResult), ppvResult);
408 *ppvResult = NULL;
410 if(pmkToLeft==NULL)
412 /* first activation of this class */
413 LPVOID pvptr;
414 res=IMoniker_BindToStorage(iface, NULL, NULL, &IID_IPropertyBag, &pvptr);
415 pProp = pvptr;
416 if (SUCCEEDED(res))
418 V_VT(&var) = VT_LPWSTR;
419 res = IPropertyBag_Read(pProp, clsid_keyname, &var, NULL);
421 if (SUCCEEDED(res))
423 res = CLSIDFromString(V_UNION(&var,bstrVal), &clsID);
424 CoTaskMemFree(V_UNION(&var, bstrVal));
426 if (SUCCEEDED(res))
428 res=CoCreateInstance(&clsID,NULL,CLSCTX_ALL,&IID_IUnknown,&pvptr);
429 pObj = pvptr;
433 if (pObj!=NULL)
435 /* get the requested interface from the loaded class */
436 res = S_OK;
437 if (pProp) {
438 HRESULT res2;
439 LPVOID ppv = NULL;
440 res2 = IUnknown_QueryInterface(pObj, &IID_IPersistPropertyBag, &ppv);
441 if (SUCCEEDED(res2)) {
442 res = IPersistPropertyBag_Load((IPersistPropertyBag *) ppv, pProp, NULL);
443 IPersistPropertyBag_Release((IPersistPropertyBag *) ppv);
446 if (SUCCEEDED(res))
447 res= IUnknown_QueryInterface(pObj,riidResult,ppvResult);
448 IUnknown_Release(pObj);
451 if (pProp)
453 IPropertyBag_Release(pProp);
456 TRACE("<- 0x%x\n", res);
458 return res;
461 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_BindToStorage(
462 LPMONIKER iface,
463 IBindCtx* pbc,
464 IMoniker* pmkToLeft,
465 REFIID riid,
466 void** ppvObj)
468 MediaCatMoniker *This = (MediaCatMoniker *)iface;
469 TRACE("(%p)->(%p, %p, %s, %p)\n", This, pbc, pmkToLeft, debugstr_guid(riid), ppvObj);
471 *ppvObj = NULL;
473 if (pbc || pmkToLeft)
474 return MK_E_NOSTORAGE;
476 if (IsEqualGUID(riid, &IID_IPropertyBag))
478 HANDLE hkey;
479 DuplicateHandle(GetCurrentProcess(), This->hkey, GetCurrentProcess(), &hkey, 0, 0, DUPLICATE_SAME_ACCESS);
480 return DEVENUM_IPropertyBag_Construct(hkey, (IPropertyBag**)ppvObj);
483 return MK_E_NOSTORAGE;
486 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_Reduce(
487 LPMONIKER iface,
488 IBindCtx* pbc,
489 DWORD dwReduceHowFar,
490 IMoniker** ppmkToLeft,
491 IMoniker** ppmkReduced)
493 TRACE("(%p)->(%p, %d, %p, %p)\n", iface, pbc, dwReduceHowFar, ppmkToLeft, ppmkReduced);
495 if (ppmkToLeft)
496 *ppmkToLeft = NULL;
497 *ppmkReduced = iface;
499 return MK_S_REDUCED_TO_SELF;
502 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_ComposeWith(
503 LPMONIKER iface,
504 IMoniker* pmkRight,
505 BOOL fOnlyIfNotGeneric,
506 IMoniker** ppmkComposite)
508 FIXME("(%p)->(%p, %s, %p): stub\n", iface, pmkRight, fOnlyIfNotGeneric ? "true" : "false", ppmkComposite);
510 /* FIXME: use CreateGenericComposite? */
511 *ppmkComposite = NULL;
513 return E_NOTIMPL;
516 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_Enum(
517 LPMONIKER iface,
518 BOOL fForward,
519 IEnumMoniker** ppenumMoniker)
521 FIXME("(%p)->(%s, %p): stub\n", iface, fForward ? "true" : "false", ppenumMoniker);
523 *ppenumMoniker = NULL;
525 return S_OK;
528 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_IsEqual(
529 LPMONIKER iface,
530 IMoniker* pmkOtherMoniker)
532 FIXME("(%p)->(%p): stub\n", iface, pmkOtherMoniker);
534 return E_NOTIMPL;
537 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_Hash(
538 LPMONIKER iface,
539 DWORD* pdwHash)
541 TRACE("(%p)->(%p)\n", iface, pdwHash);
543 *pdwHash = 0;
545 return S_OK;
548 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_IsRunning(
549 LPMONIKER iface,
550 IBindCtx* pbc,
551 IMoniker* pmkToLeft,
552 IMoniker* pmkNewlyRunning)
554 FIXME("(%p)->(%p, %p, %p): stub\n", iface, pbc, pmkToLeft, pmkNewlyRunning);
556 return S_FALSE;
559 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_GetTimeOfLastChange(
560 LPMONIKER iface,
561 IBindCtx* pbc,
562 IMoniker* pmkToLeft,
563 FILETIME* pFileTime)
565 TRACE("(%p)->(%p, %p, %p)\n", iface, pbc, pmkToLeft, pFileTime);
567 pFileTime->dwLowDateTime = 0xFFFFFFFF;
568 pFileTime->dwHighDateTime = 0x7FFFFFFF;
570 return MK_E_UNAVAILABLE;
573 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_Inverse(
574 LPMONIKER iface,
575 IMoniker** ppmk)
577 TRACE("(%p)->(%p)\n", iface, ppmk);
579 *ppmk = NULL;
581 return MK_E_NOINVERSE;
584 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_CommonPrefixWith(
585 LPMONIKER iface,
586 IMoniker* pmkOtherMoniker,
587 IMoniker** ppmkPrefix)
589 TRACE("(%p)->(%p, %p)\n", iface, pmkOtherMoniker, ppmkPrefix);
591 *ppmkPrefix = NULL;
593 return MK_E_NOPREFIX;
596 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_RelativePathTo(
597 LPMONIKER iface,
598 IMoniker* pmkOther,
599 IMoniker** ppmkRelPath)
601 TRACE("(%p)->(%p, %p)\n", iface, pmkOther, ppmkRelPath);
603 *ppmkRelPath = pmkOther;
605 return MK_S_HIM;
608 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_GetDisplayName(
609 LPMONIKER iface,
610 IBindCtx* pbc,
611 IMoniker* pmkToLeft,
612 LPOLESTR* ppszDisplayName)
614 MediaCatMoniker *This = (MediaCatMoniker *)iface;
615 WCHAR wszBuffer[MAX_PATH];
616 static const WCHAR wszFriendlyName[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
617 LONG received = sizeof(wszFriendlyName);
619 TRACE("(%p)->(%p, %p, %p)\n", iface, pbc, pmkToLeft, ppszDisplayName);
621 *ppszDisplayName = NULL;
623 /* FIXME: should this be the weird stuff we have to parse in IParseDisplayName? */
624 if (RegQueryValueW(This->hkey, wszFriendlyName, wszBuffer, &received) == ERROR_SUCCESS)
626 *ppszDisplayName = CoTaskMemAlloc(received);
627 strcpyW(*ppszDisplayName, wszBuffer);
628 return S_OK;
631 return E_FAIL;
634 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_ParseDisplayName(
635 LPMONIKER iface,
636 IBindCtx* pbc,
637 IMoniker* pmkToLeft,
638 LPOLESTR pszDisplayName,
639 ULONG* pchEaten,
640 IMoniker** ppmkOut)
642 FIXME("(%p)->(%p, %p, %s, %p, %p)\n", iface, pbc, pmkToLeft, debugstr_w(pszDisplayName), pchEaten, ppmkOut);
644 *pchEaten = 0;
645 *ppmkOut = NULL;
647 return MK_E_SYNTAX;
650 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_IsSystemMoniker(
651 LPMONIKER iface,
652 DWORD* pdwMksys)
654 TRACE("(%p)->(%p)\n", iface, pdwMksys);
656 return S_FALSE;
659 static const IMonikerVtbl IMoniker_Vtbl =
661 DEVENUM_IMediaCatMoniker_QueryInterface,
662 DEVENUM_IMediaCatMoniker_AddRef,
663 DEVENUM_IMediaCatMoniker_Release,
664 DEVENUM_IMediaCatMoniker_GetClassID,
665 DEVENUM_IMediaCatMoniker_IsDirty,
666 DEVENUM_IMediaCatMoniker_Load,
667 DEVENUM_IMediaCatMoniker_Save,
668 DEVENUM_IMediaCatMoniker_GetSizeMax,
669 DEVENUM_IMediaCatMoniker_BindToObject,
670 DEVENUM_IMediaCatMoniker_BindToStorage,
671 DEVENUM_IMediaCatMoniker_Reduce,
672 DEVENUM_IMediaCatMoniker_ComposeWith,
673 DEVENUM_IMediaCatMoniker_Enum,
674 DEVENUM_IMediaCatMoniker_IsEqual,
675 DEVENUM_IMediaCatMoniker_Hash,
676 DEVENUM_IMediaCatMoniker_IsRunning,
677 DEVENUM_IMediaCatMoniker_GetTimeOfLastChange,
678 DEVENUM_IMediaCatMoniker_Inverse,
679 DEVENUM_IMediaCatMoniker_CommonPrefixWith,
680 DEVENUM_IMediaCatMoniker_RelativePathTo,
681 DEVENUM_IMediaCatMoniker_GetDisplayName,
682 DEVENUM_IMediaCatMoniker_ParseDisplayName,
683 DEVENUM_IMediaCatMoniker_IsSystemMoniker
686 MediaCatMoniker * DEVENUM_IMediaCatMoniker_Construct(void)
688 MediaCatMoniker * pMoniker = NULL;
689 pMoniker = CoTaskMemAlloc(sizeof(MediaCatMoniker));
690 if (!pMoniker)
691 return NULL;
693 pMoniker->lpVtbl = &IMoniker_Vtbl;
694 pMoniker->ref = 0;
695 pMoniker->hkey = NULL;
697 DEVENUM_IMediaCatMoniker_AddRef((LPMONIKER)pMoniker);
699 DEVENUM_LockModule();
701 return pMoniker;
704 /**********************************************************************
705 * DEVENUM_IEnumMoniker_QueryInterface (also IUnknown)
707 static HRESULT WINAPI DEVENUM_IEnumMoniker_QueryInterface(
708 LPENUMMONIKER iface,
709 REFIID riid,
710 LPVOID *ppvObj)
712 EnumMonikerImpl *This = (EnumMonikerImpl *)iface;
714 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppvObj);
716 if (This == NULL || ppvObj == NULL) return E_POINTER;
718 if (IsEqualGUID(riid, &IID_IUnknown) ||
719 IsEqualGUID(riid, &IID_IEnumMoniker))
721 *ppvObj = iface;
722 DEVENUM_IEnumMoniker_AddRef(iface);
723 return S_OK;
726 FIXME("- no interface IID: %s\n", debugstr_guid(riid));
727 return E_NOINTERFACE;
730 /**********************************************************************
731 * DEVENUM_IEnumMoniker_AddRef (also IUnknown)
733 static ULONG WINAPI DEVENUM_IEnumMoniker_AddRef(LPENUMMONIKER iface)
735 EnumMonikerImpl *This = (EnumMonikerImpl *)iface;
736 ULONG ref = InterlockedIncrement(&This->ref);
738 TRACE("(%p)->() AddRef from %d\n", iface, ref - 1);
740 return ref;
743 /**********************************************************************
744 * DEVENUM_IEnumMoniker_Release (also IUnknown)
746 static ULONG WINAPI DEVENUM_IEnumMoniker_Release(LPENUMMONIKER iface)
748 EnumMonikerImpl *This = (EnumMonikerImpl *)iface;
749 ULONG ref = InterlockedDecrement(&This->ref);
751 TRACE("(%p)->() Release from %d\n", iface, ref + 1);
753 if (!ref)
755 RegCloseKey(This->hkey);
756 CoTaskMemFree(This);
757 DEVENUM_UnlockModule();
758 return 0;
760 return ref;
763 static HRESULT WINAPI DEVENUM_IEnumMoniker_Next(LPENUMMONIKER iface, ULONG celt, IMoniker ** rgelt, ULONG * pceltFetched)
765 WCHAR buffer[MAX_PATH + 1];
766 LONG res;
767 ULONG fetched = 0;
768 MediaCatMoniker * pMoniker;
769 EnumMonikerImpl *This = (EnumMonikerImpl *)iface;
771 TRACE("(%p)->(%d, %p, %p)\n", iface, celt, rgelt, pceltFetched);
773 while (fetched < celt)
775 res = RegEnumKeyW(This->hkey, This->index, buffer, sizeof(buffer) / sizeof(WCHAR));
776 if (res != ERROR_SUCCESS)
778 break;
780 pMoniker = DEVENUM_IMediaCatMoniker_Construct();
781 if (!pMoniker)
782 return E_OUTOFMEMORY;
784 if (RegOpenKeyW(This->hkey, buffer, &pMoniker->hkey) != ERROR_SUCCESS)
786 DEVENUM_IMediaCatMoniker_Release((LPMONIKER)pMoniker);
787 break;
789 rgelt[fetched] = (LPMONIKER)pMoniker;
790 fetched++;
793 This->index += fetched;
795 TRACE("-- fetched %d\n", fetched);
797 if (pceltFetched)
798 *pceltFetched = fetched;
800 if (fetched != celt)
801 return S_FALSE;
802 else
803 return S_OK;
806 static HRESULT WINAPI DEVENUM_IEnumMoniker_Skip(LPENUMMONIKER iface, ULONG celt)
808 EnumMonikerImpl *This = (EnumMonikerImpl *)iface;
809 DWORD subKeys;
811 TRACE("(%p)->(%d)\n", iface, celt);
813 /* Before incrementing, check if there are any more values to run thru.
814 Some programs use the Skip() function to get the amount of devices */
815 if(RegQueryInfoKeyW(This->hkey, NULL, NULL, NULL, &subKeys, NULL, NULL, NULL, NULL, NULL, NULL, NULL) != ERROR_SUCCESS)
817 return S_FALSE;
819 if((This->index + celt) >= subKeys)
821 return S_FALSE;
824 This->index += celt;
826 return S_OK;
829 static HRESULT WINAPI DEVENUM_IEnumMoniker_Reset(LPENUMMONIKER iface)
831 EnumMonikerImpl *This = (EnumMonikerImpl *)iface;
833 TRACE("(%p)->()\n", iface);
835 This->index = 0;
837 return S_OK;
840 static HRESULT WINAPI DEVENUM_IEnumMoniker_Clone(LPENUMMONIKER iface, IEnumMoniker ** ppenum)
842 FIXME("(%p)->(%p): stub\n", iface, ppenum);
844 return E_NOTIMPL;
847 /**********************************************************************
848 * IEnumMoniker_Vtbl
850 static const IEnumMonikerVtbl IEnumMoniker_Vtbl =
852 DEVENUM_IEnumMoniker_QueryInterface,
853 DEVENUM_IEnumMoniker_AddRef,
854 DEVENUM_IEnumMoniker_Release,
855 DEVENUM_IEnumMoniker_Next,
856 DEVENUM_IEnumMoniker_Skip,
857 DEVENUM_IEnumMoniker_Reset,
858 DEVENUM_IEnumMoniker_Clone
861 HRESULT DEVENUM_IEnumMoniker_Construct(HKEY hkey, IEnumMoniker ** ppEnumMoniker)
863 EnumMonikerImpl * pEnumMoniker = CoTaskMemAlloc(sizeof(EnumMonikerImpl));
864 if (!pEnumMoniker)
865 return E_OUTOFMEMORY;
867 pEnumMoniker->lpVtbl = &IEnumMoniker_Vtbl;
868 pEnumMoniker->ref = 1;
869 pEnumMoniker->index = 0;
870 pEnumMoniker->hkey = hkey;
872 *ppEnumMoniker = (IEnumMoniker *)pEnumMoniker;
874 DEVENUM_LockModule();
876 return S_OK;