diff --git a/dlls/ole32/compobj.c b/dlls/ole32/compobj.c index ab44b202a12..a757adbf6db 100644 --- a/dlls/ole32/compobj.c +++ b/dlls/ole32/compobj.c @@ -229,17 +229,17 @@ static APARTMENT *apartment_construct(DWORD model) InitializeCriticalSection(&apt->cs); DEBUG_SET_CRITSEC_NAME(&apt->cs, "apartment"); - apt->model = model; + apt->multi_threaded = !(model & COINIT_APARTMENTTHREADED); - if (model & COINIT_APARTMENTTHREADED) + if (apt->multi_threaded) { /* FIXME: should be randomly generated by in an RPC call to rpcss */ - apt->oxid = ((OXID)GetCurrentProcessId() << 32) | GetCurrentThreadId(); + apt->oxid = ((OXID)GetCurrentProcessId() << 32) | 0xcafe; } else { /* FIXME: should be randomly generated by in an RPC call to rpcss */ - apt->oxid = ((OXID)GetCurrentProcessId() << 32) | 0xcafe; + apt->oxid = ((OXID)GetCurrentProcessId() << 32) | GetCurrentThreadId(); } TRACE("Created apartment on OXID %s\n", wine_dbgstr_longlong(apt->oxid)); @@ -292,6 +292,11 @@ static APARTMENT *apartment_get_or_create(DWORD model) return apt; } +static inline BOOL apartment_is_model(APARTMENT *apt, DWORD model) +{ + return (apt->multi_threaded == !(model & COINIT_APARTMENTTHREADED)); +} + DWORD apartment_addref(struct apartment *apt) { DWORD refs = InterlockedIncrement(&apt->refs); @@ -420,7 +425,7 @@ static LRESULT CALLBACK apartment_wndproc(HWND hWnd, UINT msg, WPARAM wParam, LP HRESULT apartment_createwindowifneeded(struct apartment *apt) { - if (!(apt->model & COINIT_APARTMENTTHREADED)) + if (apt->multi_threaded) return S_OK; if (!apt->win) @@ -443,7 +448,7 @@ HRESULT apartment_createwindowifneeded(struct apartment *apt) HWND apartment_getwindow(struct apartment *apt) { - assert(apt->model & COINIT_APARTMENTTHREADED); + assert(!apt->multi_threaded); return apt->win; } @@ -633,11 +638,13 @@ HRESULT WINAPI CoInitializeEx(LPVOID lpReserved, DWORD dwCoInit) apt = apartment_get_or_create(dwCoInit); if (!apt) return E_OUTOFMEMORY; } - else if (dwCoInit != apt->model) + else if (!apartment_is_model(apt, dwCoInit)) { /* Changing the threading model after it's been set is illegal. If this warning is triggered by Wine code then we are probably using the wrong threading model to implement that API. */ - ERR("Attempt to change threading model of this apartment from 0x%lx to 0x%lx\n", apt->model, dwCoInit); + ERR("Attempt to change threading model of this apartment from %s to %s\n", + apt->multi_threaded ? "multi-threaded" : "apartment threaded", + dwCoInit & COINIT_APARTMENTTHREADED ? "apartment threaded" : "multi-threaded"); return RPC_E_CHANGED_MODE; } else diff --git a/dlls/ole32/compobj_private.h b/dlls/ole32/compobj_private.h index 2e86a9935d8..caa84de7a8f 100644 --- a/dlls/ole32/compobj_private.h +++ b/dlls/ole32/compobj_private.h @@ -132,10 +132,10 @@ struct proxy_manager /* this needs to become a COM object that implements IRemUnknown */ struct apartment { - struct list entry; + struct list entry; LONG refs; /* refcount of the apartment (LOCK) */ - DWORD model; /* threading model (RO) */ + BOOL multi_threaded; /* multi-threaded or single-threaded apartment? (RO) */ DWORD tid; /* thread id (RO) */ OXID oxid; /* object exporter ID (RO) */ LONG ipidc; /* interface pointer ID counter, starts at 1 (LOCK) */ diff --git a/dlls/ole32/rpc.c b/dlls/ole32/rpc.c index 05becb219e4..806c323d4fb 100644 --- a/dlls/ole32/rpc.c +++ b/dlls/ole32/rpc.c @@ -277,7 +277,7 @@ static HRESULT WINAPI ClientRpcChannelBuffer_SendReceive(LPRPCCHANNELBUFFER ifac RpcBindingInqObject(msg->Handle, &ipid); hr = ipid_get_dispatch_params(&ipid, &apt, ¶ms->stub, ¶ms->chan); - if ((hr == S_OK) && (apt->model & COINIT_APARTMENTTHREADED)) + if ((hr == S_OK) && !apt->multi_threaded) { params->handle = CreateEventW(NULL, FALSE, FALSE, NULL); @@ -536,7 +536,7 @@ static void __RPC_STUB dispatch_rpc(RPC_MESSAGE *msg) /* Note: this is the important difference between STAs and MTAs - we * always execute RPCs to STAs in the thread that originally created the * apartment (i.e. the one that pumps messages to the window) */ - if (apt->model & COINIT_APARTMENTTHREADED) + if (!apt->multi_threaded) { params->handle = CreateEventW(NULL, FALSE, FALSE, NULL);