gdi32: Consider whether the logical font face is vertical when selecting.
[wine/multimedia.git] / dlls / devenum / mediacatenum.c
blob7b44c13373aff051e1e51c53550376b3233f907b
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 IPropertyBag IPropertyBag_iface;
40 LONG ref;
41 HKEY hkey;
42 } RegPropBagImpl;
45 static inline RegPropBagImpl *impl_from_IPropertyBag(IPropertyBag *iface)
47 return CONTAINING_RECORD(iface, RegPropBagImpl, IPropertyBag_iface);
50 static HRESULT WINAPI DEVENUM_IPropertyBag_QueryInterface(
51 LPPROPERTYBAG iface,
52 REFIID riid,
53 LPVOID *ppvObj)
55 RegPropBagImpl *This = impl_from_IPropertyBag(iface);
57 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppvObj);
59 if (This == NULL || ppvObj == NULL) return E_POINTER;
61 if (IsEqualGUID(riid, &IID_IUnknown) ||
62 IsEqualGUID(riid, &IID_IPropertyBag))
64 *ppvObj = iface;
65 DEVENUM_IPropertyBag_AddRef(iface);
66 return S_OK;
69 FIXME("- no interface IID: %s\n", debugstr_guid(riid));
70 return E_NOINTERFACE;
73 /**********************************************************************
74 * DEVENUM_IPropertyBag_AddRef (also IUnknown)
76 static ULONG WINAPI DEVENUM_IPropertyBag_AddRef(LPPROPERTYBAG iface)
78 RegPropBagImpl *This = impl_from_IPropertyBag(iface);
80 TRACE("(%p)->() AddRef from %d\n", iface, This->ref);
82 return InterlockedIncrement(&This->ref);
85 /**********************************************************************
86 * DEVENUM_IPropertyBag_Release (also IUnknown)
88 static ULONG WINAPI DEVENUM_IPropertyBag_Release(LPPROPERTYBAG iface)
90 RegPropBagImpl *This = impl_from_IPropertyBag(iface);
91 ULONG ref;
93 TRACE("(%p)->() ReleaseThis->ref from %d\n", iface, This->ref);
95 ref = InterlockedDecrement(&This->ref);
96 if (ref == 0) {
97 RegCloseKey(This->hkey);
98 CoTaskMemFree(This);
99 DEVENUM_UnlockModule();
101 return ref;
104 static HRESULT WINAPI DEVENUM_IPropertyBag_Read(
105 LPPROPERTYBAG iface,
106 LPCOLESTR pszPropName,
107 VARIANT* pVar,
108 IErrorLog* pErrorLog)
110 LPVOID pData = NULL;
111 DWORD received;
112 DWORD type = 0;
113 RegPropBagImpl *This = impl_from_IPropertyBag(iface);
114 HRESULT res = S_OK;
115 LONG reswin32;
117 TRACE("(%p)->(%s, %p, %p)\n", This, debugstr_w(pszPropName), pVar, pErrorLog);
119 if (!pszPropName || !pVar)
120 return E_POINTER;
122 reswin32 = RegQueryValueExW(This->hkey, pszPropName, NULL, NULL, NULL, &received);
123 res = HRESULT_FROM_WIN32(reswin32);
125 if (SUCCEEDED(res))
127 pData = HeapAlloc(GetProcessHeap(), 0, received);
129 /* work around a GCC bug that occurs here unless we use the reswin32 variable as well */
130 reswin32 = RegQueryValueExW(This->hkey, pszPropName, NULL, &type, pData, &received);
131 res = HRESULT_FROM_WIN32(reswin32);
134 if (SUCCEEDED(res))
136 res = E_INVALIDARG; /* assume we cannot coerce into right type */
138 TRACE("Read %d bytes (%s)\n", received, type == REG_SZ ? debugstr_w(pData) : "binary data");
140 switch (type)
142 case REG_SZ:
143 switch (V_VT(pVar))
145 case VT_LPWSTR:
146 V_UNION(pVar, bstrVal) = CoTaskMemAlloc(received);
147 memcpy(V_UNION(pVar, bstrVal), pData, received);
148 res = S_OK;
149 break;
150 case VT_EMPTY:
151 V_VT(pVar) = VT_BSTR;
152 /* fall through */
153 case VT_BSTR:
154 V_UNION(pVar, bstrVal) = SysAllocStringLen(pData, received/sizeof(WCHAR) - 1);
155 res = S_OK;
156 break;
158 break;
159 case REG_DWORD:
160 TRACE("REG_DWORD: %x\n", *(DWORD *)pData);
161 switch (V_VT(pVar))
163 case VT_EMPTY:
164 V_VT(pVar) = VT_I4;
165 /* fall through */
166 case VT_I4:
167 case VT_UI4:
168 V_UNION(pVar, ulVal) = *(DWORD *)pData;
169 res = S_OK;
170 break;
172 break;
173 case REG_BINARY:
175 SAFEARRAYBOUND bound;
176 void * pArrayElements;
177 bound.lLbound = 0;
178 bound.cElements = received;
179 TRACE("REG_BINARY: len = %d\n", received);
180 switch (V_VT(pVar))
182 case VT_EMPTY:
183 V_VT(pVar) = VT_ARRAY | VT_UI1;
184 /* fall through */
185 case VT_ARRAY | VT_UI1:
186 if (!(V_UNION(pVar, parray) = SafeArrayCreate(VT_UI1, 1, &bound)))
187 res = E_OUTOFMEMORY;
188 else
189 res = S_OK;
190 break;
193 if (res == E_INVALIDARG)
194 break;
196 res = SafeArrayAccessData(V_UNION(pVar, parray), &pArrayElements);
197 if (FAILED(res))
198 break;
200 CopyMemory(pArrayElements, pData, received);
201 res = SafeArrayUnaccessData(V_UNION(pVar, parray));
202 break;
205 if (res == E_INVALIDARG)
206 FIXME("Variant type %x not supported for regtype %x\n", V_VT(pVar), type);
209 HeapFree(GetProcessHeap(), 0, pData);
211 TRACE("<- %x\n", res);
212 return res;
215 static HRESULT WINAPI DEVENUM_IPropertyBag_Write(
216 LPPROPERTYBAG iface,
217 LPCOLESTR pszPropName,
218 VARIANT* pVar)
220 RegPropBagImpl *This = impl_from_IPropertyBag(iface);
221 LPVOID lpData = NULL;
222 DWORD cbData = 0;
223 DWORD dwType = 0;
224 HRESULT res = S_OK;
226 TRACE("(%p)->(%s, %p)\n", This, debugstr_w(pszPropName), pVar);
228 switch (V_VT(pVar))
230 case VT_BSTR:
231 TRACE("writing %s\n", debugstr_w(V_UNION(pVar, bstrVal)));
232 lpData = V_UNION(pVar, bstrVal);
233 dwType = REG_SZ;
234 cbData = (lstrlenW(V_UNION(pVar, bstrVal)) + 1) * sizeof(WCHAR);
235 break;
236 case VT_I4:
237 case VT_UI4:
238 TRACE("writing %u\n", V_UNION(pVar, ulVal));
239 lpData = &V_UNION(pVar, ulVal);
240 dwType = REG_DWORD;
241 cbData = sizeof(DWORD);
242 break;
243 case VT_ARRAY | VT_UI1:
245 LONG lUbound = 0;
246 LONG lLbound = 0;
247 dwType = REG_BINARY;
248 res = SafeArrayGetLBound(V_UNION(pVar, parray), 1, &lLbound);
249 res = SafeArrayGetUBound(V_UNION(pVar, parray), 1, &lUbound);
250 cbData = (lUbound - lLbound + 1) /* * sizeof(BYTE)*/;
251 TRACE("cbData: %d\n", cbData);
252 res = SafeArrayAccessData(V_UNION(pVar, parray), &lpData);
253 break;
255 default:
256 FIXME("Variant type %d not handled\n", V_VT(pVar));
257 return E_FAIL;
260 if (RegSetValueExW(This->hkey,
261 pszPropName, 0,
262 dwType, lpData, cbData) != ERROR_SUCCESS)
263 res = E_FAIL;
265 if (V_VT(pVar) & VT_ARRAY)
266 res = SafeArrayUnaccessData(V_UNION(pVar, parray));
268 return res;
271 static const IPropertyBagVtbl IPropertyBag_Vtbl =
273 DEVENUM_IPropertyBag_QueryInterface,
274 DEVENUM_IPropertyBag_AddRef,
275 DEVENUM_IPropertyBag_Release,
276 DEVENUM_IPropertyBag_Read,
277 DEVENUM_IPropertyBag_Write
280 static HRESULT DEVENUM_IPropertyBag_Construct(HANDLE hkey, IPropertyBag **ppBag)
282 RegPropBagImpl * rpb = CoTaskMemAlloc(sizeof(RegPropBagImpl));
283 if (!rpb)
284 return E_OUTOFMEMORY;
285 rpb->IPropertyBag_iface.lpVtbl = &IPropertyBag_Vtbl;
286 rpb->ref = 1;
287 rpb->hkey = hkey;
288 *ppBag = &rpb->IPropertyBag_iface;
289 DEVENUM_LockModule();
290 return S_OK;
294 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_QueryInterface(
295 LPMONIKER iface,
296 REFIID riid,
297 LPVOID *ppvObj)
299 MediaCatMoniker *This = (MediaCatMoniker *)iface;
300 TRACE("\n\tIID:\t%s\n",debugstr_guid(riid));
302 if (This == NULL || ppvObj == NULL) return E_POINTER;
304 *ppvObj = NULL;
306 if (IsEqualGUID(riid, &IID_IUnknown) ||
307 IsEqualGUID(riid, &IID_IPersist) ||
308 IsEqualGUID(riid, &IID_IPersistStream) ||
309 IsEqualGUID(riid, &IID_IMoniker))
311 *ppvObj = iface;
312 DEVENUM_IMediaCatMoniker_AddRef(iface);
313 return S_OK;
316 FIXME("- no interface IID: %s\n", debugstr_guid(riid));
317 return E_NOINTERFACE;
320 /**********************************************************************
321 * DEVENUM_IMediaCatMoniker_AddRef (also IUnknown)
323 static ULONG WINAPI DEVENUM_IMediaCatMoniker_AddRef(LPMONIKER iface)
325 MediaCatMoniker *This = (MediaCatMoniker *)iface;
326 TRACE("\n");
328 return InterlockedIncrement(&This->ref);
331 /**********************************************************************
332 * DEVENUM_IMediaCatMoniker_Release (also IUnknown)
334 static ULONG WINAPI DEVENUM_IMediaCatMoniker_Release(LPMONIKER iface)
336 MediaCatMoniker *This = (MediaCatMoniker *)iface;
337 ULONG ref;
338 TRACE("\n");
340 ref = InterlockedDecrement(&This->ref);
341 if (ref == 0) {
342 RegCloseKey(This->hkey);
343 CoTaskMemFree(This);
344 DEVENUM_UnlockModule();
346 return ref;
349 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_GetClassID(
350 LPMONIKER iface,
351 CLSID* pClassID)
353 MediaCatMoniker *This = (MediaCatMoniker *)iface;
354 FIXME("(%p)->(%p): stub\n", This, pClassID);
356 if (pClassID == NULL)
357 return E_POINTER;
359 return E_NOTIMPL;
362 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_IsDirty(LPMONIKER iface)
364 FIXME("(%p)->(): stub\n", iface);
366 return S_FALSE;
369 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_Load(LPMONIKER iface, IStream* pStm)
371 FIXME("(%p)->(%p): stub\n", iface, pStm);
373 return E_NOTIMPL;
376 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_Save(LPMONIKER iface, IStream* pStm, BOOL fClearDirty)
378 FIXME("(%p)->(%p, %s): stub\n", iface, pStm, fClearDirty ? "true" : "false");
380 return STG_E_CANTSAVE;
383 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_GetSizeMax(
384 LPMONIKER iface,
385 ULARGE_INTEGER* pcbSize)
387 FIXME("(%p)->(%p): stub\n", iface, pcbSize);
389 ZeroMemory(pcbSize, sizeof(*pcbSize));
391 return S_OK;
394 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_BindToObject(
395 LPMONIKER iface,
396 IBindCtx* pbc,
397 IMoniker* pmkToLeft,
398 REFIID riidResult,
399 void** ppvResult)
401 IUnknown * pObj = NULL;
402 IPropertyBag * pProp = NULL;
403 CLSID clsID;
404 VARIANT var;
405 HRESULT res = E_FAIL;
407 MediaCatMoniker *This = (MediaCatMoniker *)iface;
409 VariantInit(&var);
411 TRACE("(%p)->(%p, %p, %s, %p)\n", This, pbc, pmkToLeft, debugstr_guid(riidResult), ppvResult);
413 *ppvResult = NULL;
415 if(pmkToLeft==NULL)
417 /* first activation of this class */
418 LPVOID pvptr;
419 res=IMoniker_BindToStorage(iface, NULL, NULL, &IID_IPropertyBag, &pvptr);
420 pProp = pvptr;
421 if (SUCCEEDED(res))
423 V_VT(&var) = VT_LPWSTR;
424 res = IPropertyBag_Read(pProp, clsid_keyname, &var, NULL);
426 if (SUCCEEDED(res))
428 res = CLSIDFromString(V_UNION(&var,bstrVal), &clsID);
429 CoTaskMemFree(V_UNION(&var, bstrVal));
431 if (SUCCEEDED(res))
433 res=CoCreateInstance(&clsID,NULL,CLSCTX_ALL,&IID_IUnknown,&pvptr);
434 pObj = pvptr;
438 if (pObj!=NULL)
440 /* get the requested interface from the loaded class */
441 res = S_OK;
442 if (pProp) {
443 HRESULT res2;
444 LPVOID ppv = NULL;
445 res2 = IUnknown_QueryInterface(pObj, &IID_IPersistPropertyBag, &ppv);
446 if (SUCCEEDED(res2)) {
447 res = IPersistPropertyBag_Load((IPersistPropertyBag *) ppv, pProp, NULL);
448 IPersistPropertyBag_Release((IPersistPropertyBag *) ppv);
451 if (SUCCEEDED(res))
452 res= IUnknown_QueryInterface(pObj,riidResult,ppvResult);
453 IUnknown_Release(pObj);
456 if (pProp)
458 IPropertyBag_Release(pProp);
461 TRACE("<- 0x%x\n", res);
463 return res;
466 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_BindToStorage(
467 LPMONIKER iface,
468 IBindCtx* pbc,
469 IMoniker* pmkToLeft,
470 REFIID riid,
471 void** ppvObj)
473 MediaCatMoniker *This = (MediaCatMoniker *)iface;
474 TRACE("(%p)->(%p, %p, %s, %p)\n", This, pbc, pmkToLeft, debugstr_guid(riid), ppvObj);
476 *ppvObj = NULL;
478 if (pbc || pmkToLeft)
479 return MK_E_NOSTORAGE;
481 if (IsEqualGUID(riid, &IID_IPropertyBag))
483 HANDLE hkey;
484 DuplicateHandle(GetCurrentProcess(), This->hkey, GetCurrentProcess(), &hkey, 0, 0, DUPLICATE_SAME_ACCESS);
485 return DEVENUM_IPropertyBag_Construct(hkey, (IPropertyBag**)ppvObj);
488 return MK_E_NOSTORAGE;
491 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_Reduce(
492 LPMONIKER iface,
493 IBindCtx* pbc,
494 DWORD dwReduceHowFar,
495 IMoniker** ppmkToLeft,
496 IMoniker** ppmkReduced)
498 TRACE("(%p)->(%p, %d, %p, %p)\n", iface, pbc, dwReduceHowFar, ppmkToLeft, ppmkReduced);
500 if (ppmkToLeft)
501 *ppmkToLeft = NULL;
502 *ppmkReduced = iface;
504 return MK_S_REDUCED_TO_SELF;
507 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_ComposeWith(
508 LPMONIKER iface,
509 IMoniker* pmkRight,
510 BOOL fOnlyIfNotGeneric,
511 IMoniker** ppmkComposite)
513 FIXME("(%p)->(%p, %s, %p): stub\n", iface, pmkRight, fOnlyIfNotGeneric ? "true" : "false", ppmkComposite);
515 /* FIXME: use CreateGenericComposite? */
516 *ppmkComposite = NULL;
518 return E_NOTIMPL;
521 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_Enum(
522 LPMONIKER iface,
523 BOOL fForward,
524 IEnumMoniker** ppenumMoniker)
526 FIXME("(%p)->(%s, %p): stub\n", iface, fForward ? "true" : "false", ppenumMoniker);
528 *ppenumMoniker = NULL;
530 return S_OK;
533 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_IsEqual(
534 LPMONIKER iface,
535 IMoniker* pmkOtherMoniker)
537 FIXME("(%p)->(%p): stub\n", iface, pmkOtherMoniker);
539 return E_NOTIMPL;
542 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_Hash(
543 LPMONIKER iface,
544 DWORD* pdwHash)
546 TRACE("(%p)->(%p)\n", iface, pdwHash);
548 *pdwHash = 0;
550 return S_OK;
553 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_IsRunning(
554 LPMONIKER iface,
555 IBindCtx* pbc,
556 IMoniker* pmkToLeft,
557 IMoniker* pmkNewlyRunning)
559 FIXME("(%p)->(%p, %p, %p): stub\n", iface, pbc, pmkToLeft, pmkNewlyRunning);
561 return S_FALSE;
564 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_GetTimeOfLastChange(
565 LPMONIKER iface,
566 IBindCtx* pbc,
567 IMoniker* pmkToLeft,
568 FILETIME* pFileTime)
570 TRACE("(%p)->(%p, %p, %p)\n", iface, pbc, pmkToLeft, pFileTime);
572 pFileTime->dwLowDateTime = 0xFFFFFFFF;
573 pFileTime->dwHighDateTime = 0x7FFFFFFF;
575 return MK_E_UNAVAILABLE;
578 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_Inverse(
579 LPMONIKER iface,
580 IMoniker** ppmk)
582 TRACE("(%p)->(%p)\n", iface, ppmk);
584 *ppmk = NULL;
586 return MK_E_NOINVERSE;
589 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_CommonPrefixWith(
590 LPMONIKER iface,
591 IMoniker* pmkOtherMoniker,
592 IMoniker** ppmkPrefix)
594 TRACE("(%p)->(%p, %p)\n", iface, pmkOtherMoniker, ppmkPrefix);
596 *ppmkPrefix = NULL;
598 return MK_E_NOPREFIX;
601 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_RelativePathTo(
602 LPMONIKER iface,
603 IMoniker* pmkOther,
604 IMoniker** ppmkRelPath)
606 TRACE("(%p)->(%p, %p)\n", iface, pmkOther, ppmkRelPath);
608 *ppmkRelPath = pmkOther;
610 return MK_S_HIM;
613 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_GetDisplayName(
614 LPMONIKER iface,
615 IBindCtx* pbc,
616 IMoniker* pmkToLeft,
617 LPOLESTR* ppszDisplayName)
619 MediaCatMoniker *This = (MediaCatMoniker *)iface;
620 WCHAR wszBuffer[MAX_PATH];
621 static const WCHAR wszFriendlyName[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
622 LONG received = sizeof(wszFriendlyName);
624 TRACE("(%p)->(%p, %p, %p)\n", iface, pbc, pmkToLeft, ppszDisplayName);
626 *ppszDisplayName = NULL;
628 /* FIXME: should this be the weird stuff we have to parse in IParseDisplayName? */
629 if (RegQueryValueW(This->hkey, wszFriendlyName, wszBuffer, &received) == ERROR_SUCCESS)
631 *ppszDisplayName = CoTaskMemAlloc(received);
632 strcpyW(*ppszDisplayName, wszBuffer);
633 return S_OK;
636 return E_FAIL;
639 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_ParseDisplayName(
640 LPMONIKER iface,
641 IBindCtx* pbc,
642 IMoniker* pmkToLeft,
643 LPOLESTR pszDisplayName,
644 ULONG* pchEaten,
645 IMoniker** ppmkOut)
647 FIXME("(%p)->(%p, %p, %s, %p, %p)\n", iface, pbc, pmkToLeft, debugstr_w(pszDisplayName), pchEaten, ppmkOut);
649 *pchEaten = 0;
650 *ppmkOut = NULL;
652 return MK_E_SYNTAX;
655 static HRESULT WINAPI DEVENUM_IMediaCatMoniker_IsSystemMoniker(
656 LPMONIKER iface,
657 DWORD* pdwMksys)
659 TRACE("(%p)->(%p)\n", iface, pdwMksys);
661 return S_FALSE;
664 static const IMonikerVtbl IMoniker_Vtbl =
666 DEVENUM_IMediaCatMoniker_QueryInterface,
667 DEVENUM_IMediaCatMoniker_AddRef,
668 DEVENUM_IMediaCatMoniker_Release,
669 DEVENUM_IMediaCatMoniker_GetClassID,
670 DEVENUM_IMediaCatMoniker_IsDirty,
671 DEVENUM_IMediaCatMoniker_Load,
672 DEVENUM_IMediaCatMoniker_Save,
673 DEVENUM_IMediaCatMoniker_GetSizeMax,
674 DEVENUM_IMediaCatMoniker_BindToObject,
675 DEVENUM_IMediaCatMoniker_BindToStorage,
676 DEVENUM_IMediaCatMoniker_Reduce,
677 DEVENUM_IMediaCatMoniker_ComposeWith,
678 DEVENUM_IMediaCatMoniker_Enum,
679 DEVENUM_IMediaCatMoniker_IsEqual,
680 DEVENUM_IMediaCatMoniker_Hash,
681 DEVENUM_IMediaCatMoniker_IsRunning,
682 DEVENUM_IMediaCatMoniker_GetTimeOfLastChange,
683 DEVENUM_IMediaCatMoniker_Inverse,
684 DEVENUM_IMediaCatMoniker_CommonPrefixWith,
685 DEVENUM_IMediaCatMoniker_RelativePathTo,
686 DEVENUM_IMediaCatMoniker_GetDisplayName,
687 DEVENUM_IMediaCatMoniker_ParseDisplayName,
688 DEVENUM_IMediaCatMoniker_IsSystemMoniker
691 MediaCatMoniker * DEVENUM_IMediaCatMoniker_Construct(void)
693 MediaCatMoniker * pMoniker = NULL;
694 pMoniker = CoTaskMemAlloc(sizeof(MediaCatMoniker));
695 if (!pMoniker)
696 return NULL;
698 pMoniker->lpVtbl = &IMoniker_Vtbl;
699 pMoniker->ref = 0;
700 pMoniker->hkey = NULL;
702 DEVENUM_IMediaCatMoniker_AddRef((LPMONIKER)pMoniker);
704 DEVENUM_LockModule();
706 return pMoniker;
709 /**********************************************************************
710 * DEVENUM_IEnumMoniker_QueryInterface (also IUnknown)
712 static HRESULT WINAPI DEVENUM_IEnumMoniker_QueryInterface(
713 LPENUMMONIKER iface,
714 REFIID riid,
715 LPVOID *ppvObj)
717 EnumMonikerImpl *This = (EnumMonikerImpl *)iface;
719 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppvObj);
721 if (This == NULL || ppvObj == NULL) return E_POINTER;
723 if (IsEqualGUID(riid, &IID_IUnknown) ||
724 IsEqualGUID(riid, &IID_IEnumMoniker))
726 *ppvObj = iface;
727 DEVENUM_IEnumMoniker_AddRef(iface);
728 return S_OK;
731 FIXME("- no interface IID: %s\n", debugstr_guid(riid));
732 return E_NOINTERFACE;
735 /**********************************************************************
736 * DEVENUM_IEnumMoniker_AddRef (also IUnknown)
738 static ULONG WINAPI DEVENUM_IEnumMoniker_AddRef(LPENUMMONIKER iface)
740 EnumMonikerImpl *This = (EnumMonikerImpl *)iface;
741 ULONG ref = InterlockedIncrement(&This->ref);
743 TRACE("(%p)->() AddRef from %d\n", iface, ref - 1);
745 return ref;
748 /**********************************************************************
749 * DEVENUM_IEnumMoniker_Release (also IUnknown)
751 static ULONG WINAPI DEVENUM_IEnumMoniker_Release(LPENUMMONIKER iface)
753 EnumMonikerImpl *This = (EnumMonikerImpl *)iface;
754 ULONG ref = InterlockedDecrement(&This->ref);
756 TRACE("(%p)->() Release from %d\n", iface, ref + 1);
758 if (!ref)
760 RegCloseKey(This->hkey);
761 CoTaskMemFree(This);
762 DEVENUM_UnlockModule();
763 return 0;
765 return ref;
768 static HRESULT WINAPI DEVENUM_IEnumMoniker_Next(LPENUMMONIKER iface, ULONG celt, IMoniker ** rgelt, ULONG * pceltFetched)
770 WCHAR buffer[MAX_PATH + 1];
771 LONG res;
772 ULONG fetched = 0;
773 MediaCatMoniker * pMoniker;
774 EnumMonikerImpl *This = (EnumMonikerImpl *)iface;
776 TRACE("(%p)->(%d, %p, %p)\n", iface, celt, rgelt, pceltFetched);
778 while (fetched < celt)
780 res = RegEnumKeyW(This->hkey, This->index, buffer, sizeof(buffer) / sizeof(WCHAR));
781 if (res != ERROR_SUCCESS)
783 break;
785 pMoniker = DEVENUM_IMediaCatMoniker_Construct();
786 if (!pMoniker)
787 return E_OUTOFMEMORY;
789 if (RegOpenKeyW(This->hkey, buffer, &pMoniker->hkey) != ERROR_SUCCESS)
791 DEVENUM_IMediaCatMoniker_Release((LPMONIKER)pMoniker);
792 break;
794 rgelt[fetched] = (LPMONIKER)pMoniker;
795 fetched++;
798 This->index += fetched;
800 TRACE("-- fetched %d\n", fetched);
802 if (pceltFetched)
803 *pceltFetched = fetched;
805 if (fetched != celt)
806 return S_FALSE;
807 else
808 return S_OK;
811 static HRESULT WINAPI DEVENUM_IEnumMoniker_Skip(LPENUMMONIKER iface, ULONG celt)
813 EnumMonikerImpl *This = (EnumMonikerImpl *)iface;
814 DWORD subKeys;
816 TRACE("(%p)->(%d)\n", iface, celt);
818 /* Before incrementing, check if there are any more values to run thru.
819 Some programs use the Skip() function to get the amount of devices */
820 if(RegQueryInfoKeyW(This->hkey, NULL, NULL, NULL, &subKeys, NULL, NULL, NULL, NULL, NULL, NULL, NULL) != ERROR_SUCCESS)
822 return S_FALSE;
824 if((This->index + celt) >= subKeys)
826 return S_FALSE;
829 This->index += celt;
831 return S_OK;
834 static HRESULT WINAPI DEVENUM_IEnumMoniker_Reset(LPENUMMONIKER iface)
836 EnumMonikerImpl *This = (EnumMonikerImpl *)iface;
838 TRACE("(%p)->()\n", iface);
840 This->index = 0;
842 return S_OK;
845 static HRESULT WINAPI DEVENUM_IEnumMoniker_Clone(LPENUMMONIKER iface, IEnumMoniker ** ppenum)
847 FIXME("(%p)->(%p): stub\n", iface, ppenum);
849 return E_NOTIMPL;
852 /**********************************************************************
853 * IEnumMoniker_Vtbl
855 static const IEnumMonikerVtbl IEnumMoniker_Vtbl =
857 DEVENUM_IEnumMoniker_QueryInterface,
858 DEVENUM_IEnumMoniker_AddRef,
859 DEVENUM_IEnumMoniker_Release,
860 DEVENUM_IEnumMoniker_Next,
861 DEVENUM_IEnumMoniker_Skip,
862 DEVENUM_IEnumMoniker_Reset,
863 DEVENUM_IEnumMoniker_Clone
866 HRESULT DEVENUM_IEnumMoniker_Construct(HKEY hkey, IEnumMoniker ** ppEnumMoniker)
868 EnumMonikerImpl * pEnumMoniker = CoTaskMemAlloc(sizeof(EnumMonikerImpl));
869 if (!pEnumMoniker)
870 return E_OUTOFMEMORY;
872 pEnumMoniker->lpVtbl = &IEnumMoniker_Vtbl;
873 pEnumMoniker->ref = 1;
874 pEnumMoniker->index = 0;
875 pEnumMoniker->hkey = hkey;
877 *ppEnumMoniker = (IEnumMoniker *)pEnumMoniker;
879 DEVENUM_LockModule();
881 return S_OK;