shell32: Implement SHCreateItemInKnownFolder.
[wine.git] / dlls / shell32 / shellitem.c
blob8fc767eae1cb15e2e72e581a9462a375b981b2c1
1 /*
2 * IShellItem and IShellItemArray implementations
4 * Copyright 2008 Vincent Povirk for CodeWeavers
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
21 #include "config.h"
22 #include "wine/port.h"
24 #include <stdio.h>
25 #include <stdarg.h>
27 #define COBJMACROS
28 #define NONAMELESSUNION
30 #include "windef.h"
31 #include "winbase.h"
32 #include "wine/debug.h"
34 #include "pidl.h"
35 #include "shell32_main.h"
36 #include "debughlp.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(shell);
40 typedef struct _ShellItem {
41 IShellItem2 IShellItem2_iface;
42 LONG ref;
43 LPITEMIDLIST pidl;
44 IPersistIDList IPersistIDList_iface;
45 } ShellItem;
47 typedef struct _CustomDestinationList {
48 ICustomDestinationList ICustomDestinationList_iface;
49 LONG ref;
50 } CustomDestinationList;
52 static inline ShellItem *impl_from_IShellItem2(IShellItem2 *iface)
54 return CONTAINING_RECORD(iface, ShellItem, IShellItem2_iface);
57 static inline ShellItem *impl_from_IPersistIDList( IPersistIDList *iface )
59 return CONTAINING_RECORD(iface, ShellItem, IPersistIDList_iface);
62 static inline CustomDestinationList *impl_from_ICustomDestinationList( ICustomDestinationList *iface )
64 return CONTAINING_RECORD(iface, CustomDestinationList, ICustomDestinationList_iface);
67 static HRESULT WINAPI ShellItem_QueryInterface(IShellItem2 *iface, REFIID riid,
68 void **ppv)
70 ShellItem *This = impl_from_IShellItem2(iface);
72 TRACE("(%p, %s, %p)\n", iface, debugstr_guid(riid), ppv);
74 if (!ppv) return E_INVALIDARG;
76 if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IShellItem, riid) ||
77 IsEqualIID(&IID_IShellItem2, riid))
79 *ppv = &This->IShellItem2_iface;
81 else if (IsEqualIID(&IID_IPersist, riid) || IsEqualIID(&IID_IPersistIDList, riid))
83 *ppv = &This->IPersistIDList_iface;
85 else {
86 FIXME("not implemented for %s\n", shdebugstr_guid(riid));
87 *ppv = NULL;
88 return E_NOINTERFACE;
91 IUnknown_AddRef((IUnknown*)*ppv);
92 return S_OK;
95 static ULONG WINAPI ShellItem_AddRef(IShellItem2 *iface)
97 ShellItem *This = impl_from_IShellItem2(iface);
98 ULONG ref = InterlockedIncrement(&This->ref);
100 TRACE("(%p), new refcount=%i\n", iface, ref);
102 return ref;
105 static ULONG WINAPI ShellItem_Release(IShellItem2 *iface)
107 ShellItem *This = impl_from_IShellItem2(iface);
108 ULONG ref = InterlockedDecrement(&This->ref);
110 TRACE("(%p), new refcount=%i\n", iface, ref);
112 if (ref == 0)
114 ILFree(This->pidl);
115 HeapFree(GetProcessHeap(), 0, This);
118 return ref;
121 static HRESULT ShellItem_get_parent_pidl(ShellItem *This, LPITEMIDLIST *parent_pidl)
123 *parent_pidl = ILClone(This->pidl);
124 if (*parent_pidl)
126 if (ILRemoveLastID(*parent_pidl))
127 return S_OK;
128 else
130 ILFree(*parent_pidl);
131 *parent_pidl = NULL;
132 return E_INVALIDARG;
135 else
137 *parent_pidl = NULL;
138 return E_OUTOFMEMORY;
142 static HRESULT ShellItem_get_parent_shellfolder(ShellItem *This, IShellFolder **ppsf)
144 LPITEMIDLIST parent_pidl;
145 IShellFolder *desktop;
146 HRESULT ret;
148 ret = ShellItem_get_parent_pidl(This, &parent_pidl);
149 if (SUCCEEDED(ret))
151 ret = SHGetDesktopFolder(&desktop);
152 if (SUCCEEDED(ret))
154 if (_ILIsDesktop(parent_pidl))
156 *ppsf = desktop;
158 else
160 ret = IShellFolder_BindToObject(desktop, parent_pidl, NULL, &IID_IShellFolder, (void**)ppsf);
161 IShellFolder_Release(desktop);
164 ILFree(parent_pidl);
167 return ret;
170 static HRESULT ShellItem_get_shellfolder(ShellItem *This, IBindCtx *pbc, IShellFolder **ppsf)
172 IShellFolder *desktop;
173 HRESULT ret;
175 ret = SHGetDesktopFolder(&desktop);
176 if (SUCCEEDED(ret))
178 if (_ILIsDesktop(This->pidl))
180 *ppsf = desktop;
181 IShellFolder_AddRef(*ppsf);
183 else
185 ret = IShellFolder_BindToObject(desktop, This->pidl, pbc, &IID_IShellFolder, (void**)ppsf);
188 IShellFolder_Release(desktop);
191 return ret;
194 static HRESULT WINAPI ShellItem_BindToHandler(IShellItem2 *iface, IBindCtx *pbc,
195 REFGUID rbhid, REFIID riid, void **ppvOut)
197 ShellItem *This = impl_from_IShellItem2(iface);
198 HRESULT ret;
199 TRACE("(%p,%p,%s,%p,%p)\n", iface, pbc, shdebugstr_guid(rbhid), riid, ppvOut);
201 *ppvOut = NULL;
202 if (IsEqualGUID(rbhid, &BHID_SFObject))
204 IShellFolder *psf;
205 ret = ShellItem_get_shellfolder(This, pbc, &psf);
206 if (SUCCEEDED(ret))
208 ret = IShellFolder_QueryInterface(psf, riid, ppvOut);
209 IShellFolder_Release(psf);
211 return ret;
213 else if (IsEqualGUID(rbhid, &BHID_SFUIObject))
215 IShellFolder *psf_parent;
216 if (_ILIsDesktop(This->pidl))
217 ret = SHGetDesktopFolder(&psf_parent);
218 else
219 ret = ShellItem_get_parent_shellfolder(This, &psf_parent);
221 if (SUCCEEDED(ret))
223 LPCITEMIDLIST pidl = ILFindLastID(This->pidl);
224 ret = IShellFolder_GetUIObjectOf(psf_parent, NULL, 1, &pidl, riid, NULL, ppvOut);
225 IShellFolder_Release(psf_parent);
227 return ret;
229 else if (IsEqualGUID(rbhid, &BHID_DataObject))
231 return ShellItem_BindToHandler(&This->IShellItem2_iface, pbc, &BHID_SFUIObject,
232 &IID_IDataObject, ppvOut);
235 FIXME("Unsupported BHID %s.\n", debugstr_guid(rbhid));
237 return MK_E_NOOBJECT;
240 static HRESULT WINAPI ShellItem_GetParent(IShellItem2 *iface, IShellItem **ppsi)
242 ShellItem *This = impl_from_IShellItem2(iface);
243 LPITEMIDLIST parent_pidl;
244 HRESULT ret;
246 TRACE("(%p,%p)\n", iface, ppsi);
248 ret = ShellItem_get_parent_pidl(This, &parent_pidl);
249 if (SUCCEEDED(ret))
251 ret = SHCreateShellItem(NULL, NULL, parent_pidl, ppsi);
252 ILFree(parent_pidl);
255 return ret;
258 static HRESULT WINAPI ShellItem_GetDisplayName(IShellItem2 *iface, SIGDN sigdnName,
259 LPWSTR *ppszName)
261 ShellItem *This = impl_from_IShellItem2(iface);
262 TRACE("(%p,%x,%p)\n", iface, sigdnName, ppszName);
264 return SHGetNameFromIDList(This->pidl, sigdnName, ppszName);
267 static HRESULT WINAPI ShellItem_GetAttributes(IShellItem2 *iface, SFGAOF sfgaoMask,
268 SFGAOF *psfgaoAttribs)
270 ShellItem *This = impl_from_IShellItem2(iface);
271 IShellFolder *parent_folder;
272 LPITEMIDLIST child_pidl;
273 HRESULT ret;
275 TRACE("(%p,%x,%p)\n", iface, sfgaoMask, psfgaoAttribs);
277 if (_ILIsDesktop(This->pidl))
278 ret = SHGetDesktopFolder(&parent_folder);
279 else
280 ret = ShellItem_get_parent_shellfolder(This, &parent_folder);
281 if (SUCCEEDED(ret))
283 child_pidl = ILFindLastID(This->pidl);
284 *psfgaoAttribs = sfgaoMask;
285 ret = IShellFolder_GetAttributesOf(parent_folder, 1, (LPCITEMIDLIST*)&child_pidl, psfgaoAttribs);
286 *psfgaoAttribs &= sfgaoMask;
287 IShellFolder_Release(parent_folder);
289 if (SUCCEEDED(ret))
291 if(sfgaoMask == *psfgaoAttribs)
292 return S_OK;
293 else
294 return S_FALSE;
298 return ret;
301 static HRESULT WINAPI ShellItem_Compare(IShellItem2 *iface, IShellItem *oth,
302 SICHINTF hint, int *piOrder)
304 LPWSTR dispname, dispname_oth;
305 HRESULT ret;
306 TRACE("(%p,%p,%x,%p)\n", iface, oth, hint, piOrder);
308 if(hint & (SICHINT_CANONICAL | SICHINT_ALLFIELDS))
309 FIXME("Unsupported flags 0x%08x\n", hint);
311 ret = IShellItem2_GetDisplayName(iface, SIGDN_DESKTOPABSOLUTEEDITING, &dispname);
312 if(SUCCEEDED(ret))
314 ret = IShellItem_GetDisplayName(oth, SIGDN_DESKTOPABSOLUTEEDITING, &dispname_oth);
315 if(SUCCEEDED(ret))
317 *piOrder = lstrcmpiW(dispname, dispname_oth);
318 CoTaskMemFree(dispname_oth);
320 CoTaskMemFree(dispname);
323 if(SUCCEEDED(ret) && *piOrder &&
324 (hint & SICHINT_TEST_FILESYSPATH_IF_NOT_EQUAL))
326 LPWSTR dispname, dispname_oth;
328 TRACE("Testing filesystem path.\n");
329 ret = IShellItem2_GetDisplayName(iface, SIGDN_FILESYSPATH, &dispname);
330 if(SUCCEEDED(ret))
332 ret = IShellItem_GetDisplayName(oth, SIGDN_FILESYSPATH, &dispname_oth);
333 if(SUCCEEDED(ret))
335 *piOrder = lstrcmpiW(dispname, dispname_oth);
336 CoTaskMemFree(dispname_oth);
338 CoTaskMemFree(dispname);
342 if(FAILED(ret))
343 return ret;
345 if(*piOrder)
346 return S_FALSE;
347 else
348 return S_OK;
351 static HRESULT WINAPI ShellItem2_GetPropertyStore(IShellItem2 *iface, GETPROPERTYSTOREFLAGS flags,
352 REFIID riid, void **ppv)
354 ShellItem *This = impl_from_IShellItem2(iface);
355 FIXME("Stub: %p (%d, %s, %p)\n", This, flags, shdebugstr_guid(riid), ppv);
356 return E_NOTIMPL;
359 static HRESULT WINAPI ShellItem2_GetPropertyStoreWithCreateObject(IShellItem2 *iface,
360 GETPROPERTYSTOREFLAGS flags, IUnknown *punkCreateObject, REFIID riid, void **ppv)
362 ShellItem *This = impl_from_IShellItem2(iface);
363 FIXME("Stub: %p (%08x, %p, %s, %p)\n",
364 This, flags, punkCreateObject, shdebugstr_guid(riid), ppv);
365 return E_NOTIMPL;
368 static HRESULT WINAPI ShellItem2_GetPropertyStoreForKeys(IShellItem2 *iface, const PROPERTYKEY *rgKeys,
369 UINT cKeys, GETPROPERTYSTOREFLAGS flags, REFIID riid, void **ppv)
371 ShellItem *This = impl_from_IShellItem2(iface);
372 FIXME("Stub: %p (%p, %d, %08x, %s, %p)\n",
373 This, rgKeys, cKeys, flags, shdebugstr_guid(riid), ppv);
374 return E_NOTIMPL;
377 static HRESULT WINAPI ShellItem2_GetPropertyDescriptionList(IShellItem2 *iface,
378 REFPROPERTYKEY keyType, REFIID riid, void **ppv)
380 ShellItem *This = impl_from_IShellItem2(iface);
381 FIXME("Stub: %p (%p, %s, %p)\n", This, keyType, debugstr_guid(riid), ppv);
382 return E_NOTIMPL;
385 static HRESULT WINAPI ShellItem2_Update(IShellItem2 *iface, IBindCtx *pbc)
387 ShellItem *This = impl_from_IShellItem2(iface);
388 FIXME("Stub: %p (%p)\n", This, pbc);
389 return E_NOTIMPL;
392 static HRESULT WINAPI ShellItem2_GetProperty(IShellItem2 *iface, REFPROPERTYKEY key, PROPVARIANT *ppropvar)
394 ShellItem *This = impl_from_IShellItem2(iface);
395 FIXME("Stub: %p (%p, %p)\n", This, key, ppropvar);
396 return E_NOTIMPL;
399 static HRESULT WINAPI ShellItem2_GetCLSID(IShellItem2 *iface, REFPROPERTYKEY key, CLSID *pclsid)
401 ShellItem *This = impl_from_IShellItem2(iface);
402 FIXME("Stub: %p (%p, %p)\n", This, key, pclsid);
403 return E_NOTIMPL;
406 static HRESULT WINAPI ShellItem2_GetFileTime(IShellItem2 *iface, REFPROPERTYKEY key, FILETIME *pft)
408 ShellItem *This = impl_from_IShellItem2(iface);
409 FIXME("Stub: %p (%p, %p)\n", This, key, pft);
410 return E_NOTIMPL;
413 static HRESULT WINAPI ShellItem2_GetInt32(IShellItem2 *iface, REFPROPERTYKEY key, int *pi)
415 ShellItem *This = impl_from_IShellItem2(iface);
416 FIXME("Stub: %p (%p, %p)\n", This, key, pi);
417 return E_NOTIMPL;
420 static HRESULT WINAPI ShellItem2_GetString(IShellItem2 *iface, REFPROPERTYKEY key, LPWSTR *ppsz)
422 ShellItem *This = impl_from_IShellItem2(iface);
423 FIXME("Stub: %p (%p, %p)\n", This, key, ppsz);
424 return E_NOTIMPL;
427 static HRESULT WINAPI ShellItem2_GetUInt32(IShellItem2 *iface, REFPROPERTYKEY key, ULONG *pui)
429 ShellItem *This = impl_from_IShellItem2(iface);
430 FIXME("Stub: %p (%p, %p)\n", This, key, pui);
431 return E_NOTIMPL;
434 static HRESULT WINAPI ShellItem2_GetUInt64(IShellItem2 *iface, REFPROPERTYKEY key, ULONGLONG *pull)
436 ShellItem *This = impl_from_IShellItem2(iface);
437 FIXME("Stub: %p (%p, %p)\n", This, key, pull);
438 return E_NOTIMPL;
441 static HRESULT WINAPI ShellItem2_GetBool(IShellItem2 *iface, REFPROPERTYKEY key, BOOL *pf)
443 ShellItem *This = impl_from_IShellItem2(iface);
444 FIXME("Stub: %p (%p, %p)\n", This, key, pf);
445 return E_NOTIMPL;
449 static const IShellItem2Vtbl ShellItem2_Vtbl = {
450 ShellItem_QueryInterface,
451 ShellItem_AddRef,
452 ShellItem_Release,
453 ShellItem_BindToHandler,
454 ShellItem_GetParent,
455 ShellItem_GetDisplayName,
456 ShellItem_GetAttributes,
457 ShellItem_Compare,
458 ShellItem2_GetPropertyStore,
459 ShellItem2_GetPropertyStoreWithCreateObject,
460 ShellItem2_GetPropertyStoreForKeys,
461 ShellItem2_GetPropertyDescriptionList,
462 ShellItem2_Update,
463 ShellItem2_GetProperty,
464 ShellItem2_GetCLSID,
465 ShellItem2_GetFileTime,
466 ShellItem2_GetInt32,
467 ShellItem2_GetString,
468 ShellItem2_GetUInt32,
469 ShellItem2_GetUInt64,
470 ShellItem2_GetBool
473 static HRESULT WINAPI ShellItem_IPersistIDList_QueryInterface(IPersistIDList *iface,
474 REFIID riid, void **ppv)
476 ShellItem *This = impl_from_IPersistIDList(iface);
477 return IShellItem2_QueryInterface(&This->IShellItem2_iface, riid, ppv);
480 static ULONG WINAPI ShellItem_IPersistIDList_AddRef(IPersistIDList *iface)
482 ShellItem *This = impl_from_IPersistIDList(iface);
483 return IShellItem2_AddRef(&This->IShellItem2_iface);
486 static ULONG WINAPI ShellItem_IPersistIDList_Release(IPersistIDList *iface)
488 ShellItem *This = impl_from_IPersistIDList(iface);
489 return IShellItem2_Release(&This->IShellItem2_iface);
492 static HRESULT WINAPI ShellItem_IPersistIDList_GetClassID(IPersistIDList* iface,
493 CLSID *pClassID)
495 *pClassID = CLSID_ShellItem;
496 return S_OK;
499 static HRESULT WINAPI ShellItem_IPersistIDList_SetIDList(IPersistIDList* iface,
500 LPCITEMIDLIST pidl)
502 ShellItem *This = impl_from_IPersistIDList(iface);
503 LPITEMIDLIST new_pidl;
505 TRACE("(%p,%p)\n", This, pidl);
507 new_pidl = ILClone(pidl);
509 if (new_pidl)
511 ILFree(This->pidl);
512 This->pidl = new_pidl;
513 return S_OK;
515 else
516 return E_OUTOFMEMORY;
519 static HRESULT WINAPI ShellItem_IPersistIDList_GetIDList(IPersistIDList* iface,
520 LPITEMIDLIST *ppidl)
522 ShellItem *This = impl_from_IPersistIDList(iface);
524 TRACE("(%p,%p)\n", This, ppidl);
526 *ppidl = ILClone(This->pidl);
527 if (*ppidl)
528 return S_OK;
529 else
530 return E_OUTOFMEMORY;
533 static const IPersistIDListVtbl ShellItem_IPersistIDList_Vtbl = {
534 ShellItem_IPersistIDList_QueryInterface,
535 ShellItem_IPersistIDList_AddRef,
536 ShellItem_IPersistIDList_Release,
537 ShellItem_IPersistIDList_GetClassID,
538 ShellItem_IPersistIDList_SetIDList,
539 ShellItem_IPersistIDList_GetIDList
543 HRESULT WINAPI IShellItem_Constructor(IUnknown *pUnkOuter, REFIID riid, void **ppv)
545 ShellItem *This;
546 HRESULT ret;
548 TRACE("(%p,%s)\n",pUnkOuter, debugstr_guid(riid));
550 *ppv = NULL;
552 if (pUnkOuter) return CLASS_E_NOAGGREGATION;
554 This = HeapAlloc(GetProcessHeap(), 0, sizeof(ShellItem));
555 This->IShellItem2_iface.lpVtbl = &ShellItem2_Vtbl;
556 This->ref = 1;
557 This->pidl = NULL;
558 This->IPersistIDList_iface.lpVtbl = &ShellItem_IPersistIDList_Vtbl;
560 ret = IShellItem2_QueryInterface(&This->IShellItem2_iface, riid, ppv);
561 IShellItem2_Release(&This->IShellItem2_iface);
563 return ret;
566 HRESULT WINAPI SHCreateShellItem(LPCITEMIDLIST pidlParent,
567 IShellFolder *psfParent, LPCITEMIDLIST pidl, IShellItem **ppsi)
569 LPITEMIDLIST new_pidl;
570 HRESULT ret;
572 TRACE("(%p,%p,%p,%p)\n", pidlParent, psfParent, pidl, ppsi);
574 *ppsi = NULL;
576 if (!pidl)
578 return E_INVALIDARG;
580 else if (pidlParent || psfParent)
582 LPITEMIDLIST temp_parent=NULL;
583 if (!pidlParent)
585 IPersistFolder2* ppf2Parent;
587 if (FAILED(IShellFolder_QueryInterface(psfParent, &IID_IPersistFolder2, (void**)&ppf2Parent)))
589 FIXME("couldn't get IPersistFolder2 interface of parent\n");
590 return E_NOINTERFACE;
593 if (FAILED(IPersistFolder2_GetCurFolder(ppf2Parent, &temp_parent)))
595 FIXME("couldn't get parent PIDL\n");
596 IPersistFolder2_Release(ppf2Parent);
597 return E_NOINTERFACE;
600 pidlParent = temp_parent;
601 IPersistFolder2_Release(ppf2Parent);
604 new_pidl = ILCombine(pidlParent, pidl);
605 ILFree(temp_parent);
607 if (!new_pidl)
608 return E_OUTOFMEMORY;
610 else
612 new_pidl = ILClone(pidl);
613 if (!new_pidl)
614 return E_OUTOFMEMORY;
617 ret = SHCreateItemFromIDList(new_pidl, &IID_IShellItem, (void**)ppsi);
618 ILFree(new_pidl);
620 return ret;
623 HRESULT WINAPI SHCreateItemFromParsingName(PCWSTR pszPath,
624 IBindCtx *pbc, REFIID riid, void **ppv)
626 LPITEMIDLIST pidl;
627 HRESULT ret;
629 *ppv = NULL;
631 ret = SHParseDisplayName(pszPath, pbc, &pidl, 0, NULL);
632 if(SUCCEEDED(ret))
634 ret = SHCreateItemFromIDList(pidl, riid, ppv);
635 ILFree(pidl);
637 return ret;
640 HRESULT WINAPI SHCreateItemFromRelativeName(IShellItem *parent, PCWSTR name, IBindCtx *pbc,
641 REFIID riid, void **ppv)
643 LPITEMIDLIST pidl_folder = NULL, pidl = NULL;
644 IShellFolder *desktop = NULL, *folder = NULL;
645 HRESULT hr;
647 TRACE("(%p, %s, %p, %s, %p)\n", parent, wine_dbgstr_w(name), pbc, debugstr_guid(riid), ppv);
649 if(!ppv)
650 return E_INVALIDARG;
651 *ppv = NULL;
652 if(!name)
653 return E_INVALIDARG;
655 hr = SHGetIDListFromObject((IUnknown*)parent, &pidl_folder);
656 if(hr != S_OK)
657 return hr;
659 hr = SHGetDesktopFolder(&desktop);
660 if(hr != S_OK)
661 goto cleanup;
663 if(!_ILIsDesktop(pidl_folder))
665 hr = IShellFolder_BindToObject(desktop, pidl_folder, NULL, &IID_IShellFolder,
666 (void**)&folder);
667 if(hr != S_OK)
668 goto cleanup;
671 hr = IShellFolder_ParseDisplayName(folder ? folder : desktop, NULL, pbc, (LPWSTR)name,
672 NULL, &pidl, NULL);
673 if(hr != S_OK)
674 goto cleanup;
675 hr = SHCreateItemFromIDList(pidl, riid, ppv);
677 cleanup:
678 if(pidl_folder)
679 ILFree(pidl_folder);
680 if(pidl)
681 ILFree(pidl);
682 if(desktop)
683 IShellFolder_Release(desktop);
684 if(folder)
685 IShellFolder_Release(folder);
686 return hr;
689 HRESULT WINAPI SHCreateItemFromIDList(PCIDLIST_ABSOLUTE pidl, REFIID riid, void **ppv)
691 IPersistIDList *persist;
692 HRESULT ret;
694 if(!pidl)
695 return E_INVALIDARG;
697 *ppv = NULL;
698 ret = IShellItem_Constructor(NULL, &IID_IPersistIDList, (void**)&persist);
699 if(FAILED(ret))
700 return ret;
702 ret = IPersistIDList_SetIDList(persist, pidl);
703 if(FAILED(ret))
705 IPersistIDList_Release(persist);
706 return ret;
709 ret = IPersistIDList_QueryInterface(persist, riid, ppv);
710 IPersistIDList_Release(persist);
711 return ret;
714 HRESULT WINAPI SHCreateItemInKnownFolder(REFKNOWNFOLDERID rfid, DWORD flags,
715 PCWSTR filename, REFIID riid, void **ppv)
717 HRESULT hr;
718 IShellItem *parent = NULL;
719 LPITEMIDLIST pidl = NULL;
721 TRACE("(%p, %x, %s, %s, %p)\n", rfid, flags, wine_dbgstr_w(filename),
722 debugstr_guid(riid), ppv);
724 if(!rfid || !ppv)
725 return E_INVALIDARG;
727 *ppv = NULL;
728 hr = SHGetKnownFolderIDList(rfid, flags, NULL, &pidl);
729 if(hr != S_OK)
730 return hr;
732 hr = SHCreateItemFromIDList(pidl, &IID_IShellItem, (void**)&parent);
733 if(hr != S_OK)
735 ILFree(pidl);
736 return hr;
739 if(filename)
740 hr = SHCreateItemFromRelativeName(parent, filename, NULL, riid, ppv);
741 else
742 hr = IShellItem_QueryInterface(parent, riid, ppv);
744 ILFree(pidl);
745 IShellItem_Release(parent);
746 return hr;
749 HRESULT WINAPI SHGetItemFromDataObject(IDataObject *pdtobj,
750 DATAOBJ_GET_ITEM_FLAGS dwFlags, REFIID riid, void **ppv)
752 FORMATETC fmt;
753 STGMEDIUM medium;
754 HRESULT ret;
756 TRACE("%p, %x, %s, %p\n", pdtobj, dwFlags, debugstr_guid(riid), ppv);
758 if(!pdtobj)
759 return E_INVALIDARG;
761 fmt.cfFormat = RegisterClipboardFormatW(CFSTR_SHELLIDLISTW);
762 fmt.ptd = NULL;
763 fmt.dwAspect = DVASPECT_CONTENT;
764 fmt.lindex = -1;
765 fmt.tymed = TYMED_HGLOBAL;
767 ret = IDataObject_GetData(pdtobj, &fmt, &medium);
768 if(SUCCEEDED(ret))
770 LPIDA pida = GlobalLock(medium.u.hGlobal);
772 if((pida->cidl > 1 && !(dwFlags & DOGIF_ONLY_IF_ONE)) ||
773 pida->cidl == 1)
775 LPITEMIDLIST pidl;
777 /* Get the first pidl (parent + child1) */
778 pidl = ILCombine((LPCITEMIDLIST) ((LPBYTE)pida+pida->aoffset[0]),
779 (LPCITEMIDLIST) ((LPBYTE)pida+pida->aoffset[1]));
781 ret = SHCreateItemFromIDList(pidl, riid, ppv);
782 ILFree(pidl);
784 else
786 ret = E_FAIL;
789 GlobalUnlock(medium.u.hGlobal);
790 GlobalFree(medium.u.hGlobal);
793 if(FAILED(ret) && !(dwFlags & DOGIF_NO_HDROP))
795 TRACE("Attempting to fall back on CF_HDROP.\n");
797 fmt.cfFormat = CF_HDROP;
798 fmt.ptd = NULL;
799 fmt.dwAspect = DVASPECT_CONTENT;
800 fmt.lindex = -1;
801 fmt.tymed = TYMED_HGLOBAL;
803 ret = IDataObject_GetData(pdtobj, &fmt, &medium);
804 if(SUCCEEDED(ret))
806 DROPFILES *df = GlobalLock(medium.u.hGlobal);
807 LPBYTE files = (LPBYTE)df + df->pFiles;
808 BOOL multiple_files = FALSE;
810 ret = E_FAIL;
811 if(!df->fWide)
813 WCHAR filename[MAX_PATH];
814 PCSTR first_file = (PCSTR)files;
815 if(*(files + lstrlenA(first_file) + 1) != 0)
816 multiple_files = TRUE;
818 if( !(multiple_files && (dwFlags & DOGIF_ONLY_IF_ONE)) )
820 MultiByteToWideChar(CP_ACP, 0, first_file, -1, filename, MAX_PATH);
821 ret = SHCreateItemFromParsingName(filename, NULL, riid, ppv);
824 else
826 PCWSTR first_file = (PCWSTR)files;
827 if(*((PCWSTR)files + lstrlenW(first_file) + 1) != 0)
828 multiple_files = TRUE;
830 if( !(multiple_files && (dwFlags & DOGIF_ONLY_IF_ONE)) )
831 ret = SHCreateItemFromParsingName(first_file, NULL, riid, ppv);
834 GlobalUnlock(medium.u.hGlobal);
835 GlobalFree(medium.u.hGlobal);
839 if(FAILED(ret) && !(dwFlags & DOGIF_NO_URL))
841 FIXME("Failed to create item, should try CF_URL.\n");
844 return ret;
847 HRESULT WINAPI SHGetItemFromObject(IUnknown *punk, REFIID riid, void **ppv)
849 LPITEMIDLIST pidl;
850 HRESULT ret;
852 ret = SHGetIDListFromObject(punk, &pidl);
853 if(SUCCEEDED(ret))
855 ret = SHCreateItemFromIDList(pidl, riid, ppv);
856 ILFree(pidl);
859 return ret;
862 /*************************************************************************
863 * IEnumShellItems implementation
865 typedef struct {
866 IEnumShellItems IEnumShellItems_iface;
867 LONG ref;
869 IShellItemArray *array;
870 DWORD count;
871 DWORD position;
872 } IEnumShellItemsImpl;
874 static inline IEnumShellItemsImpl *impl_from_IEnumShellItems(IEnumShellItems *iface)
876 return CONTAINING_RECORD(iface, IEnumShellItemsImpl, IEnumShellItems_iface);
879 static HRESULT WINAPI IEnumShellItems_fnQueryInterface(IEnumShellItems *iface,
880 REFIID riid,
881 void **ppvObject)
883 IEnumShellItemsImpl *This = impl_from_IEnumShellItems(iface);
884 TRACE("%p (%s, %p)\n", This, shdebugstr_guid(riid), ppvObject);
886 *ppvObject = NULL;
887 if(IsEqualIID(riid, &IID_IEnumShellItems) ||
888 IsEqualIID(riid, &IID_IUnknown))
890 *ppvObject = &This->IEnumShellItems_iface;
893 if(*ppvObject)
895 IUnknown_AddRef((IUnknown*)*ppvObject);
896 return S_OK;
899 return E_NOINTERFACE;
902 static ULONG WINAPI IEnumShellItems_fnAddRef(IEnumShellItems *iface)
904 IEnumShellItemsImpl *This = impl_from_IEnumShellItems(iface);
905 LONG ref = InterlockedIncrement(&This->ref);
906 TRACE("%p - ref %d\n", This, ref);
908 return ref;
911 static ULONG WINAPI IEnumShellItems_fnRelease(IEnumShellItems *iface)
913 IEnumShellItemsImpl *This = impl_from_IEnumShellItems(iface);
914 LONG ref = InterlockedDecrement(&This->ref);
915 TRACE("%p - ref %d\n", This, ref);
917 if(!ref)
919 TRACE("Freeing.\n");
920 IShellItemArray_Release(This->array);
921 HeapFree(GetProcessHeap(), 0, This);
922 return 0;
925 return ref;
928 static HRESULT WINAPI IEnumShellItems_fnNext(IEnumShellItems* iface,
929 ULONG celt,
930 IShellItem **rgelt,
931 ULONG *pceltFetched)
933 IEnumShellItemsImpl *This = impl_from_IEnumShellItems(iface);
934 HRESULT hr = S_FALSE;
935 UINT i;
936 ULONG fetched = 0;
937 TRACE("%p (%d %p %p)\n", This, celt, rgelt, pceltFetched);
939 if(pceltFetched == NULL && celt != 1)
940 return E_INVALIDARG;
942 for(i = This->position; fetched < celt && i < This->count; i++) {
943 hr = IShellItemArray_GetItemAt(This->array, i, &rgelt[fetched]);
944 if(FAILED(hr))
945 break;
946 fetched++;
947 This->position++;
950 if(SUCCEEDED(hr))
952 if(pceltFetched != NULL)
953 *pceltFetched = fetched;
955 if(fetched > 0)
956 return S_OK;
958 return S_FALSE;
961 return hr;
964 static HRESULT WINAPI IEnumShellItems_fnSkip(IEnumShellItems* iface, ULONG celt)
966 IEnumShellItemsImpl *This = impl_from_IEnumShellItems(iface);
967 TRACE("%p (%d)\n", This, celt);
969 This->position = min(This->position + celt, This->count-1);
971 return S_OK;
974 static HRESULT WINAPI IEnumShellItems_fnReset(IEnumShellItems* iface)
976 IEnumShellItemsImpl *This = impl_from_IEnumShellItems(iface);
977 TRACE("%p\n", This);
979 This->position = 0;
981 return S_OK;
984 static HRESULT WINAPI IEnumShellItems_fnClone(IEnumShellItems* iface, IEnumShellItems **ppenum)
986 IEnumShellItemsImpl *This = impl_from_IEnumShellItems(iface);
987 TRACE("%p (%p)\n", This, ppenum);
989 /* Not implemented anywhere */
990 *ppenum = NULL;
992 return E_NOTIMPL;
995 static const IEnumShellItemsVtbl vt_IEnumShellItems = {
996 IEnumShellItems_fnQueryInterface,
997 IEnumShellItems_fnAddRef,
998 IEnumShellItems_fnRelease,
999 IEnumShellItems_fnNext,
1000 IEnumShellItems_fnSkip,
1001 IEnumShellItems_fnReset,
1002 IEnumShellItems_fnClone
1005 static HRESULT IEnumShellItems_Constructor(IShellItemArray *array, IEnumShellItems **ppesi)
1007 IEnumShellItemsImpl *This;
1008 HRESULT ret;
1010 This = HeapAlloc(GetProcessHeap(), 0, sizeof(IEnumShellItemsImpl));
1011 if(!This)
1012 return E_OUTOFMEMORY;
1014 This->ref = 1;
1015 This->IEnumShellItems_iface.lpVtbl = &vt_IEnumShellItems;
1016 This->array = array;
1017 This->position = 0;
1019 IShellItemArray_AddRef(This->array);
1020 IShellItemArray_GetCount(This->array, &This->count);
1022 ret = IEnumShellItems_QueryInterface(&This->IEnumShellItems_iface, &IID_IEnumShellItems, (void**)ppesi);
1023 IEnumShellItems_Release(&This->IEnumShellItems_iface);
1025 return ret;
1029 /*************************************************************************
1030 * IShellItemArray implementation
1032 typedef struct {
1033 IShellItemArray IShellItemArray_iface;
1034 LONG ref;
1036 IShellItem **array;
1037 DWORD item_count;
1038 } IShellItemArrayImpl;
1040 static inline IShellItemArrayImpl *impl_from_IShellItemArray(IShellItemArray *iface)
1042 return CONTAINING_RECORD(iface, IShellItemArrayImpl, IShellItemArray_iface);
1045 static HRESULT WINAPI IShellItemArray_fnQueryInterface(IShellItemArray *iface,
1046 REFIID riid,
1047 void **ppvObject)
1049 IShellItemArrayImpl *This = impl_from_IShellItemArray(iface);
1050 TRACE("%p (%s, %p)\n", This, shdebugstr_guid(riid), ppvObject);
1052 *ppvObject = NULL;
1053 if(IsEqualIID(riid, &IID_IShellItemArray) ||
1054 IsEqualIID(riid, &IID_IUnknown))
1056 *ppvObject = &This->IShellItemArray_iface;
1059 if(*ppvObject)
1061 IUnknown_AddRef((IUnknown*)*ppvObject);
1062 return S_OK;
1065 return E_NOINTERFACE;
1068 static ULONG WINAPI IShellItemArray_fnAddRef(IShellItemArray *iface)
1070 IShellItemArrayImpl *This = impl_from_IShellItemArray(iface);
1071 LONG ref = InterlockedIncrement(&This->ref);
1072 TRACE("%p - ref %d\n", This, ref);
1074 return ref;
1077 static ULONG WINAPI IShellItemArray_fnRelease(IShellItemArray *iface)
1079 IShellItemArrayImpl *This = impl_from_IShellItemArray(iface);
1080 LONG ref = InterlockedDecrement(&This->ref);
1081 TRACE("%p - ref %d\n", This, ref);
1083 if(!ref)
1085 UINT i;
1086 TRACE("Freeing.\n");
1088 for(i = 0; i < This->item_count; i++)
1089 IShellItem_Release(This->array[i]);
1091 HeapFree(GetProcessHeap(), 0, This->array);
1092 HeapFree(GetProcessHeap(), 0, This);
1093 return 0;
1096 return ref;
1099 static HRESULT WINAPI IShellItemArray_fnBindToHandler(IShellItemArray *iface,
1100 IBindCtx *pbc,
1101 REFGUID bhid,
1102 REFIID riid,
1103 void **ppvOut)
1105 IShellItemArrayImpl *This = impl_from_IShellItemArray(iface);
1106 FIXME("Stub: %p (%p, %s, %s, %p)\n",
1107 This, pbc, shdebugstr_guid(bhid), shdebugstr_guid(riid), ppvOut);
1109 return E_NOTIMPL;
1112 static HRESULT WINAPI IShellItemArray_fnGetPropertyStore(IShellItemArray *iface,
1113 GETPROPERTYSTOREFLAGS flags,
1114 REFIID riid,
1115 void **ppv)
1117 IShellItemArrayImpl *This = impl_from_IShellItemArray(iface);
1118 FIXME("Stub: %p (%x, %s, %p)\n", This, flags, shdebugstr_guid(riid), ppv);
1120 return E_NOTIMPL;
1123 static HRESULT WINAPI IShellItemArray_fnGetPropertyDescriptionList(IShellItemArray *iface,
1124 REFPROPERTYKEY keyType,
1125 REFIID riid,
1126 void **ppv)
1128 IShellItemArrayImpl *This = impl_from_IShellItemArray(iface);
1129 FIXME("Stub: %p (%p, %s, %p)\n",
1130 This, keyType, shdebugstr_guid(riid), ppv);
1132 return E_NOTIMPL;
1135 static HRESULT WINAPI IShellItemArray_fnGetAttributes(IShellItemArray *iface,
1136 SIATTRIBFLAGS AttribFlags,
1137 SFGAOF sfgaoMask,
1138 SFGAOF *psfgaoAttribs)
1140 IShellItemArrayImpl *This = impl_from_IShellItemArray(iface);
1141 HRESULT hr = S_OK;
1142 SFGAOF attr;
1143 UINT i;
1144 TRACE("%p (%x, %x, %p)\n", This, AttribFlags, sfgaoMask, psfgaoAttribs);
1146 if(AttribFlags & ~(SIATTRIBFLAGS_AND|SIATTRIBFLAGS_OR))
1147 FIXME("%08x contains unsupported attribution flags\n", AttribFlags);
1149 for(i = 0; i < This->item_count; i++)
1151 hr = IShellItem_GetAttributes(This->array[i], sfgaoMask, &attr);
1152 if(FAILED(hr))
1153 break;
1155 if(i == 0)
1157 *psfgaoAttribs = attr;
1158 continue;
1161 switch(AttribFlags & SIATTRIBFLAGS_MASK)
1163 case SIATTRIBFLAGS_AND:
1164 *psfgaoAttribs &= attr;
1165 break;
1166 case SIATTRIBFLAGS_OR:
1167 *psfgaoAttribs |= attr;
1168 break;
1172 if(SUCCEEDED(hr))
1174 if(*psfgaoAttribs == sfgaoMask)
1175 return S_OK;
1177 return S_FALSE;
1180 return hr;
1183 static HRESULT WINAPI IShellItemArray_fnGetCount(IShellItemArray *iface,
1184 DWORD *pdwNumItems)
1186 IShellItemArrayImpl *This = impl_from_IShellItemArray(iface);
1187 TRACE("%p (%p)\n", This, pdwNumItems);
1189 *pdwNumItems = This->item_count;
1191 return S_OK;
1194 static HRESULT WINAPI IShellItemArray_fnGetItemAt(IShellItemArray *iface,
1195 DWORD dwIndex,
1196 IShellItem **ppsi)
1198 IShellItemArrayImpl *This = impl_from_IShellItemArray(iface);
1199 TRACE("%p (%x, %p)\n", This, dwIndex, ppsi);
1201 /* zero indexed */
1202 if(dwIndex + 1 > This->item_count)
1203 return E_FAIL;
1205 *ppsi = This->array[dwIndex];
1206 IShellItem_AddRef(*ppsi);
1208 return S_OK;
1211 static HRESULT WINAPI IShellItemArray_fnEnumItems(IShellItemArray *iface,
1212 IEnumShellItems **ppenumShellItems)
1214 IShellItemArrayImpl *This = impl_from_IShellItemArray(iface);
1215 TRACE("%p (%p)\n", This, ppenumShellItems);
1216 return IEnumShellItems_Constructor(iface, ppenumShellItems);
1219 static const IShellItemArrayVtbl vt_IShellItemArray = {
1220 IShellItemArray_fnQueryInterface,
1221 IShellItemArray_fnAddRef,
1222 IShellItemArray_fnRelease,
1223 IShellItemArray_fnBindToHandler,
1224 IShellItemArray_fnGetPropertyStore,
1225 IShellItemArray_fnGetPropertyDescriptionList,
1226 IShellItemArray_fnGetAttributes,
1227 IShellItemArray_fnGetCount,
1228 IShellItemArray_fnGetItemAt,
1229 IShellItemArray_fnEnumItems
1232 /* Caller is responsible to AddRef all items */
1233 static HRESULT create_shellitemarray(IShellItem **items, DWORD count, IShellItemArray **ret)
1235 IShellItemArrayImpl *This;
1237 TRACE("(%p, %d, %p)\n", items, count, ret);
1239 This = HeapAlloc(GetProcessHeap(), 0, sizeof(IShellItemArrayImpl));
1240 if(!This)
1241 return E_OUTOFMEMORY;
1243 This->IShellItemArray_iface.lpVtbl = &vt_IShellItemArray;
1244 This->ref = 1;
1246 This->array = HeapAlloc(GetProcessHeap(), 0, count*sizeof(IShellItem*));
1247 if (!This->array)
1249 HeapFree(GetProcessHeap(), 0, This);
1250 return E_OUTOFMEMORY;
1252 memcpy(This->array, items, count*sizeof(IShellItem*));
1253 This->item_count = count;
1255 *ret = &This->IShellItemArray_iface;
1256 return S_OK;
1259 HRESULT WINAPI SHCreateShellItemArray(PCIDLIST_ABSOLUTE pidlParent,
1260 IShellFolder *psf,
1261 UINT cidl,
1262 PCUITEMID_CHILD_ARRAY ppidl,
1263 IShellItemArray **ppsiItemArray)
1265 IShellItem **array;
1266 HRESULT ret = E_FAIL;
1267 UINT i;
1269 TRACE("%p, %p, %d, %p, %p\n", pidlParent, psf, cidl, ppidl, ppsiItemArray);
1271 *ppsiItemArray = NULL;
1273 if(!pidlParent && !psf)
1274 return E_POINTER;
1276 if(!ppidl)
1277 return E_INVALIDARG;
1279 array = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cidl*sizeof(IShellItem*));
1280 if(!array)
1281 return E_OUTOFMEMORY;
1283 for(i = 0; i < cidl; i++)
1285 ret = SHCreateShellItem(pidlParent, psf, ppidl[i], &array[i]);
1286 if(FAILED(ret)) break;
1289 if(SUCCEEDED(ret))
1291 ret = create_shellitemarray(array, cidl, ppsiItemArray);
1292 HeapFree(GetProcessHeap(), 0, array);
1293 if(SUCCEEDED(ret))
1294 return ret;
1297 /* Something failed, clean up. */
1298 for(i = 0; i < cidl; i++)
1299 if(array[i]) IShellItem_Release(array[i]);
1300 HeapFree(GetProcessHeap(), 0, array);
1301 return ret;
1304 HRESULT WINAPI SHCreateShellItemArrayFromShellItem(IShellItem *item, REFIID riid, void **ppv)
1306 IShellItemArray *array;
1307 HRESULT ret;
1309 TRACE("%p, %s, %p\n", item, shdebugstr_guid(riid), ppv);
1311 *ppv = NULL;
1313 IShellItem_AddRef(item);
1314 ret = create_shellitemarray(&item, 1, &array);
1315 if(FAILED(ret))
1317 IShellItem_Release(item);
1318 return ret;
1321 ret = IShellItemArray_QueryInterface(array, riid, ppv);
1322 IShellItemArray_Release(array);
1323 return ret;
1326 HRESULT WINAPI SHCreateShellItemArrayFromDataObject(IDataObject *pdo, REFIID riid, void **ppv)
1328 IShellItemArray *psia;
1329 FORMATETC fmt;
1330 STGMEDIUM medium;
1331 HRESULT ret;
1333 TRACE("%p, %s, %p\n", pdo, shdebugstr_guid(riid), ppv);
1335 if(!pdo)
1336 return E_INVALIDARG;
1338 *ppv = NULL;
1340 fmt.cfFormat = RegisterClipboardFormatW(CFSTR_SHELLIDLISTW);
1341 fmt.ptd = NULL;
1342 fmt.dwAspect = DVASPECT_CONTENT;
1343 fmt.lindex = -1;
1344 fmt.tymed = TYMED_HGLOBAL;
1346 ret = IDataObject_GetData(pdo, &fmt, &medium);
1347 if(SUCCEEDED(ret))
1349 LPIDA pida = GlobalLock(medium.u.hGlobal);
1350 LPCITEMIDLIST parent_pidl;
1351 LPCITEMIDLIST *children;
1352 UINT i;
1353 TRACE("Converting %d objects.\n", pida->cidl);
1355 parent_pidl = (LPCITEMIDLIST) ((LPBYTE)pida+pida->aoffset[0]);
1357 children = HeapAlloc(GetProcessHeap(), 0, sizeof(LPCITEMIDLIST)*pida->cidl);
1358 for(i = 0; i < pida->cidl; i++)
1359 children[i] = (LPCITEMIDLIST) ((LPBYTE)pida+pida->aoffset[i+1]);
1361 ret = SHCreateShellItemArray(parent_pidl, NULL, pida->cidl, children, &psia);
1363 HeapFree(GetProcessHeap(), 0, children);
1365 GlobalUnlock(medium.u.hGlobal);
1366 GlobalFree(medium.u.hGlobal);
1369 if(SUCCEEDED(ret))
1371 ret = IShellItemArray_QueryInterface(psia, riid, ppv);
1372 IShellItemArray_Release(psia);
1375 return ret;
1378 HRESULT WINAPI SHCreateShellItemArrayFromIDLists(UINT cidl,
1379 PCIDLIST_ABSOLUTE_ARRAY pidl_array,
1380 IShellItemArray **psia)
1382 IShellItem **array;
1383 HRESULT ret;
1384 UINT i;
1385 TRACE("%d, %p, %p\n", cidl, pidl_array, psia);
1387 *psia = NULL;
1389 if(cidl == 0)
1390 return E_INVALIDARG;
1392 array = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cidl*sizeof(IShellItem*));
1393 if(!array)
1394 return E_OUTOFMEMORY;
1396 for(i = 0; i < cidl; i++)
1398 ret = SHCreateShellItem(NULL, NULL, pidl_array[i], &array[i]);
1399 if(FAILED(ret))
1400 break;
1403 if(SUCCEEDED(ret))
1405 ret = create_shellitemarray(array, cidl, psia);
1406 HeapFree(GetProcessHeap(), 0, array);
1407 if(SUCCEEDED(ret))
1408 return ret;
1411 for(i = 0; i < cidl; i++)
1412 if(array[i]) IShellItem_Release(array[i]);
1413 HeapFree(GetProcessHeap(), 0, array);
1414 *psia = NULL;
1415 return ret;
1418 HRESULT WINAPI SHGetPropertyStoreFromParsingName(const WCHAR *path, IBindCtx *pbc, GETPROPERTYSTOREFLAGS flags,
1419 REFIID riid, void **ppv)
1421 IShellItem2 *item;
1422 HRESULT hr;
1424 TRACE("(%s %p %#x %p %p)\n", debugstr_w(path), pbc, flags, riid, ppv);
1426 hr = SHCreateItemFromParsingName(path, pbc, &IID_IShellItem2, (void **)&item);
1427 if(SUCCEEDED(hr))
1429 hr = IShellItem2_GetPropertyStore(item, flags, riid, ppv);
1430 IShellItem2_Release(item);
1433 return hr;
1436 static HRESULT WINAPI CustomDestinationList_QueryInterface(ICustomDestinationList *iface, REFIID riid, void **obj)
1438 CustomDestinationList *This = impl_from_ICustomDestinationList(iface);
1440 TRACE("(%p, %s, %p)\n", This, debugstr_guid(riid), obj);
1442 if (IsEqualIID(&IID_ICustomDestinationList, riid) || IsEqualIID(&IID_IUnknown, riid))
1444 *obj = &This->ICustomDestinationList_iface;
1446 else {
1447 FIXME("not implemented for %s\n", shdebugstr_guid(riid));
1448 *obj = NULL;
1449 return E_NOINTERFACE;
1452 IUnknown_AddRef((IUnknown*)*obj);
1453 return S_OK;
1456 static ULONG WINAPI CustomDestinationList_AddRef(ICustomDestinationList *iface)
1458 CustomDestinationList *This = impl_from_ICustomDestinationList(iface);
1459 ULONG ref = InterlockedIncrement(&This->ref);
1461 TRACE("(%p), new refcount=%i\n", This, ref);
1463 return ref;
1466 static ULONG WINAPI CustomDestinationList_Release(ICustomDestinationList *iface)
1468 CustomDestinationList *This = impl_from_ICustomDestinationList(iface);
1469 ULONG ref = InterlockedDecrement(&This->ref);
1471 TRACE("(%p), new refcount=%i\n", This, ref);
1473 if (ref == 0)
1474 HeapFree(GetProcessHeap(), 0, This);
1476 return ref;
1479 static HRESULT WINAPI CustomDestinationList_SetAppID(ICustomDestinationList *iface, const WCHAR *appid)
1481 CustomDestinationList *This = impl_from_ICustomDestinationList(iface);
1483 FIXME("%p (%s): stub\n", This, debugstr_w(appid));
1485 return E_NOTIMPL;
1488 static HRESULT WINAPI CustomDestinationList_BeginList(ICustomDestinationList *iface, UINT *min_slots, REFIID riid, void **obj)
1490 CustomDestinationList *This = impl_from_ICustomDestinationList(iface);
1492 FIXME("%p (%p %s %p): stub\n", This, min_slots, debugstr_guid(riid), obj);
1494 return E_NOTIMPL;
1497 static HRESULT WINAPI CustomDestinationList_AppendCategory(ICustomDestinationList *iface, const WCHAR *category, IObjectArray *array)
1499 CustomDestinationList *This = impl_from_ICustomDestinationList(iface);
1501 FIXME("%p (%s %p): stub\n", This, debugstr_w(category), array);
1503 return E_NOTIMPL;
1506 static HRESULT WINAPI CustomDestinationList_AppendKnownCategory(ICustomDestinationList *iface, KNOWNDESTCATEGORY category)
1508 CustomDestinationList *This = impl_from_ICustomDestinationList(iface);
1510 FIXME("%p (%d): stub\n", This, category);
1512 return E_NOTIMPL;
1515 static HRESULT WINAPI CustomDestinationList_AddUserTasks(ICustomDestinationList *iface, IObjectArray *tasks)
1517 CustomDestinationList *This = impl_from_ICustomDestinationList(iface);
1519 FIXME("%p (%p): stub\n", This, tasks);
1521 return E_NOTIMPL;
1524 static HRESULT WINAPI CustomDestinationList_CommitList(ICustomDestinationList *iface)
1526 CustomDestinationList *This = impl_from_ICustomDestinationList(iface);
1528 FIXME("%p: stub\n", This);
1530 return E_NOTIMPL;
1533 static HRESULT WINAPI CustomDestinationList_GetRemovedDestinations(ICustomDestinationList *iface, REFIID riid, void **obj)
1535 CustomDestinationList *This = impl_from_ICustomDestinationList(iface);
1537 FIXME("%p (%s %p): stub\n", This, debugstr_guid(riid), obj);
1539 return E_NOTIMPL;
1542 static HRESULT WINAPI CustomDestinationList_DeleteList(ICustomDestinationList *iface, const WCHAR *appid)
1544 CustomDestinationList *This = impl_from_ICustomDestinationList(iface);
1546 FIXME("%p (%s): stub\n", This, debugstr_w(appid));
1548 return E_NOTIMPL;
1551 static HRESULT WINAPI CustomDestinationList_AbortList(ICustomDestinationList *iface)
1553 CustomDestinationList *This = impl_from_ICustomDestinationList(iface);
1555 FIXME("%p: stub\n", This);
1557 return E_NOTIMPL;
1560 static const ICustomDestinationListVtbl CustomDestinationListVtbl =
1562 CustomDestinationList_QueryInterface,
1563 CustomDestinationList_AddRef,
1564 CustomDestinationList_Release,
1565 CustomDestinationList_SetAppID,
1566 CustomDestinationList_BeginList,
1567 CustomDestinationList_AppendCategory,
1568 CustomDestinationList_AppendKnownCategory,
1569 CustomDestinationList_AddUserTasks,
1570 CustomDestinationList_CommitList,
1571 CustomDestinationList_GetRemovedDestinations,
1572 CustomDestinationList_DeleteList,
1573 CustomDestinationList_AbortList
1576 HRESULT WINAPI CustomDestinationList_Constructor(IUnknown *outer, REFIID riid, void **obj)
1578 CustomDestinationList *list;
1579 HRESULT hr;
1581 TRACE("%p %s %p\n", outer, debugstr_guid(riid), obj);
1583 if (outer)
1584 return CLASS_E_NOAGGREGATION;
1586 if(!(list = HeapAlloc(GetProcessHeap(), 0, sizeof(*list))))
1587 return E_OUTOFMEMORY;
1589 list->ICustomDestinationList_iface.lpVtbl = &CustomDestinationListVtbl;
1590 list->ref = 1;
1592 hr = ICustomDestinationList_QueryInterface(&list->ICustomDestinationList_iface, riid, obj);
1593 ICustomDestinationList_Release(&list->ICustomDestinationList_iface);
1594 return hr;