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
21 * - Implements IEnumMoniker interface which enumerates through moniker
22 * objects created from HKEY_CLASSES/CLSID/{DEVICE_CLSID}/Instance
25 #include "devenum_private.h"
29 #include "wine/debug.h"
32 /* #define ICOM_THIS_From_IROTData(class, name) class* This = (class*)(((char*)name)-sizeof(void*)) */
34 WINE_DEFAULT_DEBUG_CHANNEL(devenum
);
36 static ULONG WINAPI
DEVENUM_IEnumMoniker_AddRef(LPENUMMONIKER iface
);
37 static HRESULT WINAPI
DEVENUM_IMediaCatMoniker_Hash(LPMONIKER iface
, DWORD
* pdwHash
);
38 static ULONG WINAPI
DEVENUM_IMediaCatMoniker_AddRef(LPMONIKER iface
);
39 static ULONG WINAPI
DEVENUM_IPropertyBag_AddRef(LPPROPERTYBAG iface
);
41 static HRESULT WINAPI
DEVENUM_IPropertyBag_QueryInterface(
46 ICOM_THIS(RegPropBagImpl
, iface
);
47 TRACE("\n\tIID:\t%s\n",debugstr_guid(riid
));
49 if (This
== NULL
|| ppvObj
== NULL
) return E_POINTER
;
51 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
52 IsEqualGUID(riid
, &IID_IPropertyBag
))
54 *ppvObj
= (LPVOID
)iface
;
55 DEVENUM_IPropertyBag_AddRef(iface
);
59 FIXME("- no interface\n\tIID:\t%s\n", debugstr_guid(riid
));
63 /**********************************************************************
64 * DEVENUM_IPropertyBag_AddRef (also IUnknown)
66 static ULONG WINAPI
DEVENUM_IPropertyBag_AddRef(LPPROPERTYBAG iface
)
68 ICOM_THIS(RegPropBagImpl
, iface
);
71 return InterlockedIncrement(&This
->ref
);
74 /**********************************************************************
75 * DEVENUM_IPropertyBag_Release (also IUnknown)
77 static ULONG WINAPI
DEVENUM_IPropertyBag_Release(LPPROPERTYBAG iface
)
79 ICOM_THIS(RegPropBagImpl
, iface
);
83 if (InterlockedDecrement(&This
->ref
) == 0) {
84 RegCloseKey(This
->hkey
);
91 static HRESULT WINAPI
DEVENUM_IPropertyBag_Read(
93 LPCOLESTR pszPropName
,
97 WCHAR wszData
[MAX_PATH
+ 1];
98 LONG received
= MAX_PATH
+ 1;
100 ICOM_THIS(RegPropBagImpl
, iface
);
104 TRACE("(%p)->(%s, %p, %p)\n", This
, debugstr_w(pszPropName
), pVar
, pErrorLog
);
106 if (!pszPropName
|| !pVar
)
109 /* work around a GCC bug that occurs here unless we use the reswin32 variable as well */
110 reswin32
= RegQueryValueExW(This
->hkey
, pszPropName
, NULL
, &type
, (LPVOID
)wszData
, &received
);
111 res
= HRESULT_FROM_WIN32(reswin32
);
115 TRACE("%ld, %s\n", received
, debugstr_w(wszData
));
122 V_UNION(pVar
, bstrVal
) = CoTaskMemAlloc(received
* sizeof(WCHAR
));
123 strcpyW(V_UNION(pVar
, bstrVal
), wszData
);
126 V_VT(pVar
) = VT_BSTR
;
129 V_UNION(pVar
, bstrVal
) = SysAllocStringLen(wszData
, received
- 1);
134 TRACE("REG_DWORD: %lx\n", *(DWORD
*)wszData
);
142 V_UNION(pVar
, ulVal
) = *(DWORD
*)wszData
;
148 SAFEARRAYBOUND bound
;
149 void * pArrayElements
;
151 bound
.cElements
= received
;
152 TRACE("REG_BINARY: len = %ld\n", received
);
156 case VT_ARRAY
| VT_UI1
:
157 if (!(V_UNION(pVar
, parray
) = SafeArrayCreate(VT_UI1
, 1, &bound
)))
158 return E_OUTOFMEMORY
;
162 res
= SafeArrayAccessData(V_UNION(pVar
, parray
), &pArrayElements
);
165 TRACE(" <- %lx\n", res
);
168 CopyMemory(pArrayElements
, wszData
, received
);
169 res
= SafeArrayUnaccessData(V_UNION(pVar
, parray
));
170 TRACE(" <- %lx\n", res
);
174 FIXME("Variant type %x not supported for regtype %lx\n", V_VT(pVar
), type
);
178 TRACE("<- %lx\n", res
);
182 static HRESULT WINAPI
DEVENUM_IPropertyBag_Write(
184 LPCOLESTR pszPropName
,
187 ICOM_THIS(RegPropBagImpl
, iface
);
188 LPVOID lpData
= NULL
;
193 TRACE("(%p)->(%s, %p)\n", This
, debugstr_w(pszPropName
), pVar
);
198 TRACE("writing %s\n", debugstr_w(V_UNION(pVar
, bstrVal
)));
199 lpData
= (LPVOID
)V_UNION(pVar
, bstrVal
);
201 cbData
= (lstrlenW(V_UNION(pVar
, bstrVal
)) + 1) * sizeof(WCHAR
);
205 lpData
= (LPVOID
)V_UNION(pVar
, ulVal
);
207 cbData
= sizeof(DWORD
);
209 case VT_ARRAY
| VT_UI1
:
214 res
= SafeArrayGetLBound(V_UNION(pVar
, parray
), 1, &lLbound
);
215 res
= SafeArrayGetUBound(V_UNION(pVar
, parray
), 1, &lUbound
);
216 cbData
= (lUbound
- lLbound
+ 1) /* * sizeof(BYTE)*/;
217 TRACE("cbData: %ld\n", cbData
);
218 res
= SafeArrayAccessData(V_UNION(pVar
, parray
), &lpData
);
222 FIXME("Variant type %d not handled\n", V_VT(pVar
));
226 if (RegSetValueExW(This
->hkey
,
228 dwType
, lpData
, cbData
) != ERROR_SUCCESS
)
231 if (V_VT(pVar
) & VT_ARRAY
)
232 res
= SafeArrayUnaccessData(V_UNION(pVar
, parray
));
237 static ICOM_VTABLE(IPropertyBag
) IPropertyBag_Vtbl
=
239 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
240 DEVENUM_IPropertyBag_QueryInterface
,
241 DEVENUM_IPropertyBag_AddRef
,
242 DEVENUM_IPropertyBag_Release
,
243 DEVENUM_IPropertyBag_Read
,
244 DEVENUM_IPropertyBag_Write
249 static HRESULT WINAPI
DEVENUM_IMediaCatMoniker_QueryInterface(
254 ICOM_THIS(MediaCatMoniker
, iface
);
255 TRACE("\n\tIID:\t%s\n",debugstr_guid(riid
));
257 if (This
== NULL
|| ppvObj
== NULL
) return E_POINTER
;
261 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
262 IsEqualGUID(riid
, &IID_IPersist
) ||
263 IsEqualGUID(riid
, &IID_IPersistStream
) ||
264 IsEqualGUID(riid
, &IID_IMoniker
))
266 *ppvObj
= (LPVOID
)iface
;
267 DEVENUM_IMediaCatMoniker_AddRef(iface
);
271 FIXME("- no interface\n\tIID:\t%s\n", debugstr_guid(riid
));
272 return E_NOINTERFACE
;
275 /**********************************************************************
276 * DEVENUM_IMediaCatMoniker_AddRef (also IUnknown)
278 static ULONG WINAPI
DEVENUM_IMediaCatMoniker_AddRef(LPMONIKER iface
)
280 ICOM_THIS(MediaCatMoniker
, iface
);
283 if (This
== NULL
) return E_POINTER
;
288 /**********************************************************************
289 * DEVENUM_IMediaCatMoniker_Release (also IUnknown)
291 static ULONG WINAPI
DEVENUM_IMediaCatMoniker_Release(LPMONIKER iface
)
293 ICOM_THIS(MediaCatMoniker
, iface
);
297 if (This
== NULL
) return E_POINTER
;
301 RegCloseKey(This
->hkey
);
307 static HRESULT WINAPI
DEVENUM_IMediaCatMoniker_GetClassID(
311 ICOM_THIS(MediaCatMoniker
, iface
);
312 FIXME("(%p)->(%p)\n", This
, pClassID
);
314 if (pClassID
== NULL
)
320 static HRESULT WINAPI
DEVENUM_IMediaCatMoniker_IsDirty(LPMONIKER iface
)
327 static HRESULT WINAPI
DEVENUM_IMediaCatMoniker_Load(LPMONIKER iface
, IStream
* pStm
)
329 FIXME("(%p)\n", pStm
);
334 static HRESULT WINAPI
DEVENUM_IMediaCatMoniker_Save(LPMONIKER iface
, IStream
* pStm
, BOOL fClearDirty
)
336 FIXME("(%p, %s)\n", pStm
, fClearDirty
? "true" : "false");
338 return STG_E_CANTSAVE
;
341 static HRESULT WINAPI
DEVENUM_IMediaCatMoniker_GetSizeMax(
343 ULARGE_INTEGER
* pcbSize
)
345 FIXME("(%p)\n", pcbSize
);
347 ZeroMemory(pcbSize
, sizeof(*pcbSize
));
352 static HRESULT WINAPI
DEVENUM_IMediaCatMoniker_BindToObject(
359 IUnknown
* pObj
= NULL
;
360 IPropertyBag
* pProp
= NULL
;
363 HRESULT res
= E_FAIL
;
365 ICOM_THIS(MediaCatMoniker
, iface
);
369 TRACE("(%p)->(%p, %p, %s, %p)\n", This
, pbc
, pmkToLeft
, debugstr_guid(riidResult
), ppvResult
);
375 /* first activation of this class */
377 res
=IMoniker_BindToStorage(iface
, NULL
, NULL
, &IID_IPropertyBag
, &pvptr
);
378 pProp
= (IPropertyBag
*)pvptr
;
381 V_VT(&var
) = VT_LPWSTR
;
382 res
= IPropertyBag_Read(pProp
, clsid_keyname
, &var
, NULL
);
386 res
= CLSIDFromString(V_UNION(&var
,bstrVal
), &clsID
);
387 CoTaskMemFree(V_UNION(&var
, bstrVal
));
391 res
=CoCreateInstance(&clsID
,NULL
,CLSCTX_ALL
,&IID_IUnknown
,&pvptr
);
392 pObj
= (IUnknown
*)pvptr
;
398 /* get the requested interface from the loaded class */
399 res
= IUnknown_QueryInterface(pObj
,riidResult
,ppvResult
);
404 IPropertyBag_Release(pProp
);
407 TRACE("<- 0x%lx\n", res
);
412 static HRESULT WINAPI
DEVENUM_IMediaCatMoniker_BindToStorage(
419 ICOM_THIS(MediaCatMoniker
, iface
);
420 TRACE("(%p)->(%p, %p, %s, %p)\n", This
, pbc
, pmkToLeft
, debugstr_guid(riid
), ppvObj
);
424 if (pbc
|| pmkToLeft
)
425 return MK_E_NOSTORAGE
;
427 if (IsEqualGUID(riid
, &IID_IPropertyBag
))
429 RegPropBagImpl
* rpb
= CoTaskMemAlloc(sizeof(RegPropBagImpl
));
431 return E_OUTOFMEMORY
;
432 rpb
->lpVtbl
= &IPropertyBag_Vtbl
;
433 DuplicateHandle(GetCurrentProcess(), This
->hkey
, GetCurrentProcess(), (LPHANDLE
)&(rpb
->hkey
), 0, 0, DUPLICATE_SAME_ACCESS
);
435 *ppvObj
= (LPVOID
)rpb
;
439 return MK_E_NOSTORAGE
;
442 static HRESULT WINAPI
DEVENUM_IMediaCatMoniker_Reduce(
445 DWORD dwReduceHowFar
,
446 IMoniker
** ppmkToLeft
,
447 IMoniker
** ppmkReduced
)
449 TRACE("(%p, %ld, %p, %p)\n", pbc
, dwReduceHowFar
, ppmkToLeft
, ppmkReduced
);
453 *ppmkReduced
= iface
;
455 return MK_S_REDUCED_TO_SELF
;
458 static HRESULT WINAPI
DEVENUM_IMediaCatMoniker_ComposeWith(
461 BOOL fOnlyIfNotGeneric
,
462 IMoniker
** ppmkComposite
)
464 FIXME("(%p, %s, %p): stub\n", pmkRight
, fOnlyIfNotGeneric
? "true" : "false", ppmkComposite
);
466 /* FIXME: use CreateGenericComposite? */
467 *ppmkComposite
= NULL
;
472 static HRESULT WINAPI
DEVENUM_IMediaCatMoniker_Enum(
475 IEnumMoniker
** ppenumMoniker
)
477 FIXME("(%s, %p): stub\n", fForward
? "true" : "false", ppenumMoniker
);
479 *ppenumMoniker
= NULL
;
484 static HRESULT WINAPI
DEVENUM_IMediaCatMoniker_IsEqual(
486 IMoniker
* pmkOtherMoniker
)
488 FIXME("(%p)\n", pmkOtherMoniker
);
493 static HRESULT WINAPI
DEVENUM_IMediaCatMoniker_Hash(
497 TRACE("(%p)\n", pdwHash
);
504 static HRESULT WINAPI
DEVENUM_IMediaCatMoniker_IsRunning(
508 IMoniker
* pmkNewlyRunning
)
510 FIXME("(%p, %p, %p)\n", pbc
, pmkToLeft
, pmkNewlyRunning
);
515 static HRESULT WINAPI
DEVENUM_IMediaCatMoniker_GetTimeOfLastChange(
521 TRACE("(%p, %p, %p)\n", pbc
, pmkToLeft
, pFileTime
);
523 pFileTime
->dwLowDateTime
= 0xFFFFFFFF;
524 pFileTime
->dwHighDateTime
= 0x7FFFFFFF;
526 return MK_E_UNAVAILABLE
;
529 static HRESULT WINAPI
DEVENUM_IMediaCatMoniker_Inverse(
533 TRACE("(%p)\n", ppmk
);
537 return MK_E_NOINVERSE
;
540 static HRESULT WINAPI
DEVENUM_IMediaCatMoniker_CommonPrefixWith(
542 IMoniker
* pmkOtherMoniker
,
543 IMoniker
** ppmkPrefix
)
545 TRACE("(%p, %p)\n", pmkOtherMoniker
, ppmkPrefix
);
549 return MK_E_NOPREFIX
;
552 static HRESULT WINAPI
DEVENUM_IMediaCatMoniker_RelativePathTo(
555 IMoniker
** ppmkRelPath
)
557 TRACE("(%p, %p)\n", pmkOther
, ppmkRelPath
);
559 *ppmkRelPath
= pmkOther
;
564 static HRESULT WINAPI
DEVENUM_IMediaCatMoniker_GetDisplayName(
568 LPOLESTR
* ppszDisplayName
)
570 ICOM_THIS(MediaCatMoniker
, iface
);
571 WCHAR wszBuffer
[MAX_PATH
];
572 const WCHAR wszFriendlyName
[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
573 LONG received
= sizeof(wszFriendlyName
);
575 TRACE("(%p, %p, %p)\n", pbc
, pmkToLeft
, ppszDisplayName
);
577 *ppszDisplayName
= NULL
;
579 /* FIXME: should this be the weird stuff we have to parse in IParseDisplayName? */
580 if (RegQueryValueW(This
->hkey
, wszFriendlyName
, wszBuffer
, &received
) == ERROR_SUCCESS
)
582 *ppszDisplayName
= CoTaskMemAlloc(received
);
583 strcpyW(*ppszDisplayName
, wszBuffer
);
590 static HRESULT WINAPI
DEVENUM_IMediaCatMoniker_ParseDisplayName(
594 LPOLESTR pszDisplayName
,
598 FIXME("(%p, %p, %s, %p, %p)\n", pbc
, pmkToLeft
, debugstr_w(pszDisplayName
), pchEaten
, ppmkOut
);
606 static HRESULT WINAPI
DEVENUM_IMediaCatMoniker_IsSystemMoniker(
610 TRACE("(%p)\n", pdwMksys
);
615 static ICOM_VTABLE(IMoniker
) IMoniker_Vtbl
=
617 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
618 DEVENUM_IMediaCatMoniker_QueryInterface
,
619 DEVENUM_IMediaCatMoniker_AddRef
,
620 DEVENUM_IMediaCatMoniker_Release
,
621 DEVENUM_IMediaCatMoniker_GetClassID
,
622 DEVENUM_IMediaCatMoniker_IsDirty
,
623 DEVENUM_IMediaCatMoniker_Load
,
624 DEVENUM_IMediaCatMoniker_Save
,
625 DEVENUM_IMediaCatMoniker_GetSizeMax
,
626 DEVENUM_IMediaCatMoniker_BindToObject
,
627 DEVENUM_IMediaCatMoniker_BindToStorage
,
628 DEVENUM_IMediaCatMoniker_Reduce
,
629 DEVENUM_IMediaCatMoniker_ComposeWith
,
630 DEVENUM_IMediaCatMoniker_Enum
,
631 DEVENUM_IMediaCatMoniker_IsEqual
,
632 DEVENUM_IMediaCatMoniker_Hash
,
633 DEVENUM_IMediaCatMoniker_IsRunning
,
634 DEVENUM_IMediaCatMoniker_GetTimeOfLastChange
,
635 DEVENUM_IMediaCatMoniker_Inverse
,
636 DEVENUM_IMediaCatMoniker_CommonPrefixWith
,
637 DEVENUM_IMediaCatMoniker_RelativePathTo
,
638 DEVENUM_IMediaCatMoniker_GetDisplayName
,
639 DEVENUM_IMediaCatMoniker_ParseDisplayName
,
640 DEVENUM_IMediaCatMoniker_IsSystemMoniker
643 MediaCatMoniker
* DEVENUM_IMediaCatMoniker_Construct()
645 MediaCatMoniker
* pMoniker
= NULL
;
646 pMoniker
= CoTaskMemAlloc(sizeof(MediaCatMoniker
));
650 pMoniker
->lpVtbl
= &IMoniker_Vtbl
;
652 pMoniker
->hkey
= NULL
;
654 DEVENUM_IMediaCatMoniker_AddRef((LPMONIKER
)pMoniker
);
659 /**********************************************************************
660 * DEVENUM_IEnumMoniker_QueryInterface (also IUnknown)
662 static HRESULT WINAPI
DEVENUM_IEnumMoniker_QueryInterface(
667 ICOM_THIS(EnumMonikerImpl
, iface
);
668 TRACE("\n\tIID:\t%s\n",debugstr_guid(riid
));
670 if (This
== NULL
|| ppvObj
== NULL
) return E_POINTER
;
672 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
673 IsEqualGUID(riid
, &IID_IEnumMoniker
))
675 *ppvObj
= (LPVOID
)iface
;
676 DEVENUM_IEnumMoniker_AddRef(iface
);
680 FIXME("- no interface\n\tIID:\t%s\n", debugstr_guid(riid
));
681 return E_NOINTERFACE
;
684 /**********************************************************************
685 * DEVENUM_IEnumMoniker_AddRef (also IUnknown)
687 static ULONG WINAPI
DEVENUM_IEnumMoniker_AddRef(LPENUMMONIKER iface
)
689 ICOM_THIS(EnumMonikerImpl
, iface
);
693 if (This
== NULL
) return E_POINTER
;
695 return InterlockedIncrement(&This
->ref
);
698 /**********************************************************************
699 * DEVENUM_IEnumMoniker_Release (also IUnknown)
701 static ULONG WINAPI
DEVENUM_IEnumMoniker_Release(LPENUMMONIKER iface
)
703 ICOM_THIS(EnumMonikerImpl
, iface
);
707 if (!InterlockedDecrement(&This
->ref
))
709 RegCloseKey(This
->hkey
);
716 static HRESULT WINAPI
DEVENUM_IEnumMoniker_Next(LPENUMMONIKER iface
, ULONG celt
, IMoniker
** rgelt
, ULONG
* pceltFetched
)
718 WCHAR buffer
[MAX_PATH
+ 1];
721 MediaCatMoniker
* pMoniker
;
722 ICOM_THIS(EnumMonikerImpl
, iface
);
724 TRACE("(%ld, %p, %p)\n", celt
, rgelt
, pceltFetched
);
726 while (fetched
< celt
)
728 res
= RegEnumKeyW(This
->hkey
, This
->index
, buffer
, sizeof(buffer
) / sizeof(WCHAR
));
729 if (res
!= ERROR_SUCCESS
)
733 pMoniker
= DEVENUM_IMediaCatMoniker_Construct();
735 return E_OUTOFMEMORY
;
737 if (RegOpenKeyW(This
->hkey
, buffer
, &pMoniker
->hkey
) != ERROR_SUCCESS
)
739 DEVENUM_IMediaCatMoniker_Release((LPMONIKER
)pMoniker
);
742 rgelt
[fetched
] = (LPMONIKER
)pMoniker
;
746 This
->index
+= fetched
;
748 TRACE("-- fetched %ld\n", fetched
);
751 *pceltFetched
= fetched
;
759 static HRESULT WINAPI
DEVENUM_IEnumMoniker_Skip(LPENUMMONIKER iface
, ULONG celt
)
761 ICOM_THIS(EnumMonikerImpl
, iface
);
763 TRACE("(%ld)\n", celt
);
770 static HRESULT WINAPI
DEVENUM_IEnumMoniker_Reset(LPENUMMONIKER iface
)
772 ICOM_THIS(EnumMonikerImpl
, iface
);
781 static HRESULT WINAPI
DEVENUM_IEnumMoniker_Clone(LPENUMMONIKER iface
, IEnumMoniker
** ppenum
)
783 FIXME("(%p): stub\n", ppenum
);
788 /**********************************************************************
791 ICOM_VTABLE(IEnumMoniker
) IEnumMoniker_Vtbl
=
793 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
794 DEVENUM_IEnumMoniker_QueryInterface
,
795 DEVENUM_IEnumMoniker_AddRef
,
796 DEVENUM_IEnumMoniker_Release
,
797 DEVENUM_IEnumMoniker_Next
,
798 DEVENUM_IEnumMoniker_Skip
,
799 DEVENUM_IEnumMoniker_Reset
,
800 DEVENUM_IEnumMoniker_Clone