* Sync up to trunk HEAD (r62975).
[reactos.git] / dll / win32 / msctf / threadmgr.c
index 9858ef8..3b6611c 100644 (file)
@@ -57,22 +57,22 @@ typedef struct tagAssociatedWindow
 } AssociatedWindow;
 
 typedef struct tagACLMulti {
-    const ITfThreadMgrVtbl *ThreadMgrVtbl;
-    const ITfSourceVtbl *SourceVtbl;
-    const ITfKeystrokeMgrVtbl *KeystrokeMgrVtbl;
-    const ITfMessagePumpVtbl *MessagePumpVtbl;
-    const ITfClientIdVtbl *ClientIdVtbl;
+    ITfThreadMgr ITfThreadMgr_iface;
+    ITfSource ITfSource_iface;
+    ITfKeystrokeMgr ITfKeystrokeMgr_iface;
+    ITfMessagePump ITfMessagePump_iface;
+    ITfClientId ITfClientId_iface;
     /* const ITfThreadMgrExVtbl *ThreadMgrExVtbl; */
     /* const ITfConfigureSystemKeystrokeFeedVtbl *ConfigureSystemKeystrokeFeedVtbl; */
     /* const ITfLangBarItemMgrVtbl *LangBarItemMgrVtbl; */
     /* const ITfUIElementMgrVtbl *UIElementMgrVtbl; */
-    const ITfSourceSingleVtbl *SourceSingleVtbl;
+    ITfSourceSingle ITfSourceSingle_iface;
     LONG refCount;
 
     /* Aggregation */
     ITfCompartmentMgr  *CompartmentMgr;
 
-    const ITfThreadMgrEventSinkVtbl *ThreadMgrEventSinkVtbl; /* internal */
+    ITfThreadMgrEventSink ITfThreadMgrEventSink_iface; /* internal */
 
     ITfDocumentMgr *focus;
     LONG activationCount;
@@ -96,7 +96,7 @@ typedef struct tagACLMulti {
 } ThreadMgr;
 
 typedef struct tagEnumTfDocumentMgr {
-    const IEnumTfDocumentMgrsVtbl *Vtbl;
+    IEnumTfDocumentMgrs IEnumTfDocumentMgrs_iface;
     LONG refCount;
 
     struct list *index;
@@ -105,35 +105,44 @@ typedef struct tagEnumTfDocumentMgr {
 
 static HRESULT EnumTfDocumentMgr_Constructor(struct list* head, IEnumTfDocumentMgrs **ppOut);
 
-static inline ThreadMgr *impl_from_ITfSourceVtbl(ITfSource *iface)
+static inline ThreadMgr *impl_from_ITfThreadMgr(ITfThreadMgr *iface)
 {
-    return (ThreadMgr *)((char *)iface - FIELD_OFFSET(ThreadMgr,SourceVtbl));
+    return CONTAINING_RECORD(iface, ThreadMgr, ITfThreadMgr_iface);
 }
 
-static inline ThreadMgr *impl_from_ITfKeystrokeMgrVtbl(ITfKeystrokeMgr *iface)
+static inline ThreadMgr *impl_from_ITfSource(ITfSource *iface)
 {
-    return (ThreadMgr *)((char *)iface - FIELD_OFFSET(ThreadMgr,KeystrokeMgrVtbl));
+    return CONTAINING_RECORD(iface, ThreadMgr, ITfSource_iface);
 }
 
-static inline ThreadMgr *impl_from_ITfMessagePumpVtbl(ITfMessagePump *iface)
+static inline ThreadMgr *impl_from_ITfKeystrokeMgr(ITfKeystrokeMgr *iface)
 {
-    return (ThreadMgr *)((char *)iface - FIELD_OFFSET(ThreadMgr,MessagePumpVtbl));
+    return CONTAINING_RECORD(iface, ThreadMgr, ITfKeystrokeMgr_iface);
 }
 
-static inline ThreadMgr *impl_from_ITfClientIdVtbl(ITfClientId *iface)
+static inline ThreadMgr *impl_from_ITfMessagePump(ITfMessagePump *iface)
 {
-    return (ThreadMgr *)((char *)iface - FIELD_OFFSET(ThreadMgr,ClientIdVtbl));
+    return CONTAINING_RECORD(iface, ThreadMgr, ITfMessagePump_iface);
+}
+
+static inline ThreadMgr *impl_from_ITfClientId(ITfClientId *iface)
+{
+    return CONTAINING_RECORD(iface, ThreadMgr, ITfClientId_iface);
 }
 
 static inline ThreadMgr *impl_from_ITfThreadMgrEventSink(ITfThreadMgrEventSink *iface)
 {
-    return (ThreadMgr *)((char *)iface - FIELD_OFFSET(ThreadMgr,ThreadMgrEventSinkVtbl));
+    return CONTAINING_RECORD(iface, ThreadMgr, ITfThreadMgrEventSink_iface);
 }
 
-static inline ThreadMgr *impl_from_ITfSourceSingleVtbl(ITfSourceSingle* iface)
+static inline ThreadMgr *impl_from_ITfSourceSingle(ITfSourceSingle *iface)
+{
+    return CONTAINING_RECORD(iface, ThreadMgr, ITfSourceSingle_iface);
+}
 
+static inline EnumTfDocumentMgr *impl_from_IEnumTfDocumentMgrs(IEnumTfDocumentMgrs *iface)
 {
-    return (ThreadMgr *)((char *)iface - FIELD_OFFSET(ThreadMgr,SourceSingleVtbl));
+    return CONTAINING_RECORD(iface, EnumTfDocumentMgr, IEnumTfDocumentMgrs_iface);
 }
 
 static void free_sink(ThreadMgrSink *sink)
@@ -223,28 +232,28 @@ static void ThreadMgr_Destructor(ThreadMgr *This)
 
 static HRESULT WINAPI ThreadMgr_QueryInterface(ITfThreadMgr *iface, REFIID iid, LPVOID *ppvOut)
 {
-    ThreadMgr *This = (ThreadMgr *)iface;
+    ThreadMgr *This = impl_from_ITfThreadMgr(iface);
     *ppvOut = NULL;
 
     if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfThreadMgr))
     {
-        *ppvOut = This;
+        *ppvOut = &This->ITfThreadMgr_iface;
     }
     else if (IsEqualIID(iid, &IID_ITfSource))
     {
-        *ppvOut = &This->SourceVtbl;
+        *ppvOut = &This->ITfSource_iface;
     }
     else if (IsEqualIID(iid, &IID_ITfKeystrokeMgr))
     {
-        *ppvOut = &This->KeystrokeMgrVtbl;
+        *ppvOut = &This->ITfKeystrokeMgr_iface;
     }
     else if (IsEqualIID(iid, &IID_ITfMessagePump))
     {
-        *ppvOut = &This->MessagePumpVtbl;
+        *ppvOut = &This->ITfMessagePump_iface;
     }
     else if (IsEqualIID(iid, &IID_ITfClientId))
     {
-        *ppvOut = &This->ClientIdVtbl;
+        *ppvOut = &This->ITfClientId_iface;
     }
     else if (IsEqualIID(iid, &IID_ITfCompartmentMgr))
     {
@@ -252,7 +261,7 @@ static HRESULT WINAPI ThreadMgr_QueryInterface(ITfThreadMgr *iface, REFIID iid,
     }
     else if (IsEqualIID(iid, &IID_ITfSourceSingle))
     {
-        *ppvOut = &This->SourceSingleVtbl;
+        *ppvOut = &This->ITfSourceSingle_iface;
     }
 
     if (*ppvOut)
@@ -267,13 +276,13 @@ static HRESULT WINAPI ThreadMgr_QueryInterface(ITfThreadMgr *iface, REFIID iid,
 
 static ULONG WINAPI ThreadMgr_AddRef(ITfThreadMgr *iface)
 {
-    ThreadMgr *This = (ThreadMgr *)iface;
+    ThreadMgr *This = impl_from_ITfThreadMgr(iface);
     return InterlockedIncrement(&This->refCount);
 }
 
 static ULONG WINAPI ThreadMgr_Release(ITfThreadMgr *iface)
 {
-    ThreadMgr *This = (ThreadMgr *)iface;
+    ThreadMgr *This = impl_from_ITfThreadMgr(iface);
     ULONG ret;
 
     ret = InterlockedDecrement(&This->refCount);
@@ -288,7 +297,7 @@ static ULONG WINAPI ThreadMgr_Release(ITfThreadMgr *iface)
 
 static HRESULT WINAPI ThreadMgr_fnActivate( ITfThreadMgr* iface, TfClientId *ptid)
 {
-    ThreadMgr *This = (ThreadMgr *)iface;
+    ThreadMgr *This = impl_from_ITfThreadMgr(iface);
 
     TRACE("(%p) %p\n",This, ptid);
 
@@ -299,7 +308,7 @@ static HRESULT WINAPI ThreadMgr_fnActivate( ITfThreadMgr* iface, TfClientId *pti
     {
         GUID guid;
         CoCreateGuid(&guid);
-        ITfClientId_GetClientId((ITfClientId*)&This->ClientIdVtbl,&guid,&processId);
+        ITfClientId_GetClientId(&This->ITfClientId_iface, &guid, &processId);
     }
 
     activate_textservices(iface);
@@ -310,7 +319,7 @@ static HRESULT WINAPI ThreadMgr_fnActivate( ITfThreadMgr* iface, TfClientId *pti
 
 static HRESULT WINAPI ThreadMgr_fnDeactivate( ITfThreadMgr* iface)
 {
-    ThreadMgr *This = (ThreadMgr *)iface;
+    ThreadMgr *This = impl_from_ITfThreadMgr(iface);
     TRACE("(%p)\n",This);
 
     if (This->activationCount == 0)
@@ -322,7 +331,7 @@ static HRESULT WINAPI ThreadMgr_fnDeactivate( ITfThreadMgr* iface)
     {
         if (This->focus)
         {
-            ITfThreadMgrEventSink_OnSetFocus((ITfThreadMgrEventSink*)&This->ThreadMgrEventSinkVtbl, 0, This->focus);
+            ITfThreadMgrEventSink_OnSetFocus(&This->ITfThreadMgrEventSink_iface, 0, This->focus);
             ITfDocumentMgr_Release(This->focus);
             This->focus = 0;
         }
@@ -333,10 +342,9 @@ static HRESULT WINAPI ThreadMgr_fnDeactivate( ITfThreadMgr* iface)
     return S_OK;
 }
 
-static HRESULT WINAPI ThreadMgr_CreateDocumentMgr( ITfThreadMgr* iface, ITfDocumentMgr
-**ppdim)
+static HRESULT WINAPI ThreadMgr_CreateDocumentMgr(ITfThreadMgr* iface, ITfDocumentMgr **ppdim)
 {
-    ThreadMgr *This = (ThreadMgr *)iface;
+    ThreadMgr *This = impl_from_ITfThreadMgr(iface);
     DocumentMgrEntry *mgrentry;
     HRESULT hr;
 
@@ -345,7 +353,7 @@ static HRESULT WINAPI ThreadMgr_CreateDocumentMgr( ITfThreadMgr* iface, ITfDocum
     if (mgrentry == NULL)
         return E_OUTOFMEMORY;
 
-    hr = DocumentMgr_Constructor((ITfThreadMgrEventSink*)&This->ThreadMgrEventSinkVtbl, ppdim);
+    hr = DocumentMgr_Constructor(&This->ITfThreadMgrEventSink_iface, ppdim);
 
     if (SUCCEEDED(hr))
     {
@@ -358,10 +366,9 @@ static HRESULT WINAPI ThreadMgr_CreateDocumentMgr( ITfThreadMgr* iface, ITfDocum
     return hr;
 }
 
-static HRESULT WINAPI ThreadMgr_EnumDocumentMgrs( ITfThreadMgr* iface, IEnumTfDocumentMgrs
-**ppEnum)
+static HRESULT WINAPI ThreadMgr_EnumDocumentMgrs( ITfThreadMgr* iface, IEnumTfDocumentMgrs **ppEnum)
 {
-    ThreadMgr *This = (ThreadMgr *)iface;
+    ThreadMgr *This = impl_from_ITfThreadMgr(iface);
     TRACE("(%p) %p\n",This,ppEnum);
 
     if (!ppEnum)
@@ -373,7 +380,7 @@ static HRESULT WINAPI ThreadMgr_EnumDocumentMgrs( ITfThreadMgr* iface, IEnumTfDo
 static HRESULT WINAPI ThreadMgr_GetFocus( ITfThreadMgr* iface, ITfDocumentMgr
 **ppdimFocus)
 {
-    ThreadMgr *This = (ThreadMgr *)iface;
+    ThreadMgr *This = impl_from_ITfThreadMgr(iface);
     TRACE("(%p)\n",This);
 
     if (!ppdimFocus)
@@ -393,8 +400,8 @@ static HRESULT WINAPI ThreadMgr_GetFocus( ITfThreadMgr* iface, ITfDocumentMgr
 
 static HRESULT WINAPI ThreadMgr_SetFocus( ITfThreadMgr* iface, ITfDocumentMgr *pdimFocus)
 {
+    ThreadMgr *This = impl_from_ITfThreadMgr(iface);
     ITfDocumentMgr *check;
-    ThreadMgr *This = (ThreadMgr *)iface;
 
     TRACE("(%p) %p\n",This,pdimFocus);
 
@@ -403,7 +410,7 @@ static HRESULT WINAPI ThreadMgr_SetFocus( ITfThreadMgr* iface, ITfDocumentMgr *p
     else if (FAILED(ITfDocumentMgr_QueryInterface(pdimFocus,&IID_ITfDocumentMgr,(LPVOID*) &check)))
         return E_INVALIDARG;
 
-    ITfThreadMgrEventSink_OnSetFocus((ITfThreadMgrEventSink*)&This->ThreadMgrEventSinkVtbl, check, This->focus);
+    ITfThreadMgrEventSink_OnSetFocus(&This->ITfThreadMgrEventSink_iface, check, This->focus);
 
     if (This->focus)
         ITfDocumentMgr_Release(This->focus);
@@ -467,8 +474,8 @@ static HRESULT SetupWindowsHook(ThreadMgr *This)
 static HRESULT WINAPI ThreadMgr_AssociateFocus( ITfThreadMgr* iface, HWND hwnd,
 ITfDocumentMgr *pdimNew, ITfDocumentMgr **ppdimPrev)
 {
+    ThreadMgr *This = impl_from_ITfThreadMgr(iface);
     struct list *cursor, *cursor2;
-    ThreadMgr *This = (ThreadMgr *)iface;
     AssociatedWindow *wnd;
 
     TRACE("(%p) %p %p %p\n",This,hwnd,pdimNew,ppdimPrev);
@@ -508,8 +515,9 @@ ITfDocumentMgr *pdimNew, ITfDocumentMgr **ppdimPrev)
 
 static HRESULT WINAPI ThreadMgr_IsThreadFocus( ITfThreadMgr* iface, BOOL *pfThreadFocus)
 {
+    ThreadMgr *This = impl_from_ITfThreadMgr(iface);
     HWND focus;
-    ThreadMgr *This = (ThreadMgr *)iface;
+
     TRACE("(%p) %p\n",This,pfThreadFocus);
     focus = GetFocus();
     *pfThreadFocus = (focus == NULL);
@@ -519,7 +527,7 @@ static HRESULT WINAPI ThreadMgr_IsThreadFocus( ITfThreadMgr* iface, BOOL *pfThre
 static HRESULT WINAPI ThreadMgr_GetFunctionProvider( ITfThreadMgr* iface, REFCLSID clsid,
 ITfFunctionProvider **ppFuncProv)
 {
-    ThreadMgr *This = (ThreadMgr *)iface;
+    ThreadMgr *This = impl_from_ITfThreadMgr(iface);
     FIXME("STUB:(%p)\n",This);
     return E_NOTIMPL;
 }
@@ -527,7 +535,7 @@ ITfFunctionProvider **ppFuncProv)
 static HRESULT WINAPI ThreadMgr_EnumFunctionProviders( ITfThreadMgr* iface,
 IEnumTfFunctionProviders **ppEnum)
 {
-    ThreadMgr *This = (ThreadMgr *)iface;
+    ThreadMgr *This = impl_from_ITfThreadMgr(iface);
     FIXME("STUB:(%p)\n",This);
     return E_NOTIMPL;
 }
@@ -535,7 +543,7 @@ IEnumTfFunctionProviders **ppEnum)
 static HRESULT WINAPI ThreadMgr_GetGlobalCompartment( ITfThreadMgr* iface,
 ITfCompartmentMgr **ppCompMgr)
 {
-    ThreadMgr *This = (ThreadMgr *)iface;
+    ThreadMgr *This = impl_from_ITfThreadMgr(iface);
     HRESULT hr;
     TRACE("(%p) %p\n",This, ppCompMgr);
 
@@ -554,12 +562,11 @@ ITfCompartmentMgr **ppCompMgr)
     return S_OK;
 }
 
-static const ITfThreadMgrVtbl ThreadMgr_ThreadMgrVtbl =
+static const ITfThreadMgrVtbl ThreadMgrVtbl =
 {
     ThreadMgr_QueryInterface,
     ThreadMgr_AddRef,
     ThreadMgr_Release,
-
     ThreadMgr_fnActivate,
     ThreadMgr_fnDeactivate,
     ThreadMgr_CreateDocumentMgr,
@@ -573,23 +580,22 @@ static const ITfThreadMgrVtbl ThreadMgr_ThreadMgrVtbl =
     ThreadMgr_GetGlobalCompartment
 };
 
-
 static HRESULT WINAPI Source_QueryInterface(ITfSource *iface, REFIID iid, LPVOID *ppvOut)
 {
-    ThreadMgr *This = impl_from_ITfSourceVtbl(iface);
-    return ThreadMgr_QueryInterface((ITfThreadMgr *)This, iid, *ppvOut);
+    ThreadMgr *This = impl_from_ITfSource(iface);
+    return ITfThreadMgr_QueryInterface(&This->ITfThreadMgr_iface, iid, ppvOut);
 }
 
 static ULONG WINAPI Source_AddRef(ITfSource *iface)
 {
-    ThreadMgr *This = impl_from_ITfSourceVtbl(iface);
-    return ThreadMgr_AddRef((ITfThreadMgr*)This);
+    ThreadMgr *This = impl_from_ITfSource(iface);
+    return ITfThreadMgr_AddRef(&This->ITfThreadMgr_iface);
 }
 
 static ULONG WINAPI Source_Release(ITfSource *iface)
 {
-    ThreadMgr *This = impl_from_ITfSourceVtbl(iface);
-    return ThreadMgr_Release((ITfThreadMgr *)This);
+    ThreadMgr *This = impl_from_ITfSource(iface);
+    return ITfThreadMgr_Release(&This->ITfThreadMgr_iface);
 }
 
 /*****************************************************
@@ -598,8 +604,8 @@ static ULONG WINAPI Source_Release(ITfSource *iface)
 static HRESULT WINAPI ThreadMgrSource_AdviseSink(ITfSource *iface,
         REFIID riid, IUnknown *punk, DWORD *pdwCookie)
 {
+    ThreadMgr *This = impl_from_ITfSource(iface);
     ThreadMgrSink *tms;
-    ThreadMgr *This = impl_from_ITfSourceVtbl(iface);
 
     TRACE("(%p) %s %p %p\n",This,debugstr_guid(riid),punk,pdwCookie);
 
@@ -632,8 +638,8 @@ static HRESULT WINAPI ThreadMgrSource_AdviseSink(ITfSource *iface,
 
 static HRESULT WINAPI ThreadMgrSource_UnadviseSink(ITfSource *iface, DWORD pdwCookie)
 {
+    ThreadMgr *This = impl_from_ITfSource(iface);
     ThreadMgrSink *sink;
-    ThreadMgr *This = impl_from_ITfSourceVtbl(iface);
 
     TRACE("(%p) %x\n",This,pdwCookie);
 
@@ -650,12 +656,11 @@ static HRESULT WINAPI ThreadMgrSource_UnadviseSink(ITfSource *iface, DWORD pdwCo
     return S_OK;
 }
 
-static const ITfSourceVtbl ThreadMgr_SourceVtbl =
+static const ITfSourceVtbl ThreadMgrSourceVtbl =
 {
     Source_QueryInterface,
     Source_AddRef,
     Source_Release,
-
     ThreadMgrSource_AdviseSink,
     ThreadMgrSource_UnadviseSink,
 };
@@ -666,26 +671,26 @@ static const ITfSourceVtbl ThreadMgr_SourceVtbl =
 
 static HRESULT WINAPI KeystrokeMgr_QueryInterface(ITfKeystrokeMgr *iface, REFIID iid, LPVOID *ppvOut)
 {
-    ThreadMgr *This = impl_from_ITfKeystrokeMgrVtbl(iface);
-    return ThreadMgr_QueryInterface((ITfThreadMgr *)This, iid, *ppvOut);
+    ThreadMgr *This = impl_from_ITfKeystrokeMgr(iface);
+    return ITfThreadMgr_QueryInterface(&This->ITfThreadMgr_iface, iid, ppvOut);
 }
 
 static ULONG WINAPI KeystrokeMgr_AddRef(ITfKeystrokeMgr *iface)
 {
-    ThreadMgr *This = impl_from_ITfKeystrokeMgrVtbl(iface);
-    return ThreadMgr_AddRef((ITfThreadMgr*)This);
+    ThreadMgr *This = impl_from_ITfKeystrokeMgr(iface);
+    return ITfThreadMgr_AddRef(&This->ITfThreadMgr_iface);
 }
 
 static ULONG WINAPI KeystrokeMgr_Release(ITfKeystrokeMgr *iface)
 {
-    ThreadMgr *This = impl_from_ITfKeystrokeMgrVtbl(iface);
-    return ThreadMgr_Release((ITfThreadMgr *)This);
+    ThreadMgr *This = impl_from_ITfKeystrokeMgr(iface);
+    return ITfThreadMgr_Release(&This->ITfThreadMgr_iface);
 }
 
 static HRESULT WINAPI KeystrokeMgr_AdviseKeyEventSink(ITfKeystrokeMgr *iface,
         TfClientId tid, ITfKeyEventSink *pSink, BOOL fForeground)
 {
-    ThreadMgr *This = impl_from_ITfKeystrokeMgrVtbl(iface);
+    ThreadMgr *This = impl_from_ITfKeystrokeMgr(iface);
     CLSID textservice;
     ITfKeyEventSink *check = NULL;
 
@@ -725,7 +730,7 @@ static HRESULT WINAPI KeystrokeMgr_AdviseKeyEventSink(ITfKeystrokeMgr *iface,
 static HRESULT WINAPI KeystrokeMgr_UnadviseKeyEventSink(ITfKeystrokeMgr *iface,
         TfClientId tid)
 {
-    ThreadMgr *This = impl_from_ITfKeystrokeMgrVtbl(iface);
+    ThreadMgr *This = impl_from_ITfKeystrokeMgr(iface);
     CLSID textservice;
     ITfKeyEventSink *check = NULL;
     TRACE("(%p) %x\n",This,tid);
@@ -757,7 +762,7 @@ static HRESULT WINAPI KeystrokeMgr_UnadviseKeyEventSink(ITfKeystrokeMgr *iface,
 static HRESULT WINAPI KeystrokeMgr_GetForeground(ITfKeystrokeMgr *iface,
         CLSID *pclsid)
 {
-    ThreadMgr *This = impl_from_ITfKeystrokeMgrVtbl(iface);
+    ThreadMgr *This = impl_from_ITfKeystrokeMgr(iface);
     TRACE("(%p) %p\n",This,pclsid);
     if (!pclsid)
         return E_INVALIDARG;
@@ -772,7 +777,7 @@ static HRESULT WINAPI KeystrokeMgr_GetForeground(ITfKeystrokeMgr *iface,
 static HRESULT WINAPI KeystrokeMgr_TestKeyDown(ITfKeystrokeMgr *iface,
         WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
 {
-    ThreadMgr *This = impl_from_ITfKeystrokeMgrVtbl(iface);
+    ThreadMgr *This = impl_from_ITfKeystrokeMgr(iface);
     FIXME("STUB:(%p)\n",This);
     return E_NOTIMPL;
 }
@@ -780,7 +785,7 @@ static HRESULT WINAPI KeystrokeMgr_TestKeyDown(ITfKeystrokeMgr *iface,
 static HRESULT WINAPI KeystrokeMgr_TestKeyUp(ITfKeystrokeMgr *iface,
         WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
 {
-    ThreadMgr *This = impl_from_ITfKeystrokeMgrVtbl(iface);
+    ThreadMgr *This = impl_from_ITfKeystrokeMgr(iface);
     FIXME("STUB:(%p)\n",This);
     return E_NOTIMPL;
 }
@@ -788,7 +793,7 @@ static HRESULT WINAPI KeystrokeMgr_TestKeyUp(ITfKeystrokeMgr *iface,
 static HRESULT WINAPI KeystrokeMgr_KeyDown(ITfKeystrokeMgr *iface,
         WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
 {
-    ThreadMgr *This = impl_from_ITfKeystrokeMgrVtbl(iface);
+    ThreadMgr *This = impl_from_ITfKeystrokeMgr(iface);
     FIXME("STUB:(%p)\n",This);
     return E_NOTIMPL;
 }
@@ -796,7 +801,7 @@ static HRESULT WINAPI KeystrokeMgr_KeyDown(ITfKeystrokeMgr *iface,
 static HRESULT WINAPI KeystrokeMgr_KeyUp(ITfKeystrokeMgr *iface,
         WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
 {
-    ThreadMgr *This = impl_from_ITfKeystrokeMgrVtbl(iface);
+    ThreadMgr *This = impl_from_ITfKeystrokeMgr(iface);
     FIXME("STUB:(%p)\n",This);
     return E_NOTIMPL;
 }
@@ -804,7 +809,7 @@ static HRESULT WINAPI KeystrokeMgr_KeyUp(ITfKeystrokeMgr *iface,
 static HRESULT WINAPI KeystrokeMgr_GetPreservedKey(ITfKeystrokeMgr *iface,
         ITfContext *pic, const TF_PRESERVEDKEY *pprekey, GUID *pguid)
 {
-    ThreadMgr *This = impl_from_ITfKeystrokeMgrVtbl(iface);
+    ThreadMgr *This = impl_from_ITfKeystrokeMgr(iface);
     FIXME("STUB:(%p)\n",This);
     return E_NOTIMPL;
 }
@@ -812,7 +817,7 @@ static HRESULT WINAPI KeystrokeMgr_GetPreservedKey(ITfKeystrokeMgr *iface,
 static HRESULT WINAPI KeystrokeMgr_IsPreservedKey(ITfKeystrokeMgr *iface,
         REFGUID rguid, const TF_PRESERVEDKEY *pprekey, BOOL *pfRegistered)
 {
-    ThreadMgr *This = impl_from_ITfKeystrokeMgrVtbl(iface);
+    ThreadMgr *This = impl_from_ITfKeystrokeMgr(iface);
     struct list *cursor;
 
     TRACE("(%p) %s (%x %x) %p\n",This,debugstr_guid(rguid), (pprekey)?pprekey->uVKey:0, (pprekey)?pprekey->uModifiers:0, pfRegistered);
@@ -838,7 +843,7 @@ static HRESULT WINAPI KeystrokeMgr_PreserveKey(ITfKeystrokeMgr *iface,
         TfClientId tid, REFGUID rguid, const TF_PRESERVEDKEY *prekey,
         const WCHAR *pchDesc, ULONG cchDesc)
 {
-    ThreadMgr *This = impl_from_ITfKeystrokeMgrVtbl(iface);
+    ThreadMgr *This = impl_from_ITfKeystrokeMgr(iface);
     struct list *cursor;
     PreservedKey *newkey;
 
@@ -881,7 +886,7 @@ static HRESULT WINAPI KeystrokeMgr_PreserveKey(ITfKeystrokeMgr *iface,
 static HRESULT WINAPI KeystrokeMgr_UnpreserveKey(ITfKeystrokeMgr *iface,
         REFGUID rguid, const TF_PRESERVEDKEY *pprekey)
 {
-    ThreadMgr *This = impl_from_ITfKeystrokeMgrVtbl(iface);
+    ThreadMgr *This = impl_from_ITfKeystrokeMgr(iface);
     PreservedKey* key = NULL;
     struct list *cursor;
     TRACE("(%p) %s (%x %x)\n",This,debugstr_guid(rguid),(pprekey)?pprekey->uVKey:0, (pprekey)?pprekey->uModifiers:0);
@@ -910,7 +915,7 @@ static HRESULT WINAPI KeystrokeMgr_UnpreserveKey(ITfKeystrokeMgr *iface,
 static HRESULT WINAPI KeystrokeMgr_SetPreservedKeyDescription(ITfKeystrokeMgr *iface,
         REFGUID rguid, const WCHAR *pchDesc, ULONG cchDesc)
 {
-    ThreadMgr *This = impl_from_ITfKeystrokeMgrVtbl(iface);
+    ThreadMgr *This = impl_from_ITfKeystrokeMgr(iface);
     FIXME("STUB:(%p)\n",This);
     return E_NOTIMPL;
 }
@@ -918,7 +923,7 @@ static HRESULT WINAPI KeystrokeMgr_SetPreservedKeyDescription(ITfKeystrokeMgr *i
 static HRESULT WINAPI KeystrokeMgr_GetPreservedKeyDescription(ITfKeystrokeMgr *iface,
         REFGUID rguid, BSTR *pbstrDesc)
 {
-    ThreadMgr *This = impl_from_ITfKeystrokeMgrVtbl(iface);
+    ThreadMgr *This = impl_from_ITfKeystrokeMgr(iface);
     FIXME("STUB:(%p)\n",This);
     return E_NOTIMPL;
 }
@@ -926,17 +931,16 @@ static HRESULT WINAPI KeystrokeMgr_GetPreservedKeyDescription(ITfKeystrokeMgr *i
 static HRESULT WINAPI KeystrokeMgr_SimulatePreservedKey(ITfKeystrokeMgr *iface,
         ITfContext *pic, REFGUID rguid, BOOL *pfEaten)
 {
-    ThreadMgr *This = impl_from_ITfKeystrokeMgrVtbl(iface);
+    ThreadMgr *This = impl_from_ITfKeystrokeMgr(iface);
     FIXME("STUB:(%p)\n",This);
     return E_NOTIMPL;
 }
 
-static const ITfKeystrokeMgrVtbl ThreadMgr_KeystrokeMgrVtbl =
+static const ITfKeystrokeMgrVtbl KeystrokeMgrVtbl =
 {
     KeystrokeMgr_QueryInterface,
     KeystrokeMgr_AddRef,
     KeystrokeMgr_Release,
-
     KeystrokeMgr_AdviseKeyEventSink,
     KeystrokeMgr_UnadviseKeyEventSink,
     KeystrokeMgr_GetForeground,
@@ -959,20 +963,20 @@ static const ITfKeystrokeMgrVtbl ThreadMgr_KeystrokeMgrVtbl =
 
 static HRESULT WINAPI MessagePump_QueryInterface(ITfMessagePump *iface, REFIID iid, LPVOID *ppvOut)
 {
-    ThreadMgr *This = impl_from_ITfMessagePumpVtbl(iface);
-    return ThreadMgr_QueryInterface((ITfThreadMgr *)This, iid, *ppvOut);
+    ThreadMgr *This = impl_from_ITfMessagePump(iface);
+    return ITfThreadMgr_QueryInterface(&This->ITfThreadMgr_iface, iid, ppvOut);
 }
 
 static ULONG WINAPI MessagePump_AddRef(ITfMessagePump *iface)
 {
-    ThreadMgr *This = impl_from_ITfMessagePumpVtbl(iface);
-    return ThreadMgr_AddRef((ITfThreadMgr*)This);
+    ThreadMgr *This = impl_from_ITfMessagePump(iface);
+    return ITfThreadMgr_AddRef(&This->ITfThreadMgr_iface);
 }
 
 static ULONG WINAPI MessagePump_Release(ITfMessagePump *iface)
 {
-    ThreadMgr *This = impl_from_ITfMessagePumpVtbl(iface);
-    return ThreadMgr_Release((ITfThreadMgr *)This);
+    ThreadMgr *This = impl_from_ITfMessagePump(iface);
+    return ITfThreadMgr_Release(&This->ITfThreadMgr_iface);
 }
 
 static HRESULT WINAPI MessagePump_PeekMessageA(ITfMessagePump *iface,
@@ -1015,12 +1019,11 @@ static HRESULT WINAPI MessagePump_GetMessageW(ITfMessagePump *iface,
     return S_OK;
 }
 
-static const ITfMessagePumpVtbl ThreadMgr_MessagePumpVtbl =
+static const ITfMessagePumpVtbl MessagePumpVtbl =
 {
     MessagePump_QueryInterface,
     MessagePump_AddRef,
     MessagePump_Release,
-
     MessagePump_PeekMessageA,
     MessagePump_GetMessageA,
     MessagePump_PeekMessageW,
@@ -1033,29 +1036,29 @@ static const ITfMessagePumpVtbl ThreadMgr_MessagePumpVtbl =
 
 static HRESULT WINAPI ClientId_QueryInterface(ITfClientId *iface, REFIID iid, LPVOID *ppvOut)
 {
-    ThreadMgr *This = impl_from_ITfClientIdVtbl(iface);
-    return ThreadMgr_QueryInterface((ITfThreadMgr *)This, iid, *ppvOut);
+    ThreadMgr *This = impl_from_ITfClientId(iface);
+    return ITfThreadMgr_QueryInterface(&This->ITfThreadMgr_iface, iid, ppvOut);
 }
 
 static ULONG WINAPI ClientId_AddRef(ITfClientId *iface)
 {
-    ThreadMgr *This = impl_from_ITfClientIdVtbl(iface);
-    return ThreadMgr_AddRef((ITfThreadMgr*)This);
+    ThreadMgr *This = impl_from_ITfClientId(iface);
+    return ITfThreadMgr_AddRef(&This->ITfThreadMgr_iface);
 }
 
 static ULONG WINAPI ClientId_Release(ITfClientId *iface)
 {
-    ThreadMgr *This = impl_from_ITfClientIdVtbl(iface);
-    return ThreadMgr_Release((ITfThreadMgr *)This);
+    ThreadMgr *This = impl_from_ITfClientId(iface);
+    return ITfThreadMgr_Release(&This->ITfThreadMgr_iface);
 }
 
 static HRESULT WINAPI ClientId_GetClientId(ITfClientId *iface,
     REFCLSID rclsid, TfClientId *ptid)
 
 {
+    ThreadMgr *This = impl_from_ITfClientId(iface);
     HRESULT hr;
     ITfCategoryMgr *catmgr;
-    ThreadMgr *This = impl_from_ITfClientIdVtbl(iface);
 
     TRACE("(%p) %s\n",This,debugstr_guid(rclsid));
 
@@ -1066,12 +1069,11 @@ static HRESULT WINAPI ClientId_GetClientId(ITfClientId *iface,
     return hr;
 }
 
-static const ITfClientIdVtbl ThreadMgr_ClientIdVtbl =
+static const ITfClientIdVtbl ClientIdVtbl =
 {
     ClientId_QueryInterface,
     ClientId_AddRef,
     ClientId_Release,
-
     ClientId_GetClientId
 };
 
@@ -1081,19 +1083,19 @@ static const ITfClientIdVtbl ThreadMgr_ClientIdVtbl =
 static HRESULT WINAPI ThreadMgrEventSink_QueryInterface(ITfThreadMgrEventSink *iface, REFIID iid, LPVOID *ppvOut)
 {
     ThreadMgr *This = impl_from_ITfThreadMgrEventSink(iface);
-    return ThreadMgr_QueryInterface((ITfThreadMgr *)This, iid, *ppvOut);
+    return ITfThreadMgr_QueryInterface(&This->ITfThreadMgr_iface, iid, ppvOut);
 }
 
 static ULONG WINAPI ThreadMgrEventSink_AddRef(ITfThreadMgrEventSink *iface)
 {
     ThreadMgr *This = impl_from_ITfThreadMgrEventSink(iface);
-    return ThreadMgr_AddRef((ITfThreadMgr*)This);
+    return ITfThreadMgr_AddRef(&This->ITfThreadMgr_iface);
 }
 
 static ULONG WINAPI ThreadMgrEventSink_Release(ITfThreadMgrEventSink *iface)
 {
     ThreadMgr *This = impl_from_ITfThreadMgrEventSink(iface);
-    return ThreadMgr_Release((ITfThreadMgr *)This);
+    return ITfThreadMgr_Release(&This->ITfThreadMgr_iface);
 }
 
 
@@ -1183,12 +1185,11 @@ static HRESULT WINAPI ThreadMgrEventSink_OnPopContext(
     return S_OK;
 }
 
-static const ITfThreadMgrEventSinkVtbl ThreadMgr_ThreadMgrEventSinkVtbl =
+static const ITfThreadMgrEventSinkVtbl ThreadMgrEventSinkVtbl =
 {
     ThreadMgrEventSink_QueryInterface,
     ThreadMgrEventSink_AddRef,
     ThreadMgrEventSink_Release,
-
     ThreadMgrEventSink_OnInitDocumentMgr,
     ThreadMgrEventSink_OnUninitDocumentMgr,
     ThreadMgrEventSink_OnSetFocus,
@@ -1201,26 +1202,26 @@ static const ITfThreadMgrEventSinkVtbl ThreadMgr_ThreadMgrEventSinkVtbl =
  *****************************************************/
 static HRESULT WINAPI ThreadMgrSourceSingle_QueryInterface(ITfSourceSingle *iface, REFIID iid, LPVOID *ppvOut)
 {
-    ThreadMgr *This = impl_from_ITfSourceSingleVtbl(iface);
-    return ThreadMgr_QueryInterface((ITfThreadMgr *)This, iid, *ppvOut);
+    ThreadMgr *This = impl_from_ITfSourceSingle(iface);
+    return ITfThreadMgr_QueryInterface(&This->ITfThreadMgr_iface, iid, ppvOut);
 }
 
 static ULONG WINAPI ThreadMgrSourceSingle_AddRef(ITfSourceSingle *iface)
 {
-    ThreadMgr *This = impl_from_ITfSourceSingleVtbl(iface);
-    return ThreadMgr_AddRef((ITfThreadMgr *)This);
+    ThreadMgr *This = impl_from_ITfSourceSingle(iface);
+    return ITfThreadMgr_AddRef(&This->ITfThreadMgr_iface);
 }
 
 static ULONG WINAPI ThreadMgrSourceSingle_Release(ITfSourceSingle *iface)
 {
-    ThreadMgr *This = impl_from_ITfSourceSingleVtbl(iface);
-    return ThreadMgr_Release((ITfThreadMgr *)This);
+    ThreadMgr *This = impl_from_ITfSourceSingle(iface);
+    return ITfThreadMgr_Release(&This->ITfThreadMgr_iface);
 }
 
 static HRESULT WINAPI ThreadMgrSourceSingle_AdviseSingleSink( ITfSourceSingle *iface,
     TfClientId tid, REFIID riid, IUnknown *punk)
 {
-    ThreadMgr *This = impl_from_ITfSourceSingleVtbl(iface);
+    ThreadMgr *This = impl_from_ITfSourceSingle(iface);
     FIXME("STUB:(%p) %i %s %p\n",This, tid, debugstr_guid(riid),punk);
     return E_NOTIMPL;
 }
@@ -1228,19 +1229,18 @@ static HRESULT WINAPI ThreadMgrSourceSingle_AdviseSingleSink( ITfSourceSingle *i
 static HRESULT WINAPI ThreadMgrSourceSingle_UnadviseSingleSink( ITfSourceSingle *iface,
     TfClientId tid, REFIID riid)
 {
-    ThreadMgr *This = impl_from_ITfSourceSingleVtbl(iface);
+    ThreadMgr *This = impl_from_ITfSourceSingle(iface);
     FIXME("STUB:(%p) %i %s\n",This, tid, debugstr_guid(riid));
     return E_NOTIMPL;
 }
 
-static const ITfSourceSingleVtbl ThreadMgr_SourceSingleVtbl =
+static const ITfSourceSingleVtbl SourceSingleVtbl =
 {
     ThreadMgrSourceSingle_QueryInterface,
     ThreadMgrSourceSingle_AddRef,
     ThreadMgrSourceSingle_Release,
-
     ThreadMgrSourceSingle_AdviseSingleSink,
-    ThreadMgrSourceSingle_UnadviseSingleSink,
+    ThreadMgrSourceSingle_UnadviseSingleSink
 };
 
 HRESULT ThreadMgr_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut)
@@ -1253,8 +1253,8 @@ HRESULT ThreadMgr_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut)
     This = TlsGetValue(tlsIndex);
     if (This)
     {
-        ThreadMgr_AddRef((ITfThreadMgr*)This);
-        *ppOut = (IUnknown*)This;
+        ThreadMgr_AddRef(&This->ITfThreadMgr_iface);
+        *ppOut = (IUnknown*)&This->ITfThreadMgr_iface;
         return S_OK;
     }
 
@@ -1262,13 +1262,13 @@ HRESULT ThreadMgr_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut)
     if (This == NULL)
         return E_OUTOFMEMORY;
 
-    This->ThreadMgrVtbl= &ThreadMgr_ThreadMgrVtbl;
-    This->SourceVtbl = &ThreadMgr_SourceVtbl;
-    This->KeystrokeMgrVtbl= &ThreadMgr_KeystrokeMgrVtbl;
-    This->MessagePumpVtbl= &ThreadMgr_MessagePumpVtbl;
-    This->ClientIdVtbl = &ThreadMgr_ClientIdVtbl;
-    This->ThreadMgrEventSinkVtbl = &ThreadMgr_ThreadMgrEventSinkVtbl;
-    This->SourceSingleVtbl = &ThreadMgr_SourceSingleVtbl;
+    This->ITfThreadMgr_iface.lpVtbl= &ThreadMgrVtbl;
+    This->ITfSource_iface.lpVtbl = &ThreadMgrSourceVtbl;
+    This->ITfKeystrokeMgr_iface.lpVtbl= &KeystrokeMgrVtbl;
+    This->ITfMessagePump_iface.lpVtbl = &MessagePumpVtbl;
+    This->ITfClientId_iface.lpVtbl = &ClientIdVtbl;
+    This->ITfThreadMgrEventSink_iface.lpVtbl = &ThreadMgrEventSinkVtbl;
+    This->ITfSourceSingle_iface.lpVtbl = &SourceSingleVtbl;
     This->refCount = 1;
     TlsSetValue(tlsIndex,This);
 
@@ -1286,7 +1286,7 @@ HRESULT ThreadMgr_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut)
     list_init(&This->ThreadMgrEventSink);
 
     TRACE("returning %p\n", This);
-    *ppOut = (IUnknown *)This;
+    *ppOut = (IUnknown *)&This->ITfThreadMgr_iface;
     return S_OK;
 }
 
@@ -1301,12 +1301,12 @@ static void EnumTfDocumentMgr_Destructor(EnumTfDocumentMgr *This)
 
 static HRESULT WINAPI EnumTfDocumentMgr_QueryInterface(IEnumTfDocumentMgrs *iface, REFIID iid, LPVOID *ppvOut)
 {
-    EnumTfDocumentMgr *This = (EnumTfDocumentMgr *)iface;
+    EnumTfDocumentMgr *This = impl_from_IEnumTfDocumentMgrs(iface);
     *ppvOut = NULL;
 
     if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_IEnumTfDocumentMgrs))
     {
-        *ppvOut = This;
+        *ppvOut = &This->IEnumTfDocumentMgrs_iface;
     }
 
     if (*ppvOut)
@@ -1321,13 +1321,13 @@ static HRESULT WINAPI EnumTfDocumentMgr_QueryInterface(IEnumTfDocumentMgrs *ifac
 
 static ULONG WINAPI EnumTfDocumentMgr_AddRef(IEnumTfDocumentMgrs *iface)
 {
-    EnumTfDocumentMgr *This = (EnumTfDocumentMgr*)iface;
+    EnumTfDocumentMgr *This = impl_from_IEnumTfDocumentMgrs(iface);
     return InterlockedIncrement(&This->refCount);
 }
 
 static ULONG WINAPI EnumTfDocumentMgr_Release(IEnumTfDocumentMgrs *iface)
 {
-    EnumTfDocumentMgr *This = (EnumTfDocumentMgr *)iface;
+    EnumTfDocumentMgr *This = impl_from_IEnumTfDocumentMgrs(iface);
     ULONG ret;
 
     ret = InterlockedDecrement(&This->refCount);
@@ -1339,7 +1339,7 @@ static ULONG WINAPI EnumTfDocumentMgr_Release(IEnumTfDocumentMgrs *iface)
 static HRESULT WINAPI EnumTfDocumentMgr_Next(IEnumTfDocumentMgrs *iface,
     ULONG ulCount, ITfDocumentMgr **rgDocumentMgr, ULONG *pcFetched)
 {
-    EnumTfDocumentMgr *This = (EnumTfDocumentMgr *)iface;
+    EnumTfDocumentMgr *This = impl_from_IEnumTfDocumentMgrs(iface);
     ULONG fetched = 0;
 
     TRACE("(%p)\n",This);
@@ -1370,8 +1370,9 @@ static HRESULT WINAPI EnumTfDocumentMgr_Next(IEnumTfDocumentMgrs *iface,
 
 static HRESULT WINAPI EnumTfDocumentMgr_Skip( IEnumTfDocumentMgrs* iface, ULONG celt)
 {
+    EnumTfDocumentMgr *This = impl_from_IEnumTfDocumentMgrs(iface);
     ULONG i;
-    EnumTfDocumentMgr *This = (EnumTfDocumentMgr *)iface;
+
     TRACE("(%p)\n",This);
     for(i = 0; i < celt && This->index != NULL; i++)
         This->index = list_next(This->head, This->index);
@@ -1380,7 +1381,7 @@ static HRESULT WINAPI EnumTfDocumentMgr_Skip( IEnumTfDocumentMgrs* iface, ULONG
 
 static HRESULT WINAPI EnumTfDocumentMgr_Reset( IEnumTfDocumentMgrs* iface)
 {
-    EnumTfDocumentMgr *This = (EnumTfDocumentMgr *)iface;
+    EnumTfDocumentMgr *This = impl_from_IEnumTfDocumentMgrs(iface);
     TRACE("(%p)\n",This);
     This->index = list_head(This->head);
     return S_OK;
@@ -1389,7 +1390,7 @@ static HRESULT WINAPI EnumTfDocumentMgr_Reset( IEnumTfDocumentMgrs* iface)
 static HRESULT WINAPI EnumTfDocumentMgr_Clone( IEnumTfDocumentMgrs *iface,
     IEnumTfDocumentMgrs **ppenum)
 {
-    EnumTfDocumentMgr *This = (EnumTfDocumentMgr *)iface;
+    EnumTfDocumentMgr *This = impl_from_IEnumTfDocumentMgrs(iface);
     HRESULT res;
 
     TRACE("(%p)\n",This);
@@ -1399,17 +1400,17 @@ static HRESULT WINAPI EnumTfDocumentMgr_Clone( IEnumTfDocumentMgrs *iface,
     res = EnumTfDocumentMgr_Constructor(This->head, ppenum);
     if (SUCCEEDED(res))
     {
-        EnumTfDocumentMgr *new_This = (EnumTfDocumentMgr *)*ppenum;
+        EnumTfDocumentMgr *new_This = impl_from_IEnumTfDocumentMgrs(*ppenum);
         new_This->index = This->index;
     }
     return res;
 }
 
-static const IEnumTfDocumentMgrsVtbl IEnumTfDocumentMgrs_Vtbl ={
+static const IEnumTfDocumentMgrsVtbl EnumTfDocumentMgrsVtbl =
+{
     EnumTfDocumentMgr_QueryInterface,
     EnumTfDocumentMgr_AddRef,
     EnumTfDocumentMgr_Release,
-
     EnumTfDocumentMgr_Clone,
     EnumTfDocumentMgr_Next,
     EnumTfDocumentMgr_Reset,
@@ -1424,7 +1425,7 @@ static HRESULT EnumTfDocumentMgr_Constructor(struct list* head, IEnumTfDocumentM
     if (This == NULL)
         return E_OUTOFMEMORY;
 
-    This->Vtbl= &IEnumTfDocumentMgrs_Vtbl;
+    This->IEnumTfDocumentMgrs_iface.lpVtbl= &EnumTfDocumentMgrsVtbl;
     This->refCount = 1;
     This->head = head;
     This->index = list_head(This->head);
@@ -1434,9 +1435,9 @@ static HRESULT EnumTfDocumentMgr_Constructor(struct list* head, IEnumTfDocumentM
     return S_OK;
 }
 
-void ThreadMgr_OnDocumentMgrDestruction(ITfThreadMgr *tm, ITfDocumentMgr *mgr)
+void ThreadMgr_OnDocumentMgrDestruction(ITfThreadMgr *iface, ITfDocumentMgr *mgr)
 {
-    ThreadMgr *This = (ThreadMgr *)tm;
+    ThreadMgr *This = impl_from_ITfThreadMgr(iface);
     struct list *cursor;
     LIST_FOR_EACH(cursor, &This->CreatedDocumentMgrs)
     {