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.
This commit is contained in:
Robert Shearman 2006-01-09 18:41:19 +01:00 committed by Alexandre Julliard
parent 1eda42ccac
commit b75db2d9de
3 changed files with 20 additions and 0 deletions

View File

@ -422,6 +422,12 @@ static LRESULT CALLBACK apartment_wndproc(HWND hWnd, UINT msg, WPARAM wParam, LP
}
}
void apartment_joinmta(void)
{
apartment_addref(MTA);
COM_CurrentInfo()->apt = MTA;
}
/*****************************************************************************
* This section contains OpenDllList implemantation
*/

View File

@ -228,6 +228,7 @@ static inline HRESULT apartment_getoxid(struct apartment *apt, OXID *oxid)
*oxid = apt->oxid;
return S_OK;
}
void apartment_joinmta(void);
/* DCOM messages used by the apartment window (not compatible with native) */

View File

@ -503,7 +503,20 @@ static void __RPC_STUB dispatch_rpc(RPC_MESSAGE *msg)
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);