diff --git a/dlls/msctf/msctf.c b/dlls/msctf/msctf.c index 254444bacb7..7dc1bcd6000 100644 --- a/dlls/msctf/msctf.c +++ b/dlls/msctf/msctf.c @@ -43,6 +43,8 @@ static LONG MSCTF_refCount; static HINSTANCE MSCTF_hinstance; +DWORD tlsIndex = 0; + typedef HRESULT (*LPFNCONSTRUCTOR)(IUnknown *pUnkOuter, IUnknown **ppvOut); static const struct { @@ -159,8 +161,11 @@ BOOL WINAPI DllMain(HINSTANCE hinst, DWORD fdwReason, LPVOID fImpLoad) case DLL_WINE_PREATTACH: return FALSE; /* prefer native version */ case DLL_PROCESS_ATTACH: - DisableThreadLibraryCalls(hinst); MSCTF_hinstance = hinst; + tlsIndex = TlsAlloc(); + break; + case DLL_PROCESS_DETACH: + TlsFree(tlsIndex); break; } return TRUE; diff --git a/dlls/msctf/msctf_internal.h b/dlls/msctf/msctf_internal.h index ee87a506d5c..fa4a6ef814d 100644 --- a/dlls/msctf/msctf_internal.h +++ b/dlls/msctf/msctf_internal.h @@ -20,6 +20,7 @@ #ifndef __WINE_MSCTF_I_H #define __WINE_MSCTF_I_H +extern DWORD tlsIndex; extern HRESULT ThreadMgr_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut); extern HRESULT DocumentMgr_Constructor(ITfDocumentMgr **ppOut); diff --git a/dlls/msctf/threadmgr.c b/dlls/msctf/threadmgr.c index b16f7ec1cbe..7385f0bde91 100644 --- a/dlls/msctf/threadmgr.c +++ b/dlls/msctf/threadmgr.c @@ -49,6 +49,7 @@ typedef struct tagACLMulti { static void ThreadMgr_Destructor(ThreadMgr *This) { + TlsSetValue(tlsIndex,NULL); TRACE("destroying %p\n", This); if (This->focus) ITfDocumentMgr_Release(This->focus); @@ -227,12 +228,22 @@ HRESULT ThreadMgr_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut) if (pUnkOuter) return CLASS_E_NOAGGREGATION; + /* Only 1 ThreadMgr is created per thread */ + This = TlsGetValue(tlsIndex); + if (This) + { + ThreadMgr_AddRef((ITfThreadMgr*)This); + *ppOut = (IUnknown*)This; + return S_OK; + } + This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ThreadMgr)); if (This == NULL) return E_OUTOFMEMORY; This->ThreadMgrVtbl= &ThreadMgr_ThreadMgrVtbl; This->refCount = 1; + TlsSetValue(tlsIndex,This); TRACE("returning %p\n", This); *ppOut = (IUnknown *)This;