From: Vibhav Pant vibhavp@gmail.com
--- dlls/vccorlib140/tests/vccorlib.c | 10 ++-------- dlls/vccorlib140/vccorlib.c | 30 ++++++++++++++++++++++++++---- 2 files changed, 28 insertions(+), 12 deletions(-)
diff --git a/dlls/vccorlib140/tests/vccorlib.c b/dlls/vccorlib140/tests/vccorlib.c index bda38adfbc6..b901f5365d0 100644 --- a/dlls/vccorlib140/tests/vccorlib.c +++ b/dlls/vccorlib140/tests/vccorlib.c @@ -980,16 +980,10 @@ static void test_GetWeakReference(void)
/* This is just a wrapper around QueryInterface(IID_IWeakReferenceSource) + IWeakReferenceSource::GetWeakReference. */ weakref = p_GetWeakReference((IUnknown *)&obj->IWeakReferenceSource_iface); - todo_wine ok(weakref == &obj->block->IWeakReference_iface, "got weakref %p != %p\n", weakref, + ok(weakref == &obj->block->IWeakReference_iface, "got weakref %p != %p\n", weakref, &obj->block->IWeakReference_iface); - todo_wine ok(obj->block->ref_weak == 2, "got ref_weak %lu\n", obj->block->ref_weak); + ok(obj->block->ref_weak == 2, "got ref_weak %lu\n", obj->block->ref_weak); ok(obj->block->ref_strong == 1, "got ref_strong %lu\n", obj->block->ref_strong); - if (!weakref) - { - skip("GetWeakReference failed.\n"); - IWeakReferenceSource_Release(&obj->IWeakReferenceSource_iface); - return; - }
hr = IWeakReference_Resolve(weakref, &IID_IUnknown, (IInspectable **)&unk); ok(hr == S_OK, "got hr %#lx\n", hr); diff --git a/dlls/vccorlib140/vccorlib.c b/dlls/vccorlib140/vccorlib.c index 4c5a027cf35..baa825ef186 100644 --- a/dlls/vccorlib140/vccorlib.c +++ b/dlls/vccorlib140/vccorlib.c @@ -264,14 +264,36 @@ void __thiscall control_block_ReleaseTarget(struct control_block *weakref)
IWeakReference *WINAPI GetWeakReference(IUnknown *obj) { - FIXME("(%p): stub!\n", obj); - return NULL; + IWeakReferenceSource *src; + IWeakReference *ref; + HRESULT hr; + + TRACE("(%p)\n", obj); + + if (!obj) + __abi_WinRTraiseInvalidArgumentException(); + if (SUCCEEDED((hr = IUnknown_QueryInterface(obj, &IID_IWeakReferenceSource, (void **)&src)))) + { + hr = IWeakReferenceSource_GetWeakReference(src, &ref); + IWeakReferenceSource_Release(src); + } + if (FAILED(hr)) + __abi_WinRTraiseCOMException(hr); + + return ref; }
IUnknown *WINAPI ResolveWeakReference(const GUID *iid, IWeakReference **weakref) { - FIXME("(%s, %p): stub!\n", debugstr_guid(iid), weakref); - return NULL; + IUnknown *obj = NULL; + HRESULT hr; + + TRACE("(%s, %p)\n", debugstr_guid(iid), weakref); + + if (*weakref && FAILED((hr = IWeakReference_Resolve(*weakref, iid, (IInspectable **)&obj)))) + __abi_WinRTraiseCOMException(hr); + + return obj; }
struct __abi_type_descriptor