diff --git a/dlls/ole32/compobj.c b/dlls/ole32/compobj.c index b3801eb1999..627371c8dcf 100644 --- a/dlls/ole32/compobj.c +++ b/dlls/ole32/compobj.c @@ -2034,40 +2034,69 @@ HRESULT WINAPI CoInitializeWOW(DWORD x,DWORD y) { /*********************************************************************** * CoGetState [OLE32.@] * - * NOTES: might be incomplete + * Retrieves the thread state object previously stored by CoSetState(). + * + * PARAMS + * ppv [I] Address where pointer to object will be stored. + * + * RETURNS + * Success: S_OK. + * Failure: E_OUTOFMEMORY. + * + * NOTES + * Crashes on all invalid ppv addresses, including NULL. + * If the function returns a non-NULL object then the caller must release its + * reference on the object when the object is no longer required. + * + * SEE ALSO + * CoSetState(). */ HRESULT WINAPI CoGetState(IUnknown ** ppv) { - HRESULT hr = E_FAIL; + struct oletls *info = COM_CurrentInfo(); + if (!info) return E_OUTOFMEMORY; *ppv = NULL; - if (COM_CurrentInfo()->state) + if (info->state) { - IUnknown_AddRef(COM_CurrentInfo()->state); - *ppv = COM_CurrentInfo()->state; - TRACE("apt->state=%p\n", COM_CurrentInfo()->state); - hr = S_OK; + IUnknown_AddRef(info->state); + *ppv = info->state; + TRACE("apt->state=%p\n", info->state); } - return hr; + return S_OK; } /*********************************************************************** * CoSetState [OLE32.@] * + * Sets the thread state object. + * + * PARAMS + * pv [I] Pointer to state object to be stored. + * + * NOTES + * The system keeps a reference on the object while the object stored. + * + * RETURNS + * Success: S_OK. + * Failure: E_OUTOFMEMORY. */ HRESULT WINAPI CoSetState(IUnknown * pv) { + struct oletls *info = COM_CurrentInfo(); + if (!info) return E_OUTOFMEMORY; + if (pv) IUnknown_AddRef(pv); - if (COM_CurrentInfo()->state) + if (info->state) { - TRACE("-- release %p now\n", COM_CurrentInfo()->state); - IUnknown_Release(COM_CurrentInfo()->state); + TRACE("-- release %p now\n", info->state); + IUnknown_Release(info->state); } - COM_CurrentInfo()->state = pv; + info->state = pv; return S_OK; } diff --git a/dlls/ole32/compobj_private.h b/dlls/ole32/compobj_private.h index ea1f657cb8f..25a139852e7 100644 --- a/dlls/ole32/compobj_private.h +++ b/dlls/ole32/compobj_private.h @@ -227,9 +227,9 @@ struct oletls /* will create if necessary */ static inline struct oletls *COM_CurrentInfo(void) { - if (!NtCurrentTeb()->ReservedForOle) + if (!NtCurrentTeb()->ReservedForOle) NtCurrentTeb()->ReservedForOle = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct oletls)); - + return NtCurrentTeb()->ReservedForOle; }