ole: Change the Apartment Model field to a boolean. Change the apartment model field to a boolean that just specifies whether the apartment is multi-threaded or not and fix up all the places where this is used. Fixes a bug where we would return an error if the previous apartment model passed into CoInitializeEx matches the new apartment model, but additional optimisation flags are specified.
diff --git a/dlls/ole32/compobj.c b/dlls/ole32/compobj.c index ab44b20..a757adb 100644 --- a/dlls/ole32/compobj.c +++ b/dlls/ole32/compobj.c
@@ -229,17 +229,17 @@ 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 @@ 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 @@ 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 @@ HWND apartment_getwindow(struct apartment *apt) { - assert(apt->model & COINIT_APARTMENTTHREADED); + assert(!apt->multi_threaded); return apt->win; } @@ -633,11 +638,13 @@ 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 2e86a99..caa84de 100644 --- a/dlls/ole32/compobj_private.h +++ b/dlls/ole32/compobj_private.h
@@ -132,10 +132,10 @@ /* 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 05becb2..806c323 100644 --- a/dlls/ole32/rpc.c +++ b/dlls/ole32/rpc.c
@@ -277,7 +277,7 @@ 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 @@ /* 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);