ole: Join the MTA if necessary when executing an RPC call.
Join the MTA if necessary when executing an RPC call to ensure that it
is executing with a valid apartment and won't fail for certain COM
calls.
diff --git a/dlls/ole32/compobj.c b/dlls/ole32/compobj.c
index d28728e..6f33091 100644
--- a/dlls/ole32/compobj.c
+++ b/dlls/ole32/compobj.c
@@ -422,6 +422,12 @@
}
}
+void apartment_joinmta(void)
+{
+ apartment_addref(MTA);
+ COM_CurrentInfo()->apt = MTA;
+}
+
/*****************************************************************************
* This section contains OpenDllList implemantation
*/
diff --git a/dlls/ole32/compobj_private.h b/dlls/ole32/compobj_private.h
index 14a33b7..c7a1069 100644
--- a/dlls/ole32/compobj_private.h
+++ b/dlls/ole32/compobj_private.h
@@ -228,6 +228,7 @@
*oxid = apt->oxid;
return S_OK;
}
+void apartment_joinmta(void);
/* DCOM messages used by the apartment window (not compatible with native) */
diff --git a/dlls/ole32/rpc.c b/dlls/ole32/rpc.c
index 09fb902..ba8ad10 100644
--- a/dlls/ole32/rpc.c
+++ b/dlls/ole32/rpc.c
@@ -503,7 +503,20 @@
CloseHandle(params->handle);
}
else
+ {
+ BOOL joined = FALSE;
+ if (!COM_CurrentInfo()->apt)
+ {
+ apartment_joinmta();
+ joined = TRUE;
+ }
RPC_ExecuteCall(params);
+ if (joined)
+ {
+ apartment_release(COM_CurrentInfo()->apt);
+ COM_CurrentInfo()->apt = NULL;
+ }
+ }
HeapFree(GetProcessHeap(), 0, params);