[PATCH v3 2/3] shell32: Implement FolderItem::get_GetLink.
Myah Caron
qsniyg at protonmail.com
Sun Sep 13 17:33:20 CDT 2020
Signed-off-by: Myah Caron <qsniyg at protonmail.com>
---
v3:
Following Nikolay's comments:
- Move ::Constructor from patch #1 to this patch.
- Remove copy/paste bug with a superfluous AddRef.
- Remove goto.
- Use FAILED instead of != S_OK.
dlls/shell32/shelldispatch.c | 60 +++++++++++++++++++++++++++++-
dlls/shell32/tests/shelldispatch.c | 4 +-
2 files changed, 60 insertions(+), 4 deletions(-)
diff --git a/dlls/shell32/shelldispatch.c b/dlls/shell32/shelldispatch.c
index 05e2cafb9ee..5d2f36f1543 100644
--- a/dlls/shell32/shelldispatch.c
+++ b/dlls/shell32/shelldispatch.c
@@ -883,6 +883,49 @@ static const IShellLinkDual2Vtbl ShellLinkObjectVtbl = {
ShellLinkObject_get_Target,
};
+static HRESULT ShellLinkObject_Constructor(FolderItemImpl *item, IShellLinkDual2 **link)
+{
+ HRESULT hr;
+ ShellLinkObjectImpl *This;
+
+ TRACE("%p\n", item);
+
+ *link = NULL;
+
+ This = heap_alloc(sizeof(*This));
+ if (!This) return E_OUTOFMEMORY;
+ 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;
+ }
+
+ This->persist_file = NULL;
+ hr = IShellLinkW_QueryInterface(This->shell_link, &IID_IPersistFile,
+ (LPVOID*)&This->persist_file);
+ if (FAILED(hr))
+ {
+ heap_free(This);
+ return hr;
+ }
+
+ hr = IPersistFile_Load(This->persist_file, item->path, STGM_READ);
+ if (FAILED(hr))
+ {
+ heap_free(This);
+ return hr;
+ }
+
+ *link = (IShellLinkDual2 *)&This->IShellLinkDual2_iface;
+ return S_OK;
+}
+
static HRESULT WINAPI FolderItemImpl_QueryInterface(FolderItem2 *iface,
REFIID riid, LPVOID *ppv)
{
@@ -1069,10 +1112,23 @@ static HRESULT WINAPI FolderItemImpl_get_Path(FolderItem2 *iface, BSTR *path)
static HRESULT WINAPI FolderItemImpl_get_GetLink(FolderItem2 *iface,
IDispatch **ppid)
{
- FIXME("(%p,%p)\n", iface, ppid);
+ IShellLinkDual2 *link;
+ HRESULT hr;
+ FolderItemImpl *This = impl_from_FolderItem(iface);
+
+ TRACE("(%p,%p)\n", iface, ppid);
*ppid = NULL;
- return E_NOTIMPL;
+
+ if (!(This->attributes & SFGAO_LINK))
+ return E_NOTIMPL;
+
+ hr = ShellLinkObject_Constructor(This, &link);
+ if (hr != S_OK)
+ return hr;
+
+ *ppid = (IDispatch*)link;
+ return S_OK;
}
static HRESULT WINAPI FolderItemImpl_get_GetFolder(FolderItem2 *iface,
diff --git a/dlls/shell32/tests/shelldispatch.c b/dlls/shell32/tests/shelldispatch.c
index 28b0b186b8e..ae1cf086270 100644
--- a/dlls/shell32/tests/shelldispatch.c
+++ b/dlls/shell32/tests/shelldispatch.c
@@ -1492,8 +1492,8 @@ static void test_ShellLinkObject(void)
dispatch = NULL;
hr = FolderItem_get_GetLink(item, &dispatch);
- todo_wine ok(hr == S_OK, "got 0x%08x\n", hr);
- todo_wine ok(dispatch != NULL, "got %p\n", dispatch);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+ ok(dispatch != NULL, "got %p\n", dispatch);
if (dispatch) {
sld = (IShellLinkDual2*)dispatch;
--
2.28.0
More information about the wine-devel
mailing list