From fbceeff26b0cc329018931b789813174f0e54d69 Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Tue, 28 Sep 2021 15:56:32 +0300 Subject: [PATCH] ole32/composite: Improve handling of BindToObject() when left side moniker is specified. Signed-off-by: Nikolay Sivov Signed-off-by: Alexandre Julliard --- dlls/ole32/compositemoniker.c | 52 +++++++++++++++++------------------ dlls/ole32/tests/moniker.c | 41 +++++++++++++++++++++++++-- 2 files changed, 64 insertions(+), 29 deletions(-) diff --git a/dlls/ole32/compositemoniker.c b/dlls/ole32/compositemoniker.c index b2ec02e1150..4451f0daae6 100644 --- a/dlls/ole32/compositemoniker.c +++ b/dlls/ole32/compositemoniker.c @@ -315,23 +315,30 @@ CompositeMonikerImpl_GetSizeMax(IMoniker* iface,ULARGE_INTEGER* pcbSize) return S_OK; } -static HRESULT WINAPI CompositeMonikerImpl_BindToObject(IMoniker *iface, IBindCtx *pbc, - IMoniker *pmkToLeft, REFIID riid, void **result) +static HRESULT compose_with(IMoniker *left, IMoniker *right, IMoniker **c) { + HRESULT hr = IMoniker_ComposeWith(left, right, TRUE, c); + if (FAILED(hr) && hr != MK_E_NEEDGENERIC) return hr; + return CreateGenericComposite(left, right, c); +} + +static HRESULT WINAPI CompositeMonikerImpl_BindToObject(IMoniker *iface, IBindCtx *pbc, + IMoniker *toleft, REFIID riid, void **result) +{ + CompositeMonikerImpl *moniker = impl_from_IMoniker(iface); + IMoniker *left, *rightmost, *c; IRunningObjectTable *rot; IUnknown *object; HRESULT hr; - IMoniker *tempMk,*antiMk,*rightMostMk; - IEnumMoniker *enumMoniker; - TRACE("(%p,%p,%p,%s,%p)\n", iface, pbc, pmkToLeft, debugstr_guid(riid), result); + TRACE("%p, %p, %p, %s, %p.\n", iface, pbc, toleft, debugstr_guid(riid), result); if (!result) return E_POINTER; *result = NULL; - if (!pmkToLeft) + if (!toleft) { hr = IBindCtx_GetRunningObjectTable(pbc, &rot); if (SUCCEEDED(hr)) @@ -343,25 +350,25 @@ static HRESULT WINAPI CompositeMonikerImpl_BindToObject(IMoniker *iface, IBindCt hr = IUnknown_QueryInterface(object, riid, result); IUnknown_Release(object); } + + return hr; } - else{ - /* If pmkToLeft is not NULL, the method recursively calls IMoniker::BindToObject on the rightmost */ - /* component of the composite, passing the rest of the composite as the pmkToLeft parameter for that call */ - IMoniker_Enum(iface,FALSE,&enumMoniker); - IEnumMoniker_Next(enumMoniker,1,&rightMostMk,NULL); - IEnumMoniker_Release(enumMoniker); + /* Try to bind rightmost component with (toleft, composite->left) composite at its left side */ + if (FAILED(hr = composite_get_rightmost(moniker, &left, &rightmost))) + return hr; - hr = CreateAntiMoniker(&antiMk); - hr = IMoniker_ComposeWith(iface,antiMk,0,&tempMk); - IMoniker_Release(antiMk); + hr = compose_with(toleft, left, &c); + IMoniker_Release(left); - hr = IMoniker_BindToObject(rightMostMk,pbc,tempMk,riid,result); - - IMoniker_Release(tempMk); - IMoniker_Release(rightMostMk); + if (SUCCEEDED(hr)) + { + hr = IMoniker_BindToObject(rightmost, pbc, c, riid, result); + IMoniker_Release(c); } + IMoniker_Release(rightmost); + return hr; } @@ -683,13 +690,6 @@ CompositeMonikerImpl_IsRunning(IMoniker* iface, IBindCtx* pbc, } } -static HRESULT compose_with(IMoniker *left, IMoniker *right, IMoniker **c) -{ - HRESULT hr = IMoniker_ComposeWith(left, right, TRUE, c); - if (FAILED(hr) && hr != MK_E_NEEDGENERIC) return hr; - return CreateGenericComposite(left, right, c); -} - static HRESULT WINAPI CompositeMonikerImpl_GetTimeOfLastChange(IMoniker *iface, IBindCtx *pbc, IMoniker *toleft, FILETIME *changetime) { diff --git a/dlls/ole32/tests/moniker.c b/dlls/ole32/tests/moniker.c index 2c257dcff50..795d8750d05 100644 --- a/dlls/ole32/tests/moniker.c +++ b/dlls/ole32/tests/moniker.c @@ -3108,7 +3108,7 @@ static void test_generic_composite_moniker(void) { "CI1I2", "A3", MKSYS_ANTIMONIKER, L"\\.." }, { "CI1I3", "CA1I2", MKSYS_GENERICCOMPOSITE, L"!I1!I2" }, }; - IMoniker *moniker, *inverse, *moniker1, *moniker2, *moniker3; + IMoniker *moniker, *inverse, *moniker1, *moniker2, *moniker3, *moniker4; struct test_moniker *m, *m2; IEnumMoniker *enummoniker; IRunningObjectTable *rot; @@ -3267,10 +3267,45 @@ todo_wine hr = IRunningObjectTable_Revoke(rot, cookie); ok(hr == S_OK, "Unexpected hr %#x.\n", hr); - IRunningObjectTable_Release(rot); - IMoniker_Release(moniker); + /* BindToObject() with moniker at left */ + hr = CreatePointerMoniker((IUnknown *)rot, &moniker); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + + /* (I1,P) */ + hr = create_moniker_from_desc("I1", &moniker2); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + + hr = CreateGenericComposite(moniker2, moniker, &moniker3); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + + hr = IMoniker_BindToObject(moniker3, bindctx, moniker2, &IID_IMoniker, (void **)&unknown); + ok(hr == E_NOINTERFACE, "Unexpected hr %#x.\n", hr); + + /* Register (I1,I1,P), check if ROT is used for left != NULL case */ + hr = CreateGenericComposite(moniker2, moniker3, &moniker4); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + + cookie = 0; + hr = IRunningObjectTable_Register(rot, ROTFLAGS_REGISTRATIONKEEPSALIVE, (IUnknown *)moniker4, + moniker4, &cookie); +todo_wine + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + + hr = IMoniker_BindToObject(moniker3, bindctx, moniker2, &IID_IMoniker, (void **)&unknown); + ok(hr == E_NOINTERFACE, "Unexpected hr %#x.\n", hr); + + hr = IRunningObjectTable_Revoke(rot, cookie); +todo_wine + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + + IMoniker_Release(moniker3); + IMoniker_Release(moniker2); + IMoniker_Release(moniker); + + IRunningObjectTable_Release(rot); + /* Uninitialized composite */ hr = CoCreateInstance(&CLSID_CompositeMoniker, NULL, CLSCTX_SERVER, &IID_IMoniker, (void **)&moniker); ok(hr == S_OK, "Unexpected hr %#x.\n", hr);