diff --git a/dlls/ole32/compobj_private.h b/dlls/ole32/compobj_private.h index 6abfdfd07e8..cfee6e39b44 100644 --- a/dlls/ole32/compobj_private.h +++ b/dlls/ole32/compobj_private.h @@ -168,6 +168,7 @@ struct oletls IErrorInfo *errorinfo; /* see errorinfo.c */ IUnknown *state; /* see CoSetState */ DWORD inits; /* number of times CoInitializeEx called */ + DWORD ole_inits; /* number of times OleInitialize called */ GUID causality_id; /* unique identifier for each COM call */ LONG pending_call_count_client; /* number of client calls pending */ LONG pending_call_count_server; /* number of server calls pending */ diff --git a/dlls/ole32/ole2.c b/dlls/ole32/ole2.c index 5da68fc4477..fa02c42ce3e 100644 --- a/dlls/ole32/ole2.c +++ b/dlls/ole32/ole2.c @@ -107,7 +107,7 @@ static OleMenuHookItem *hook_list; * This is the lock count on the OLE library. It is controlled by the * OLEInitialize/OLEUninitialize methods. */ -static ULONG OLE_moduleLockCount = 0; +static LONG OLE_moduleLockCount = 0; /* * Name of our registered window class. @@ -203,7 +203,8 @@ HRESULT WINAPI OleInitialize(LPVOID reserved) * Object linking and Embedding * In-place activation */ - if (OLE_moduleLockCount==0) + if (!COM_CurrentInfo()->ole_inits++ && + InterlockedIncrement(&OLE_moduleLockCount) == 1) { /* * Initialize the libraries. @@ -226,11 +227,6 @@ HRESULT WINAPI OleInitialize(LPVOID reserved) OLEMenu_Initialize(); } - /* - * Then, we increase the lock count on the OLE module. - */ - OLE_moduleLockCount++; - return hr; } @@ -242,15 +238,10 @@ void WINAPI OleUninitialize(void) { TRACE("()\n"); - /* - * Decrease the lock count on the OLE module. - */ - OLE_moduleLockCount--; - /* * If we hit the bottom of the lock stack, free the libraries. */ - if (OLE_moduleLockCount==0) + if (!--COM_CurrentInfo()->ole_inits && !InterlockedDecrement(&OLE_moduleLockCount)) { /* * Actually free the libraries.