From 4c99e3ef341a6b4eda67dffa13a86829fa343bbb Mon Sep 17 00:00:00 2001 From: Myah Caron Date: Mon, 14 Sep 2020 20:52:47 +0000 Subject: [PATCH] shell32: Implement ShellLinkObject::get_Path. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=49591 Signed-off-by: Myah Caron Signed-off-by: Nikolay Sivov Signed-off-by: Alexandre Julliard --- dlls/shell32/shelldispatch.c | 53 +++++++++++++++++++++++++++--- dlls/shell32/tests/shelldispatch.c | 2 +- 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/dlls/shell32/shelldispatch.c b/dlls/shell32/shelldispatch.c index 5eda5c76eef..de581dec427 100644 --- a/dlls/shell32/shelldispatch.c +++ b/dlls/shell32/shelldispatch.c @@ -106,6 +106,8 @@ typedef struct { typedef struct { IShellLinkDual2 IShellLinkDual2_iface; LONG ref; + + IShellLinkW *shell_link; } ShellLinkObjectImpl; static inline ShellDispatch *impl_from_IShellDispatch6(IShellDispatch6 *iface) @@ -671,6 +673,7 @@ static ULONG WINAPI ShellLinkObject_Release(IShellLinkDual2 *iface) if (!ref) { + if (This->shell_link) IShellLinkW_Release(This->shell_link); heap_free(This); } return ref; @@ -732,9 +735,20 @@ static HRESULT WINAPI ShellLinkObject_Invoke(IShellLinkDual2 *iface, DISPID disp static HRESULT WINAPI ShellLinkObject_get_Path(IShellLinkDual2 *iface, BSTR *pbs) { - FIXME("(%p, %p)\n", iface, pbs); + ShellLinkObjectImpl *This = impl_from_IShellLinkDual(iface); + WCHAR path[MAX_PATH]; + HRESULT hr; - return E_NOTIMPL; + TRACE("(%p, %p)\n", iface, pbs); + + *pbs = NULL; + + hr = IShellLinkW_GetPath(This->shell_link, path, MAX_PATH, NULL, 0); + if (hr != S_OK) + return hr; + + *pbs = SysAllocString(path); + return hr; } static HRESULT WINAPI ShellLinkObject_put_Path(IShellLinkDual2 *iface, BSTR bs) @@ -878,11 +892,13 @@ static const IShellLinkDual2Vtbl ShellLinkObjectVtbl = { ShellLinkObject_get_Target, }; -static HRESULT ShellLinkObject_Constructor(IShellLinkDual2 **link) +static HRESULT ShellLinkObject_Constructor(FolderItemImpl *item, IShellLinkDual2 **link) { + HRESULT hr; + IPersistFile *persist_file = NULL; ShellLinkObjectImpl *This; - FIXME("(%p)\n", link); + TRACE("(%p, %p)\n", item, link); *link = NULL; @@ -891,6 +907,33 @@ static HRESULT ShellLinkObject_Constructor(IShellLinkDual2 **link) This->IShellLinkDual2_iface.lpVtbl = &ShellLinkObjectVtbl; This->ref = 1; + This->shell_link = NULL; + hr = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, + &IID_IShellLinkW, (LPVOID*)&This->shell_link); + if (FAILED(hr)) + { + heap_free(This); + return hr; + } + + hr = IShellLinkW_QueryInterface(This->shell_link, &IID_IPersistFile, + (LPVOID*)&persist_file); + if (FAILED(hr)) + { + IShellLinkW_Release(This->shell_link); + heap_free(This); + return hr; + } + + hr = IPersistFile_Load(persist_file, item->path, STGM_READ); + IPersistFile_Release(persist_file); + if (FAILED(hr)) + { + IShellLinkW_Release(This->shell_link); + heap_free(This); + return hr; + } + *link = (IShellLinkDual2 *)&This->IShellLinkDual2_iface; return S_OK; } @@ -1092,7 +1135,7 @@ static HRESULT WINAPI FolderItemImpl_get_GetLink(FolderItem2 *iface, if (!(This->attributes & SFGAO_LINK)) return E_NOTIMPL; - hr = ShellLinkObject_Constructor(&link); + hr = ShellLinkObject_Constructor(This, &link); if (hr != S_OK) return hr; diff --git a/dlls/shell32/tests/shelldispatch.c b/dlls/shell32/tests/shelldispatch.c index ae1cf086270..33ada2d80cc 100644 --- a/dlls/shell32/tests/shelldispatch.c +++ b/dlls/shell32/tests/shelldispatch.c @@ -1500,7 +1500,7 @@ static void test_ShellLinkObject(void) str = NULL; hr = IShellLinkDual2_get_Path(sld, &str); - todo_wine ok(hr == S_OK, "got 0x%08x\n", hr); + ok(hr == S_OK, "got 0x%08x\n", hr); if (hr == S_OK) { ok(!wcscmp(str, empty_path), "got %s (wanted %s)\n", wine_dbgstr_w(str), wine_dbgstr_w(empty_path));