From bf1b56be101d17fed35d0ca342c3e9a45923484c Mon Sep 17 00:00:00 2001 From: David Hedberg Date: Mon, 26 Jul 2010 11:54:04 +0200 Subject: [PATCH] shell32: Implement SHCreateShellItemArrayFromShellItem. --- dlls/shell32/shell32.spec | 1 + dlls/shell32/shellitem.c | 30 ++++++++++++++++++ dlls/shell32/tests/shlfolder.c | 57 ++++++++++++++++++++++++++++++++++ include/shobjidl.idl | 1 + 4 files changed, 89 insertions(+) diff --git a/dlls/shell32/shell32.spec b/dlls/shell32/shell32.spec index 426e8412ca3..41cfde31ca7 100644 --- a/dlls/shell32/shell32.spec +++ b/dlls/shell32/shell32.spec @@ -335,6 +335,7 @@ @ stub SHCreateProcessAsUserW @ stdcall SHCreateShellItem(ptr ptr ptr ptr) @ stdcall SHCreateShellItemArray(ptr ptr long ptr ptr) +@ stdcall SHCreateShellItemArrayFromShellItem(ptr ptr ptr) @ stdcall SHEmptyRecycleBinA(long str long) @ stdcall SHEmptyRecycleBinW(long wstr long) @ stub SHExtractIconsW diff --git a/dlls/shell32/shellitem.c b/dlls/shell32/shellitem.c index 8dd6239e288..68cd32e10c5 100644 --- a/dlls/shell32/shellitem.c +++ b/dlls/shell32/shellitem.c @@ -827,3 +827,33 @@ HRESULT WINAPI SHCreateShellItemArray(PCIDLIST_ABSOLUTE pidlParent, *ppsiItemArray = NULL; return ret; } + +HRESULT WINAPI SHCreateShellItemArrayFromShellItem(IShellItem *psi, REFIID riid, void **ppv) +{ + IShellItemArrayImpl *This; + IShellItem **array; + HRESULT ret; + + TRACE("%p, %s, %p\n", psi, shdebugstr_guid(riid), ppv); + + array = HeapAlloc(GetProcessHeap(), 0, sizeof(IShellItem*)); + if(!array) + return E_OUTOFMEMORY; + + ret = IShellItemArray_Constructor(NULL, riid, (void**)&This); + if(SUCCEEDED(ret)) + { + array[0] = psi; + IShellItem_AddRef(psi); + This->array = array; + This->item_count = 1; + *ppv = This; + } + else + { + HeapFree(GetProcessHeap(), 0, array); + *ppv = NULL; + } + + return ret; +} diff --git a/dlls/shell32/tests/shlfolder.c b/dlls/shell32/tests/shlfolder.c index 491327e5244..b8c5da6b45b 100644 --- a/dlls/shell32/tests/shlfolder.c +++ b/dlls/shell32/tests/shlfolder.c @@ -59,6 +59,7 @@ static HRESULT (WINAPI *pSHCreateItemFromIDList)(PCIDLIST_ABSOLUTE pidl, REFIID static HRESULT (WINAPI *pSHCreateItemFromParsingName)(PCWSTR,IBindCtx*,REFIID,void**); static HRESULT (WINAPI *pSHCreateShellItem)(LPCITEMIDLIST,IShellFolder*,LPCITEMIDLIST,IShellItem**); static HRESULT (WINAPI *pSHCreateShellItemArray)(LPCITEMIDLIST,IShellFolder*,UINT,LPCITEMIDLIST*,IShellItemArray**); +static HRESULT (WINAPI *pSHCreateShellItemArrayFromShellItem)(IShellItem*, REFIID, void **); static LPITEMIDLIST (WINAPI *pILCombine)(LPCITEMIDLIST,LPCITEMIDLIST); static HRESULT (WINAPI *pSHParseDisplayName)(LPCWSTR,IBindCtx*,LPITEMIDLIST*,SFGAOF,SFGAOF*); static LPITEMIDLIST (WINAPI *pSHSimpleIDListFromPathAW)(LPCVOID); @@ -81,6 +82,7 @@ static void init_function_pointers(void) MAKEFUNC(SHCreateItemFromParsingName); MAKEFUNC(SHCreateShellItem); MAKEFUNC(SHCreateShellItemArray); + MAKEFUNC(SHCreateShellItemArrayFromShellItem); MAKEFUNC(SHGetFolderPathA); MAKEFUNC(SHGetFolderPathAndSubDirA); MAKEFUNC(SHGetPathFromIDListW); @@ -3056,6 +3058,61 @@ static void test_SHCreateShellItemArray(void) } } + /* SHCreateShellItemArrayFromShellItem */ + if(pSHCreateShellItemArrayFromShellItem) + { + IShellItem *psi; + + if(0) + { + /* Crashes under Windows 7 */ + hr = pSHCreateShellItemArrayFromShellItem(NULL, &IID_IShellItemArray, NULL); + hr = pSHCreateShellItemArrayFromShellItem(NULL, &IID_IShellItemArray, (void**)&psia); + hr = pSHCreateShellItemArrayFromShellItem(psi, &IID_IShellItemArray, NULL); + } + + hr = pSHCreateItemFromIDList(pidl_testdir, &IID_IShellItem, (void**)&psi); + ok(hr == S_OK, "Got 0x%08x\n", hr); + if(SUCCEEDED(hr)) + { + hr = pSHCreateShellItemArrayFromShellItem(psi, &IID_IShellItemArray, (void**)&psia); + ok(hr == S_OK, "Got 0x%08x\n", hr); + if(SUCCEEDED(hr)) + { + IShellItem *psi2; + UINT count; + hr = IShellItemArray_GetCount(psia, &count); + ok(hr == S_OK, "Got 0x%08x\n", hr); + ok(count == 1, "Got count %d\n", count); + hr = IShellItemArray_GetItemAt(psia, 0, &psi2); + ok(hr == S_OK, "Got 0x%08x\n", hr); + todo_wine + ok(psi != psi2, "ShellItems are of the same instance.\n"); + if(SUCCEEDED(hr)) + { + LPITEMIDLIST pidl1, pidl2; + hr = pSHGetIDListFromObject((IUnknown*)psi, &pidl1); + ok(hr == S_OK, "Got 0x%08x\n", hr); + ok(pidl1 != NULL, "pidl1 was null.\n"); + hr = pSHGetIDListFromObject((IUnknown*)psi2, &pidl2); + ok(hr == S_OK, "Got 0x%08x\n", hr); + ok(pidl2 != NULL, "pidl2 was null.\n"); + ok(ILIsEqual(pidl1, pidl2), "pidls not equal.\n"); + pILFree(pidl1); + pILFree(pidl2); + IShellItem_Release(psi2); + } + hr = IShellItemArray_GetItemAt(psia, 1, &psi2); + ok(hr == E_FAIL, "Got 0x%08x\n", hr); + IShellItemArray_Release(psia); + } + IShellItem_Release(psi); + } + } + else + skip("No SHCreateShellItemArrayFromShellItem.\n"); + + IShellFolder_Release(psf); pILFree(pidl_testdir); Cleanup(); diff --git a/include/shobjidl.idl b/include/shobjidl.idl index d982cc1a008..f4defe0d1fd 100644 --- a/include/shobjidl.idl +++ b/include/shobjidl.idl @@ -518,6 +518,7 @@ cpp_quote("HRESULT WINAPI SHGetItemFromDataObject(IDataObject *pdtobj, DATAOBJ_G cpp_quote("HRESULT WINAPI SHGetIDListFromObject(IUnknown *punk, PIDLIST_ABSOLUTE *ppidl);") cpp_quote("HRESULT WINAPI SHGetItemFromObject(IUnknown *punk, REFIID riid, void **ppv);") cpp_quote("HRESULT WINAPI SHCreateShellItemArray(PCIDLIST_ABSOLUTE pidlParent, IShellFolder* psf, UINT cidl, PCUITEMID_CHILD_ARRAY ppidl, IShellItemArray **ppsiItemArray);") +cpp_quote("HRESULT WINAPI SHCreateShellItemArrayFromShellItem(IShellItem *psi, REFIID riid, void **ppv);") /***************************************************************************** * IShellItemFilter interface