From 222d2142ef0161cd1a1b380c95b2a3bd248f3262 Mon Sep 17 00:00:00 2001 From: David Hedberg Date: Thu, 22 Jul 2010 20:17:04 +0200 Subject: [PATCH] shell32: Implement SHCreateItemFromIDList. --- dlls/shell32/shell32.spec | 1 + dlls/shell32/shellitem.c | 18 +++++++++++ dlls/shell32/tests/shlfolder.c | 58 ++++++++++++++++++++++++++++++++++ include/shobjidl.idl | 1 + 4 files changed, 78 insertions(+) diff --git a/dlls/shell32/shell32.spec b/dlls/shell32/shell32.spec index bb1796dc786..cc7744d0a2e 100644 --- a/dlls/shell32/shell32.spec +++ b/dlls/shell32/shell32.spec @@ -330,6 +330,7 @@ @ stub SHChangeNotifySuspendResume @ stdcall SHCreateDirectoryExA(long str ptr) @ stdcall SHCreateDirectoryExW(long wstr ptr) +@ stdcall SHCreateItemFromIDList(ptr ptr ptr) @ stdcall SHCreateItemFromParsingName(wstr ptr ptr ptr) @ stub SHCreateProcessAsUserW @ stdcall SHCreateShellItem(ptr ptr ptr ptr) diff --git a/dlls/shell32/shellitem.c b/dlls/shell32/shellitem.c index 762b13bcef7..84a195fb11a 100644 --- a/dlls/shell32/shellitem.c +++ b/dlls/shell32/shellitem.c @@ -419,3 +419,21 @@ HRESULT WINAPI SHCreateItemFromParsingName(PCWSTR pszPath, } return ret; } + +HRESULT WINAPI SHCreateItemFromIDList(PCIDLIST_ABSOLUTE pidl, REFIID riid, void **ppv) +{ + ShellItem *psiimpl; + HRESULT ret; + + if(!pidl) + return E_INVALIDARG; + + ret = IShellItem_Constructor(NULL, riid, ppv); + if(SUCCEEDED(ret)) + { + psiimpl = (ShellItem*)*ppv; + psiimpl->pidl = ILClone(pidl); + } + + return ret; +} diff --git a/dlls/shell32/tests/shlfolder.c b/dlls/shell32/tests/shlfolder.c index 10838e689a9..7eda9914140 100644 --- a/dlls/shell32/tests/shlfolder.c +++ b/dlls/shell32/tests/shlfolder.c @@ -53,6 +53,7 @@ static HRESULT (WINAPI *pStrRetToBufW)(STRRET*,LPCITEMIDLIST,LPWSTR,UINT); static LPITEMIDLIST (WINAPI *pILFindLastID)(LPCITEMIDLIST); static void (WINAPI *pILFree)(LPITEMIDLIST); static BOOL (WINAPI *pILIsEqual)(LPCITEMIDLIST, LPCITEMIDLIST); +static HRESULT (WINAPI *pSHCreateItemFromIDList)(PCIDLIST_ABSOLUTE pidl, REFIID riid, void **ppv); static HRESULT (WINAPI *pSHCreateItemFromParsingName)(PCWSTR,IBindCtx*,REFIID,void**); static HRESULT (WINAPI *pSHCreateShellItem)(LPCITEMIDLIST,IShellFolder*,LPCITEMIDLIST,IShellItem**); static LPITEMIDLIST (WINAPI *pILCombine)(LPCITEMIDLIST,LPCITEMIDLIST); @@ -70,6 +71,7 @@ static void init_function_pointers(void) #define MAKEFUNC(f) (p##f = (void*)GetProcAddress(hmod, #f)) MAKEFUNC(SHBindToParent); + MAKEFUNC(SHCreateItemFromIDList); MAKEFUNC(SHCreateItemFromParsingName); MAKEFUNC(SHCreateShellItem); MAKEFUNC(SHGetFolderPathA); @@ -2079,6 +2081,62 @@ static void test_SHCreateShellItem(void) else win_skip("No SHCreateItemFromParsingName\n"); + + /* SHCreateItemFromIDList */ + if(pSHCreateItemFromIDList) + { + if(0) + { + /* Crashes under win7 */ + ret = pSHCreateItemFromIDList(NULL, &IID_IShellItem, NULL); + } + + ret = pSHCreateItemFromIDList(NULL, &IID_IShellItem, (void**)&shellitem); + ok(ret == E_INVALIDARG, "SHCreateItemFromIDList returned %x\n", ret); + + ret = pSHCreateItemFromIDList(pidl_cwd, &IID_IShellItem, (void**)&shellitem); + ok(ret == S_OK, "SHCreateItemFromIDList returned %x\n", ret); + if (SUCCEEDED(ret)) + { + ret = IShellItem_QueryInterface(shellitem, &IID_IPersistIDList, (void**)&persistidl); + ok(ret == S_OK, "QueryInterface returned %x\n", ret); + if (SUCCEEDED(ret)) + { + ret = IPersistIDList_GetIDList(persistidl, &pidl_test); + ok(ret == S_OK, "GetIDList returned %x\n", ret); + if (SUCCEEDED(ret)) + { + ok(ILIsEqual(pidl_cwd, pidl_test), "id lists are not equal\n"); + pILFree(pidl_test); + } + IPersistIDList_Release(persistidl); + } + IShellItem_Release(shellitem); + } + + ret = pSHCreateItemFromIDList(pidl_testfile, &IID_IShellItem, (void**)&shellitem); + ok(ret == S_OK, "SHCreateItemFromIDList returned %x\n", ret); + if (SUCCEEDED(ret)) + { + ret = IShellItem_QueryInterface(shellitem, &IID_IPersistIDList, (void**)&persistidl); + ok(ret == S_OK, "QueryInterface returned %x\n", ret); + if (SUCCEEDED(ret)) + { + ret = IPersistIDList_GetIDList(persistidl, &pidl_test); + ok(ret == S_OK, "GetIDList returned %x\n", ret); + if (SUCCEEDED(ret)) + { + ok(ILIsEqual(pidl_testfile, pidl_test), "id lists are not equal\n"); + pILFree(pidl_test); + } + IPersistIDList_Release(persistidl); + } + IShellItem_Release(shellitem); + } + } + else + win_skip("No SHCreateItemFromIDList\n"); + DeleteFileA(".\\testfile"); pILFree(pidl_abstestfile); pILFree(pidl_testfile); diff --git a/include/shobjidl.idl b/include/shobjidl.idl index 60c0f18db30..d79c932bc56 100644 --- a/include/shobjidl.idl +++ b/include/shobjidl.idl @@ -496,6 +496,7 @@ interface IShellItemArray : IUnknown cpp_quote("HRESULT WINAPI SHGetNameFromIDList(PCIDLIST_ABSOLUTE pidl, SIGDN sigdnName, PWSTR *ppszName);") cpp_quote("HRESULT WINAPI SHCreateItemFromParsingName(PCWSTR pszPath, IBindCtx *pbc, REFIID riid, void **ppv);") +cpp_quote("HRESULT WINAPI SHCreateItemFromIDList(PCIDLIST_ABSOLUTE pidl, REFIID riid, void **ppv);") /***************************************************************************** * IShellItemFilter interface