[MSCTF] Sync with Wine Staging 3.3. CORE-14434
[reactos.git] / dll / win32 / msctf / compartmentmgr.c
index 76a9a94..4fe7b82 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
-#define WIN32_NO_STATUS
-#define _INC_WINDOWS
-#define COM_NO_WINDOWS_H
+#include "config.h"
 
-#include <config.h>
-
-//#include <stdarg.h>
+#include <stdarg.h>
 
 #define COBJMACROS
 
-#include <wine/debug.h>
-//#include "windef.h"
-#include <winbase.h>
-//#include "winreg.h"
-//#include "winuser.h"
-//#include "shlwapi.h"
-//#include "winerror.h"
-#include <objbase.h>
-#include <oleauto.h>
-#include <olectl.h>
-
-//#include "wine/unicode.h"
-#include <wine/list.h>
-
-#include <msctf.h>
+#include "wine/debug.h"
+#include "windef.h"
+#include "winbase.h"
+#include "winreg.h"
+#include "winuser.h"
+#include "shlwapi.h"
+#include "winerror.h"
+#include "objbase.h"
+#include "oleauto.h"
+#include "olectl.h"
+
+#include "wine/unicode.h"
+
+#include "msctf.h"
 #include "msctf_internal.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(msctf);
@@ -55,7 +50,7 @@ typedef struct tagCompartmentValue {
 } CompartmentValue;
 
 typedef struct tagCompartmentMgr {
-    const ITfCompartmentMgrVtbl *CompartmentMgrVtbl;
+    ITfCompartmentMgr ITfCompartmentMgr_iface;
     LONG refCount;
 
     IUnknown *pUnkOuter;
@@ -64,25 +59,16 @@ typedef struct tagCompartmentMgr {
 } CompartmentMgr;
 
 typedef struct tagCompartmentEnumGuid {
-    const IEnumGUIDVtbl *Vtbl;
+    IEnumGUID IEnumGUID_iface;
     LONG refCount;
 
     struct list *values;
     struct list *cursor;
 } CompartmentEnumGuid;
 
-
-typedef struct tagCompartmentSink {
-    struct list         entry;
-    union {
-        IUnknown            *pIUnknown;
-        ITfCompartmentEventSink *pITfCompartmentEventSink;
-    } interfaces;
-} CompartmentSink;
-
 typedef struct tagCompartment {
-    const ITfCompartmentVtbl *Vtbl;
-    const ITfSourceVtbl *SourceVtbl;
+    ITfCompartment ITfCompartment_iface;
+    ITfSource ITfSource_iface;
     LONG refCount;
 
     /* Only VT_I4, VT_UNKNOWN and VT_BSTR data types are allowed */
@@ -94,14 +80,29 @@ typedef struct tagCompartment {
 static HRESULT CompartmentEnumGuid_Constructor(struct list* values, IEnumGUID **ppOut);
 static HRESULT Compartment_Constructor(CompartmentValue *value, ITfCompartment **ppOut);
 
-static inline Compartment *impl_from_ITfSourceVtbl(ITfSource *iface)
+static inline CompartmentMgr *impl_from_ITfCompartmentMgr(ITfCompartmentMgr *iface)
+{
+    return CONTAINING_RECORD(iface, CompartmentMgr, ITfCompartmentMgr_iface);
+}
+
+static inline Compartment *impl_from_ITfCompartment(ITfCompartment *iface)
+{
+    return CONTAINING_RECORD(iface, Compartment, ITfCompartment_iface);
+}
+
+static inline Compartment *impl_from_ITfSource(ITfSource *iface)
 {
-    return (Compartment *)((char *)iface - FIELD_OFFSET(Compartment,SourceVtbl));
+    return CONTAINING_RECORD(iface, Compartment, ITfSource_iface);
+}
+
+static inline CompartmentEnumGuid *impl_from_IEnumGUID(IEnumGUID *iface)
+{
+    return CONTAINING_RECORD(iface, CompartmentEnumGuid, IEnumGUID_iface);
 }
 
 HRESULT CompartmentMgr_Destructor(ITfCompartmentMgr *iface)
 {
-    CompartmentMgr *This = (CompartmentMgr *)iface;
+    CompartmentMgr *This = impl_from_ITfCompartmentMgr(iface);
     struct list *cursor, *cursor2;
 
     LIST_FOR_EACH_SAFE(cursor, cursor2, &This->values)
@@ -121,21 +122,21 @@ HRESULT CompartmentMgr_Destructor(ITfCompartmentMgr *iface)
  *****************************************************/
 static HRESULT WINAPI CompartmentMgr_QueryInterface(ITfCompartmentMgr *iface, REFIID iid, LPVOID *ppvOut)
 {
-    CompartmentMgr *This = (CompartmentMgr *)iface;
+    CompartmentMgr *This = impl_from_ITfCompartmentMgr(iface);
     if (This->pUnkOuter)
-        return IUnknown_QueryInterface(This->pUnkOuter, iid, *ppvOut);
+        return IUnknown_QueryInterface(This->pUnkOuter, iid, ppvOut);
     else
     {
         *ppvOut = NULL;
 
         if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfCompartmentMgr))
         {
-            *ppvOut = This;
+            *ppvOut = &This->ITfCompartmentMgr_iface;
         }
 
         if (*ppvOut)
         {
-            IUnknown_AddRef(iface);
+            ITfCompartmentMgr_AddRef(iface);
             return S_OK;
         }
 
@@ -146,7 +147,7 @@ static HRESULT WINAPI CompartmentMgr_QueryInterface(ITfCompartmentMgr *iface, RE
 
 static ULONG WINAPI CompartmentMgr_AddRef(ITfCompartmentMgr *iface)
 {
-    CompartmentMgr *This = (CompartmentMgr *)iface;
+    CompartmentMgr *This = impl_from_ITfCompartmentMgr(iface);
     if (This->pUnkOuter)
         return IUnknown_AddRef(This->pUnkOuter);
     else
@@ -155,7 +156,7 @@ static ULONG WINAPI CompartmentMgr_AddRef(ITfCompartmentMgr *iface)
 
 static ULONG WINAPI CompartmentMgr_Release(ITfCompartmentMgr *iface)
 {
-    CompartmentMgr *This = (CompartmentMgr *)iface;
+    CompartmentMgr *This = impl_from_ITfCompartmentMgr(iface);
     if (This->pUnkOuter)
         return IUnknown_Release(This->pUnkOuter);
     else
@@ -172,7 +173,7 @@ static ULONG WINAPI CompartmentMgr_Release(ITfCompartmentMgr *iface)
 static HRESULT WINAPI CompartmentMgr_GetCompartment(ITfCompartmentMgr *iface,
         REFGUID rguid, ITfCompartment **ppcomp)
 {
-    CompartmentMgr *This = (CompartmentMgr *)iface;
+    CompartmentMgr *This = impl_from_ITfCompartmentMgr(iface);
     CompartmentValue* value;
     struct list *cursor;
     HRESULT hr;
@@ -211,8 +212,9 @@ static HRESULT WINAPI CompartmentMgr_GetCompartment(ITfCompartmentMgr *iface,
 static HRESULT WINAPI CompartmentMgr_ClearCompartment(ITfCompartmentMgr *iface,
     TfClientId tid, REFGUID rguid)
 {
+    CompartmentMgr *This = impl_from_ITfCompartmentMgr(iface);
     struct list *cursor;
-    CompartmentMgr *This = (CompartmentMgr *)iface;
+
     TRACE("(%p) %i %s\n",This,tid,debugstr_guid(rguid));
 
     LIST_FOR_EACH(cursor, &This->values)
@@ -235,19 +237,19 @@ static HRESULT WINAPI CompartmentMgr_ClearCompartment(ITfCompartmentMgr *iface,
 static HRESULT WINAPI CompartmentMgr_EnumCompartments(ITfCompartmentMgr *iface,
  IEnumGUID **ppEnum)
 {
-    CompartmentMgr *This = (CompartmentMgr *)iface;
+    CompartmentMgr *This = impl_from_ITfCompartmentMgr(iface);
+
     TRACE("(%p) %p\n",This,ppEnum);
     if (!ppEnum)
         return E_INVALIDARG;
     return CompartmentEnumGuid_Constructor(&This->values, ppEnum);
 }
 
-static const ITfCompartmentMgrVtbl CompartmentMgr_CompartmentMgrVtbl =
+static const ITfCompartmentMgrVtbl CompartmentMgrVtbl =
 {
     CompartmentMgr_QueryInterface,
     CompartmentMgr_AddRef,
     CompartmentMgr_Release,
-
     CompartmentMgr_GetCompartment,
     CompartmentMgr_ClearCompartment,
     CompartmentMgr_EnumCompartments
@@ -267,20 +269,20 @@ HRESULT CompartmentMgr_Constructor(IUnknown *pUnkOuter, REFIID riid, IUnknown **
     if (This == NULL)
         return E_OUTOFMEMORY;
 
-    This->CompartmentMgrVtbl = &CompartmentMgr_CompartmentMgrVtbl;
+    This->ITfCompartmentMgr_iface.lpVtbl = &CompartmentMgrVtbl;
     This->pUnkOuter = pUnkOuter;
     list_init(&This->values);
 
     if (pUnkOuter)
     {
-        TRACE("returning %p\n", This);
-        *ppOut = (IUnknown*)This;
+        *ppOut = (IUnknown*)&This->ITfCompartmentMgr_iface;
+        TRACE("returning %p\n", *ppOut);
         return S_OK;
     }
     else
     {
         HRESULT hr;
-        hr = IUnknown_QueryInterface((IUnknown*)This, riid, (LPVOID*)ppOut);
+        hr = ITfCompartmentMgr_QueryInterface(&This->ITfCompartmentMgr_iface, riid, (void**)ppOut);
         if (FAILED(hr))
             HeapFree(GetProcessHeap(),0,This);
         return hr;
@@ -298,17 +300,17 @@ static void CompartmentEnumGuid_Destructor(CompartmentEnumGuid *This)
 
 static HRESULT WINAPI CompartmentEnumGuid_QueryInterface(IEnumGUID *iface, REFIID iid, LPVOID *ppvOut)
 {
-    CompartmentEnumGuid *This = (CompartmentEnumGuid *)iface;
+    CompartmentEnumGuid *This = impl_from_IEnumGUID(iface);
     *ppvOut = NULL;
 
     if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_IEnumGUID))
     {
-        *ppvOut = This;
+        *ppvOut = &This->IEnumGUID_iface;
     }
 
     if (*ppvOut)
     {
-        IUnknown_AddRef(iface);
+        IEnumGUID_AddRef(iface);
         return S_OK;
     }
 
@@ -318,13 +320,13 @@ static HRESULT WINAPI CompartmentEnumGuid_QueryInterface(IEnumGUID *iface, REFII
 
 static ULONG WINAPI CompartmentEnumGuid_AddRef(IEnumGUID *iface)
 {
-    CompartmentEnumGuid *This = (CompartmentEnumGuid*)iface;
+    CompartmentEnumGuid *This = impl_from_IEnumGUID(iface);
     return InterlockedIncrement(&This->refCount);
 }
 
 static ULONG WINAPI CompartmentEnumGuid_Release(IEnumGUID *iface)
 {
-    CompartmentEnumGuid *This = (CompartmentEnumGuid *)iface;
+    CompartmentEnumGuid *This = impl_from_IEnumGUID(iface);
     ULONG ret;
 
     ret = InterlockedDecrement(&This->refCount);
@@ -336,10 +338,10 @@ static ULONG WINAPI CompartmentEnumGuid_Release(IEnumGUID *iface)
 /*****************************************************
  * IEnumGuid functions
  *****************************************************/
-static HRESULT WINAPI CompartmentEnumGuid_Next( LPENUMGUID iface,
+static HRESULT WINAPI CompartmentEnumGuid_Next(IEnumGUID *iface,
     ULONG celt, GUID *rgelt, ULONG *pceltFetched)
 {
-    CompartmentEnumGuid *This = (CompartmentEnumGuid *)iface;
+    CompartmentEnumGuid *This = impl_from_IEnumGUID(iface);
     ULONG fetched = 0;
 
     TRACE("(%p)\n",This);
@@ -363,27 +365,27 @@ static HRESULT WINAPI CompartmentEnumGuid_Next( LPENUMGUID iface,
     return fetched == celt ? S_OK : S_FALSE;
 }
 
-static HRESULT WINAPI CompartmentEnumGuid_Skip( LPENUMGUID iface, ULONG celt)
+static HRESULT WINAPI CompartmentEnumGuid_Skip(IEnumGUID *iface, ULONG celt)
 {
-    CompartmentEnumGuid *This = (CompartmentEnumGuid *)iface;
+    CompartmentEnumGuid *This = impl_from_IEnumGUID(iface);
     TRACE("(%p)\n",This);
 
     This->cursor = list_next(This->values,This->cursor);
     return S_OK;
 }
 
-static HRESULT WINAPI CompartmentEnumGuid_Reset( LPENUMGUID iface)
+static HRESULT WINAPI CompartmentEnumGuid_Reset(IEnumGUID *iface)
 {
-    CompartmentEnumGuid *This = (CompartmentEnumGuid *)iface;
+    CompartmentEnumGuid *This = impl_from_IEnumGUID(iface);
     TRACE("(%p)\n",This);
     This->cursor = list_head(This->values);
     return S_OK;
 }
 
-static HRESULT WINAPI CompartmentEnumGuid_Clone( LPENUMGUID iface,
+static HRESULT WINAPI CompartmentEnumGuid_Clone(IEnumGUID *iface,
     IEnumGUID **ppenum)
 {
-    CompartmentEnumGuid *This = (CompartmentEnumGuid *)iface;
+    CompartmentEnumGuid *This = impl_from_IEnumGUID(iface);
     HRESULT res;
 
     TRACE("(%p)\n",This);
@@ -393,17 +395,17 @@ static HRESULT WINAPI CompartmentEnumGuid_Clone( LPENUMGUID iface,
     res = CompartmentEnumGuid_Constructor(This->values, ppenum);
     if (SUCCEEDED(res))
     {
-        CompartmentEnumGuid *new_This = (CompartmentEnumGuid *)*ppenum;
+        CompartmentEnumGuid *new_This = impl_from_IEnumGUID(*ppenum);
         new_This->cursor = This->cursor;
     }
     return res;
 }
 
-static const IEnumGUIDVtbl IEnumGUID_Vtbl ={
+static const IEnumGUIDVtbl EnumGUIDVtbl =
+{
     CompartmentEnumGuid_QueryInterface,
     CompartmentEnumGuid_AddRef,
     CompartmentEnumGuid_Release,
-
     CompartmentEnumGuid_Next,
     CompartmentEnumGuid_Skip,
     CompartmentEnumGuid_Reset,
@@ -418,57 +420,46 @@ static HRESULT CompartmentEnumGuid_Constructor(struct list *values, IEnumGUID **
     if (This == NULL)
         return E_OUTOFMEMORY;
 
-    This->Vtbl= &IEnumGUID_Vtbl;
+    This->IEnumGUID_iface.lpVtbl= &EnumGUIDVtbl;
     This->refCount = 1;
 
     This->values = values;
     This->cursor = list_head(values);
 
-    TRACE("returning %p\n", This);
-    *ppOut = (IEnumGUID*)This;
+    *ppOut = &This->IEnumGUID_iface;
+    TRACE("returning %p\n", *ppOut);
     return S_OK;
 }
 
 /**************************************************
  * ITfCompartment
  **************************************************/
-static void free_sink(CompartmentSink *sink)
-{
-        IUnknown_Release(sink->interfaces.pIUnknown);
-        HeapFree(GetProcessHeap(),0,sink);
-}
-
 static void Compartment_Destructor(Compartment *This)
 {
-    struct list *cursor, *cursor2;
     TRACE("destroying %p\n", This);
     VariantClear(&This->variant);
-    LIST_FOR_EACH_SAFE(cursor, cursor2, &This->CompartmentEventSink)
-    {
-        CompartmentSink* sink = LIST_ENTRY(cursor,CompartmentSink,entry);
-        list_remove(cursor);
-        free_sink(sink);
-    }
+    free_sinks(&This->CompartmentEventSink);
     HeapFree(GetProcessHeap(),0,This);
 }
 
 static HRESULT WINAPI Compartment_QueryInterface(ITfCompartment *iface, REFIID iid, LPVOID *ppvOut)
 {
-    Compartment *This = (Compartment *)iface;
+    Compartment *This = impl_from_ITfCompartment(iface);
+
     *ppvOut = NULL;
 
     if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfCompartment))
     {
-        *ppvOut = This;
+        *ppvOut = &This->ITfCompartment_iface;
     }
     else if (IsEqualIID(iid, &IID_ITfSource))
     {
-        *ppvOut = &This->SourceVtbl;
+        *ppvOut = &This->ITfSource_iface;
     }
 
     if (*ppvOut)
     {
-        IUnknown_AddRef(iface);
+        ITfCompartment_AddRef(iface);
         return S_OK;
     }
 
@@ -478,13 +469,13 @@ static HRESULT WINAPI Compartment_QueryInterface(ITfCompartment *iface, REFIID i
 
 static ULONG WINAPI Compartment_AddRef(ITfCompartment *iface)
 {
-    Compartment *This = (Compartment*)iface;
+    Compartment *This = impl_from_ITfCompartment(iface);
     return InterlockedIncrement(&This->refCount);
 }
 
 static ULONG WINAPI Compartment_Release(ITfCompartment *iface)
 {
-    Compartment *This = (Compartment *)iface;
+    Compartment *This = impl_from_ITfCompartment(iface);
     ULONG ret;
 
     ret = InterlockedDecrement(&This->refCount);
@@ -496,7 +487,8 @@ static ULONG WINAPI Compartment_Release(ITfCompartment *iface)
 static HRESULT WINAPI Compartment_SetValue(ITfCompartment *iface,
     TfClientId tid, const VARIANT *pvarValue)
 {
-    Compartment *This = (Compartment *)iface;
+    Compartment *This = impl_from_ITfCompartment(iface);
+    ITfCompartmentEventSink *sink;
     struct list *cursor;
 
     TRACE("(%p) %i %p\n",This,tid,pvarValue);
@@ -522,10 +514,9 @@ static HRESULT WINAPI Compartment_SetValue(ITfCompartment *iface,
     else if (V_VT(pvarValue) == VT_UNKNOWN)
         IUnknown_AddRef(V_UNKNOWN(&This->variant));
 
-    LIST_FOR_EACH(cursor, &This->CompartmentEventSink)
+    SINK_FOR_EACH(cursor, &This->CompartmentEventSink, ITfCompartmentEventSink, sink)
     {
-        CompartmentSink* sink = LIST_ENTRY(cursor,CompartmentSink,entry);
-        ITfCompartmentEventSink_OnChange(sink->interfaces.pITfCompartmentEventSink,&This->valueData->guid);
+        ITfCompartmentEventSink_OnChange(sink, &This->valueData->guid);
     }
 
     return S_OK;
@@ -534,7 +525,7 @@ static HRESULT WINAPI Compartment_SetValue(ITfCompartment *iface,
 static HRESULT WINAPI Compartment_GetValue(ITfCompartment *iface,
     VARIANT *pvarValue)
 {
-    Compartment *This = (Compartment *)iface;
+    Compartment *This = impl_from_ITfCompartment(iface);
     TRACE("(%p) %p\n",This, pvarValue);
 
     if (!pvarValue)
@@ -545,11 +536,11 @@ static HRESULT WINAPI Compartment_GetValue(ITfCompartment *iface,
     return VariantCopy(pvarValue,&This->variant);
 }
 
-static const ITfCompartmentVtbl ITfCompartment_Vtbl ={
+static const ITfCompartmentVtbl CompartmentVtbl =
+{
     Compartment_QueryInterface,
     Compartment_AddRef,
     Compartment_Release,
-
     Compartment_SetValue,
     Compartment_GetValue
 };
@@ -558,29 +549,28 @@ static const ITfCompartmentVtbl ITfCompartment_Vtbl ={
  * ITfSource functions
  *****************************************************/
 
-static HRESULT WINAPI Source_QueryInterface(ITfSource *iface, REFIID iid, LPVOID *ppvOut)
+static HRESULT WINAPI CompartmentSource_QueryInterface(ITfSource *iface, REFIID iid, LPVOID *ppvOut)
 {
-    Compartment *This = impl_from_ITfSourceVtbl(iface);
-    return Compartment_QueryInterface((ITfCompartment *)This, iid, *ppvOut);
+    Compartment *This = impl_from_ITfSource(iface);
+    return ITfCompartment_QueryInterface(&This->ITfCompartment_iface, iid, ppvOut);
 }
 
-static ULONG WINAPI Source_AddRef(ITfSource *iface)
+static ULONG WINAPI CompartmentSource_AddRef(ITfSource *iface)
 {
-    Compartment *This = impl_from_ITfSourceVtbl(iface);
-    return Compartment_AddRef((ITfCompartment*)This);
+    Compartment *This = impl_from_ITfSource(iface);
+    return ITfCompartment_AddRef(&This->ITfCompartment_iface);
 }
 
-static ULONG WINAPI Source_Release(ITfSource *iface)
+static ULONG WINAPI CompartmentSource_Release(ITfSource *iface)
 {
-    Compartment *This = impl_from_ITfSourceVtbl(iface);
-    return Compartment_Release((ITfCompartment *)This);
+    Compartment *This = impl_from_ITfSource(iface);
+    return ITfCompartment_Release(&This->ITfCompartment_iface);
 }
 
 static HRESULT WINAPI CompartmentSource_AdviseSink(ITfSource *iface,
         REFIID riid, IUnknown *punk, DWORD *pdwCookie)
 {
-    CompartmentSink *cs;
-    Compartment *This = impl_from_ITfSourceVtbl(iface);
+    Compartment *This = impl_from_ITfSource(iface);
 
     TRACE("(%p) %s %p %p\n",This,debugstr_guid(riid),punk,pdwCookie);
 
@@ -588,55 +578,30 @@ static HRESULT WINAPI CompartmentSource_AdviseSink(ITfSource *iface,
         return E_INVALIDARG;
 
     if (IsEqualIID(riid, &IID_ITfCompartmentEventSink))
-    {
-        cs = HeapAlloc(GetProcessHeap(),0,sizeof(CompartmentSink));
-        if (!cs)
-            return E_OUTOFMEMORY;
-        if (FAILED(IUnknown_QueryInterface(punk, riid, (LPVOID *)&cs->interfaces.pITfCompartmentEventSink)))
-        {
-            HeapFree(GetProcessHeap(),0,cs);
-            return CONNECT_E_CANNOTCONNECT;
-        }
-        list_add_head(&This->CompartmentEventSink,&cs->entry);
-        *pdwCookie = generate_Cookie(COOKIE_MAGIC_COMPARTMENTSINK , cs);
-    }
-    else
-    {
-        FIXME("(%p) Unhandled Sink: %s\n",This,debugstr_guid(riid));
-        return E_NOTIMPL;
-    }
-
-    TRACE("cookie %x\n",*pdwCookie);
+        return advise_sink(&This->CompartmentEventSink, &IID_ITfCompartmentEventSink,
+                           COOKIE_MAGIC_COMPARTMENTSINK, punk, pdwCookie);
 
-    return S_OK;
+    FIXME("(%p) Unhandled Sink: %s\n",This,debugstr_guid(riid));
+    return E_NOTIMPL;
 }
 
 static HRESULT WINAPI CompartmentSource_UnadviseSink(ITfSource *iface, DWORD pdwCookie)
 {
-    CompartmentSink *sink;
-    Compartment *This = impl_from_ITfSourceVtbl(iface);
+    Compartment *This = impl_from_ITfSource(iface);
 
     TRACE("(%p) %x\n",This,pdwCookie);
 
     if (get_Cookie_magic(pdwCookie)!=COOKIE_MAGIC_COMPARTMENTSINK)
         return E_INVALIDARG;
 
-    sink = (CompartmentSink*)remove_Cookie(pdwCookie);
-    if (!sink)
-        return CONNECT_E_NOCONNECTION;
-
-    list_remove(&sink->entry);
-    free_sink(sink);
-
-    return S_OK;
+    return unadvise_sink(pdwCookie);
 }
 
-static const ITfSourceVtbl Compartment_SourceVtbl =
+static const ITfSourceVtbl CompartmentSourceVtbl =
 {
-    Source_QueryInterface,
-    Source_AddRef,
-    Source_Release,
-
+    CompartmentSource_QueryInterface,
+    CompartmentSource_AddRef,
+    CompartmentSource_Release,
     CompartmentSource_AdviseSink,
     CompartmentSource_UnadviseSink,
 };
@@ -649,8 +614,8 @@ static HRESULT Compartment_Constructor(CompartmentValue *valueData, ITfCompartme
     if (This == NULL)
         return E_OUTOFMEMORY;
 
-    This->Vtbl= &ITfCompartment_Vtbl;
-    This->SourceVtbl = &Compartment_SourceVtbl;
+    This->ITfCompartment_iface.lpVtbl= &CompartmentVtbl;
+    This->ITfSource_iface.lpVtbl = &CompartmentSourceVtbl;
     This->refCount = 1;
 
     This->valueData = valueData;
@@ -658,7 +623,7 @@ static HRESULT Compartment_Constructor(CompartmentValue *valueData, ITfCompartme
 
     list_init(&This->CompartmentEventSink);
 
-    TRACE("returning %p\n", This);
-    *ppOut = (ITfCompartment*)This;
+    *ppOut = &This->ITfCompartment_iface;
+    TRACE("returning %p\n", *ppOut);
     return S_OK;
 }