From: Vibhav Pant <vibhavp@gmail.com> --- dlls/combase/roapi.c | 49 ++++++++++++++++++++++++++++++++++---- dlls/combase/tests/roapi.c | 8 +++---- 2 files changed, 49 insertions(+), 8 deletions(-) diff --git a/dlls/combase/roapi.c b/dlls/combase/roapi.c index f4f7c0aac26..6085b4897a1 100644 --- a/dlls/combase/roapi.c +++ b/dlls/combase/roapi.c @@ -18,6 +18,8 @@ */ #define COBJMACROS #include "objbase.h" +#include "ctxtcall.h" +#include "comsvcs.h" #include "initguid.h" #include "roapi.h" #include "roparameterizediid.h" @@ -246,6 +248,7 @@ struct agile_reference CRITICAL_SECTION cs; IUnknown *obj; BOOLEAN is_agile; + IUnknown *ctx; LONG ref; }; @@ -324,10 +327,28 @@ static ULONG WINAPI agile_ref_Release(IAgileReference *iface) return ref; } +struct marshal_context_params +{ + struct agile_reference *impl; + REFIID iid; +}; + +static HRESULT WINAPI marshal_object_in_context(ComCallData *arg) +{ + struct marshal_context_params *params = (struct marshal_context_params *)arg; + HRESULT hr; + + hr = marshal_object_in_agile_reference(params->impl, params->iid, params->impl->obj); + IUnknown_Release(params->impl->obj); + params->impl->obj = NULL; + return hr; +} + static HRESULT WINAPI agile_ref_Resolve(IAgileReference *iface, REFIID riid, void **obj) { struct agile_reference *impl = impl_from_IAgileReference(iface); LARGE_INTEGER zero = {0}; + void *cur_ctx; HRESULT hr; TRACE("(%p, %s, %p)\n", iface, debugstr_guid(riid), obj); @@ -335,17 +356,29 @@ static HRESULT WINAPI agile_ref_Resolve(IAgileReference *iface, REFIID riid, voi if (impl->is_agile) return IUnknown_QueryInterface(impl->obj, riid, obj); + if (FAILED(hr = CoGetContextToken((ULONG_PTR *)&cur_ctx))) + return hr; + EnterCriticalSection(&impl->cs); if (impl->option == AGILEREFERENCE_DELAYEDMARSHAL && impl->marshal_stream == NULL) { - if (FAILED(hr = marshal_object_in_agile_reference(impl, riid, impl->obj))) + struct marshal_context_params params = { impl, riid }; + IContextCallback *ctx; + + if (FAILED(hr = IUnknown_QueryInterface(impl->ctx, &IID_IContextCallback, (void **)&ctx))) { LeaveCriticalSection(&impl->cs); return hr; } - IUnknown_Release(impl->obj); - impl->obj = NULL; + hr = IContextCallback_ContextCallback(ctx, marshal_object_in_context, (ComCallData *)¶ms, + &IID_IContextCallback, 5, NULL); + IContextCallback_Release(ctx); + if (FAILED(hr)) + { + LeaveCriticalSection(&impl->cs); + return hr; + } } if (SUCCEEDED(hr = IStream_Seek(impl->marshal_stream, zero, STREAM_SEEK_SET, NULL))) @@ -380,6 +413,7 @@ static BOOL object_has_interface(IUnknown *obj, REFIID iid) HRESULT WINAPI RoGetAgileReference(enum AgileReferenceOptions option, REFIID riid, IUnknown *obj, IAgileReference **agile_reference) { + struct apartment *apt; struct agile_reference *impl; HRESULT hr; @@ -388,11 +422,13 @@ HRESULT WINAPI RoGetAgileReference(enum AgileReferenceOptions option, REFIID rii if (option != AGILEREFERENCE_DEFAULT && option != AGILEREFERENCE_DELAYEDMARSHAL) return E_INVALIDARG; - if (!InternalIsProcessInitialized()) + if (!(apt = apartment_get_current_or_mta())) { ERR("Apartment not initialized\n"); return CO_E_NOTINITIALIZED; } + rpc_start_remoting(apt); + apartment_release(apt); if (!object_has_interface(obj, riid)) return E_NOINTERFACE; @@ -407,6 +443,11 @@ HRESULT WINAPI RoGetAgileReference(enum AgileReferenceOptions option, REFIID rii impl->option = option; impl->is_agile = object_has_interface(obj, &IID_IAgileObject); impl->ref = 1; + if (FAILED(hr = CoGetContextToken((ULONG_PTR *)&impl->ctx))) + { + free( impl ); + return hr; + } if (option == AGILEREFERENCE_DELAYEDMARSHAL || impl->is_agile) { diff --git a/dlls/combase/tests/roapi.c b/dlls/combase/tests/roapi.c index 125244c5c3a..93a3f94f2f1 100644 --- a/dlls/combase/tests/roapi.c +++ b/dlls/combase/tests/roapi.c @@ -484,11 +484,11 @@ static void test_apartment_context_(int line, const struct unk_ctx_impl *impl) ok_(__FILE__, line)(hr == S_OK, "CoGetContextToken failed, got hr %#lx\n", hr); /* As this object has apartment-affinity, its methods can only be called from the apartment and context it was * created in. */ - todo_wine_if(impl->todo) ok_(__FILE__, line)(cur_ctx == impl->context, "got cur_ctx %#Ix != %#Ix\n", cur_ctx, impl->context); + ok_(__FILE__, line)(cur_ctx == impl->context, "got cur_ctx %#Ix != %#Ix\n", cur_ctx, impl->context); hr = CoGetApartmentType(&type, &qualifier); ok_(__FILE__, line)(hr == S_OK, "CoGetApartmentType failed, got hr %#lx\n", hr); - todo_wine_if(impl->todo) ok_(__FILE__, line)(type == impl->type, "got type %d\n", type); + ok_(__FILE__, line)(type == impl->type, "got type %d\n", type); hr = RoGetApartmentIdentifier(&cur_id); ok_(__FILE__, line)(hr == S_OK || broken(hr == HRESULT_FROM_WIN32(ERROR_API_UNAVAILABLE)), @@ -518,7 +518,7 @@ static void test_apartment_context_(int line, const struct unk_ctx_impl *impl) /* If this object belongs to an STA, we should now be in the same thread that the object was created in. */ if (impl->type == APTTYPE_STA || impl->type == APTTYPE_MAINSTA) { - todo_wine ok(cur_tid == impl->thread_id, "Got cur_tid %lu != %lu\n", cur_tid, impl->thread_id); + ok(cur_tid == impl->thread_id, "Got cur_tid %lu != %lu\n", cur_tid, impl->thread_id); ok(!IsEqualGUID(&ctx_com_tid, &impl->com_thread_id), "Got cur_com_tid %s != %s\n", debugstr_guid(&ctx_com_tid), debugstr_guid(&impl->com_thread_id)); } @@ -676,7 +676,7 @@ static DWORD CALLBACK test_agile_resolve_context(void *arg) winetest_push_context("from_type=%d, to_type=%d", params->from_type, params->to_type); hr = IAgileReference_Resolve(params->ref, &IID_IUnknown, (void **)&unknown); - todo_wine_if(params->to_type == RO_INIT_MULTITHREADED) ok(hr == S_OK, "got hr %#lx\n", hr); + ok(hr == S_OK, "got hr %#lx\n", hr); if (SUCCEEDED(hr)) IUnknown_Release(unknown); winetest_pop_context(); -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/11018