[MSCTF] Sync with Wine Staging 3.3. CORE-14434
[reactos.git] / dll / win32 / msctf / inputprocessor.c
index 849a4e9..fdeba38 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 <olectl.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 "olectl.h"
 
-#include <wine/unicode.h>
-#include <wine/list.h>
+#include "wine/unicode.h"
 
-#include <msctf.h>
+#include "msctf.h"
 #include "msctf_internal.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(msctf);
@@ -56,19 +51,10 @@ static const WCHAR szwDefault[] = {'D','e','f','a','u','l','t',0};
 static const WCHAR szwProfile[] = {'P','r','o','f','i','l','e',0};
 static const WCHAR szwDefaultFmt[] = {'%','s','\\','%','s','\\','0','x','%','0','8','x','\\','%','s',0};
 
-typedef struct tagInputProcessorProfilesSink {
-    struct list         entry;
-    union {
-        /* InputProcessorProfile Sinks */
-        IUnknown            *pIUnknown;
-        ITfLanguageProfileNotifySink *pITfLanguageProfileNotifySink;
-    } interfaces;
-} InputProcessorProfilesSink;
-
 typedef struct tagInputProcessorProfiles {
-    const ITfInputProcessorProfilesVtbl *InputProcessorProfilesVtbl;
-    const ITfSourceVtbl *SourceVtbl;
-    /* const ITfInputProcessorProfileMgrVtbl *InputProcessorProfileMgrVtbl; */
+    ITfInputProcessorProfiles ITfInputProcessorProfiles_iface;
+    ITfSource ITfSource_iface;
+    ITfInputProcessorProfileMgr ITfInputProcessorProfileMgr_iface;
     /* const ITfInputProcessorProfilesExVtbl *InputProcessorProfilesExVtbl; */
     /* const ITfInputProcessorProfileSubstituteLayoutVtbl *InputProcessorProfileSubstituteLayoutVtbl; */
     LONG refCount;
@@ -79,7 +65,7 @@ typedef struct tagInputProcessorProfiles {
 } InputProcessorProfiles;
 
 typedef struct tagProfilesEnumGuid {
-    const IEnumGUIDVtbl *Vtbl;
+    IEnumGUID IEnumGUID_iface;
     LONG refCount;
 
     HKEY key;
@@ -87,7 +73,7 @@ typedef struct tagProfilesEnumGuid {
 } ProfilesEnumGuid;
 
 typedef struct tagEnumTfLanguageProfiles {
-    const IEnumTfLanguageProfilesVtbl *Vtbl;
+    IEnumTfLanguageProfiles IEnumTfLanguageProfiles_iface;
     LONG refCount;
 
     HKEY    tipkey;
@@ -101,33 +87,132 @@ typedef struct tagEnumTfLanguageProfiles {
     ITfCategoryMgr *catmgr;
 } EnumTfLanguageProfiles;
 
+typedef struct {
+    IEnumTfInputProcessorProfiles IEnumTfInputProcessorProfiles_iface;
+    LONG ref;
+} EnumTfInputProcessorProfiles;
+
 static HRESULT ProfilesEnumGuid_Constructor(IEnumGUID **ppOut);
-static HRESULT EnumTfLanguageProfiles_Constructor(LANGID langid, IEnumTfLanguageProfiles **ppOut);
+static HRESULT EnumTfLanguageProfiles_Constructor(LANGID langid, EnumTfLanguageProfiles **out);
+
+static inline EnumTfInputProcessorProfiles *impl_from_IEnumTfInputProcessorProfiles(IEnumTfInputProcessorProfiles *iface)
+{
+    return CONTAINING_RECORD(iface, EnumTfInputProcessorProfiles, IEnumTfInputProcessorProfiles_iface);
+}
+
+static HRESULT WINAPI EnumTfInputProcessorProfiles_QueryInterface(IEnumTfInputProcessorProfiles *iface,
+        REFIID riid, void **ppv)
+{
+    EnumTfInputProcessorProfiles *This = impl_from_IEnumTfInputProcessorProfiles(iface);
+
+    if(IsEqualGUID(riid, &IID_IUnknown)) {
+        TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
+        *ppv = &This->IEnumTfInputProcessorProfiles_iface;
+    }else if(IsEqualGUID(riid, &IID_IEnumTfInputProcessorProfiles)) {
+        TRACE("(%p)->(IID_IEnumTfInputProcessorProfiles %p)\n", This, ppv);
+        *ppv = &This->IEnumTfInputProcessorProfiles_iface;
+    }else {
+        *ppv = NULL;
+        WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
+        return E_NOINTERFACE;
+    }
+
+    IUnknown_AddRef((IUnknown*)*ppv);
+    return S_OK;
+}
+
+static ULONG WINAPI EnumTfInputProcessorProfiles_AddRef(IEnumTfInputProcessorProfiles *iface)
+{
+    EnumTfInputProcessorProfiles *This = impl_from_IEnumTfInputProcessorProfiles(iface);
+    LONG ref = InterlockedIncrement(&This->ref);
+
+    TRACE("(%p) ref=%d\n", This, ref);
+
+    return ref;
+}
+
+static ULONG WINAPI EnumTfInputProcessorProfiles_Release(IEnumTfInputProcessorProfiles *iface)
+{
+    EnumTfInputProcessorProfiles *This = impl_from_IEnumTfInputProcessorProfiles(iface);
+    LONG ref = InterlockedDecrement(&This->ref);
+
+    TRACE("(%p) ref=%d\n", This, ref);
+
+    if(!ref)
+        HeapFree(GetProcessHeap(), 0, This);
+
+    return ref;
+}
+
+static HRESULT WINAPI EnumTfInputProcessorProfiles_Clone(IEnumTfInputProcessorProfiles *iface,
+        IEnumTfInputProcessorProfiles **ret)
+{
+    EnumTfInputProcessorProfiles *This = impl_from_IEnumTfInputProcessorProfiles(iface);
+    FIXME("(%p)->(%p)\n", This, ret);
+    return E_NOTIMPL;
+}
+
+static HRESULT WINAPI EnumTfInputProcessorProfiles_Next(IEnumTfInputProcessorProfiles *iface, ULONG count,
+        TF_INPUTPROCESSORPROFILE *profile, ULONG *fetch)
+{
+    EnumTfInputProcessorProfiles *This = impl_from_IEnumTfInputProcessorProfiles(iface);
+
+    FIXME("(%p)->(%u %p %p)\n", This, count, profile, fetch);
+
+    if(fetch)
+        *fetch = 0;
+    return S_FALSE;
+}
+
+static HRESULT WINAPI EnumTfInputProcessorProfiles_Reset(IEnumTfInputProcessorProfiles *iface)
+{
+    EnumTfInputProcessorProfiles *This = impl_from_IEnumTfInputProcessorProfiles(iface);
+    FIXME("(%p)\n", This);
+    return E_NOTIMPL;
+}
+
+static HRESULT WINAPI EnumTfInputProcessorProfiles_Skip(IEnumTfInputProcessorProfiles *iface, ULONG count)
+{
+    EnumTfInputProcessorProfiles *This = impl_from_IEnumTfInputProcessorProfiles(iface);
+    FIXME("(%p)->(%u)\n", This, count);
+    return E_NOTIMPL;
+}
+
+static const IEnumTfInputProcessorProfilesVtbl EnumTfInputProcessorProfilesVtbl = {
+    EnumTfInputProcessorProfiles_QueryInterface,
+    EnumTfInputProcessorProfiles_AddRef,
+    EnumTfInputProcessorProfiles_Release,
+    EnumTfInputProcessorProfiles_Clone,
+    EnumTfInputProcessorProfiles_Next,
+    EnumTfInputProcessorProfiles_Reset,
+    EnumTfInputProcessorProfiles_Skip
+};
+
+static inline InputProcessorProfiles *impl_from_ITfInputProcessorProfiles(ITfInputProcessorProfiles *iface)
+{
+    return CONTAINING_RECORD(iface, InputProcessorProfiles, ITfInputProcessorProfiles_iface);
+}
 
-static inline InputProcessorProfiles *impl_from_ITfSourceVtbl(ITfSource *iface)
+static inline InputProcessorProfiles *impl_from_ITfSource(ITfSource *iface)
 {
-    return (InputProcessorProfiles *)((char *)iface - FIELD_OFFSET(InputProcessorProfiles,SourceVtbl));
+    return CONTAINING_RECORD(iface, InputProcessorProfiles, ITfSource_iface);
 }
 
-static void free_sink(InputProcessorProfilesSink *sink)
+static inline ProfilesEnumGuid *impl_from_IEnumGUID(IEnumGUID *iface)
 {
-        IUnknown_Release(sink->interfaces.pIUnknown);
-        HeapFree(GetProcessHeap(),0,sink);
+    return CONTAINING_RECORD(iface, ProfilesEnumGuid, IEnumGUID_iface);
+}
+
+static inline EnumTfLanguageProfiles *impl_from_IEnumTfLanguageProfiles(IEnumTfLanguageProfiles *iface)
+{
+    return CONTAINING_RECORD(iface, EnumTfLanguageProfiles, IEnumTfLanguageProfiles_iface);
 }
 
 static void InputProcessorProfiles_Destructor(InputProcessorProfiles *This)
 {
-    struct list *cursor, *cursor2;
     TRACE("destroying %p\n", This);
 
-    /* free sinks */
-    LIST_FOR_EACH_SAFE(cursor, cursor2, &This->LanguageProfileNotifySink)
-    {
-        InputProcessorProfilesSink* sink = LIST_ENTRY(cursor,InputProcessorProfilesSink,entry);
-        list_remove(cursor);
-        free_sink(sink);
-    }
-
+    free_sinks(&This->LanguageProfileNotifySink);
     HeapFree(GetProcessHeap(),0,This);
 }
 
@@ -160,39 +245,42 @@ static void add_userkey( REFCLSID rclsid, LANGID langid,
         RegCloseKey(key);
 }
 
-static HRESULT WINAPI InputProcessorProfiles_QueryInterface(ITfInputProcessorProfiles *iface, REFIID iid, LPVOID *ppvOut)
+static HRESULT WINAPI InputProcessorProfiles_QueryInterface(ITfInputProcessorProfiles *iface, REFIID iid, void **ppv)
 {
-    InputProcessorProfiles *This = (InputProcessorProfiles *)iface;
-    *ppvOut = NULL;
+    InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
 
     if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfInputProcessorProfiles))
     {
-        *ppvOut = This;
+        *ppv = &This->ITfInputProcessorProfiles_iface;
+    }
+    else if (IsEqualIID(iid, &IID_ITfInputProcessorProfileMgr))
+    {
+        *ppv = &This->ITfInputProcessorProfileMgr_iface;
     }
     else if (IsEqualIID(iid, &IID_ITfSource))
     {
-        *ppvOut = &This->SourceVtbl;
+        *ppv = &This->ITfSource_iface;
     }
-
-    if (*ppvOut)
+    else
     {
-        IUnknown_AddRef(iface);
-        return S_OK;
+        *ppv = NULL;
+        WARN("unsupported interface: %s\n", debugstr_guid(iid));
+        return E_NOINTERFACE;
     }
 
-    WARN("unsupported interface: %s\n", debugstr_guid(iid));
-    return E_NOINTERFACE;
+    ITfInputProcessorProfiles_AddRef(iface);
+    return S_OK;
 }
 
 static ULONG WINAPI InputProcessorProfiles_AddRef(ITfInputProcessorProfiles *iface)
 {
-    InputProcessorProfiles *This = (InputProcessorProfiles *)iface;
+    InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
     return InterlockedIncrement(&This->refCount);
 }
 
 static ULONG WINAPI InputProcessorProfiles_Release(ITfInputProcessorProfiles *iface)
 {
-    InputProcessorProfiles *This = (InputProcessorProfiles *)iface;
+    InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
     ULONG ret;
 
     ret = InterlockedDecrement(&This->refCount);
@@ -207,7 +295,7 @@ static ULONG WINAPI InputProcessorProfiles_Release(ITfInputProcessorProfiles *if
 static HRESULT WINAPI InputProcessorProfiles_Register(
         ITfInputProcessorProfiles *iface, REFCLSID rclsid)
 {
-    InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
+    InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
     HKEY tipkey;
     WCHAR buf[39];
     WCHAR fullkey[68];
@@ -229,9 +317,9 @@ static HRESULT WINAPI InputProcessorProfiles_Register(
 static HRESULT WINAPI InputProcessorProfiles_Unregister(
         ITfInputProcessorProfiles *iface, REFCLSID rclsid)
 {
+    InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
     WCHAR buf[39];
     WCHAR fullkey[68];
-    InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
 
     TRACE("(%p) %s\n",This,debugstr_guid(rclsid));
 
@@ -250,6 +338,7 @@ static HRESULT WINAPI InputProcessorProfiles_AddLanguageProfile(
         ULONG cchDesc, const WCHAR *pchIconFile, ULONG cchFile,
         ULONG uIconIndex)
 {
+    InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
     HKEY tipkey,fmtkey;
     WCHAR buf[39];
     WCHAR fullkey[100];
@@ -261,8 +350,6 @@ static HRESULT WINAPI InputProcessorProfiles_AddLanguageProfile(
     static const WCHAR icnf[] = {'I','c','o','n','F','i','l','e',0};
     static const WCHAR icni[] = {'I','c','o','n','I','n','d','e','x',0};
 
-    InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
-
     TRACE("(%p) %s %x %s %s %s %i\n",This,debugstr_guid(rclsid), langid,
             debugstr_guid(guidProfile), debugstr_wn(pchDesc,cchDesc),
             debugstr_wn(pchIconFile,cchFile),uIconIndex);
@@ -304,7 +391,7 @@ static HRESULT WINAPI InputProcessorProfiles_RemoveLanguageProfile(
         ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
         REFGUID guidProfile)
 {
-    InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
+    InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
     FIXME("STUB:(%p)\n",This);
     return E_NOTIMPL;
 }
@@ -312,7 +399,7 @@ static HRESULT WINAPI InputProcessorProfiles_RemoveLanguageProfile(
 static HRESULT WINAPI InputProcessorProfiles_EnumInputProcessorInfo(
         ITfInputProcessorProfiles *iface, IEnumGUID **ppEnum)
 {
-    InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
+    InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
     TRACE("(%p) %p\n",This,ppEnum);
     return ProfilesEnumGuid_Constructor(ppEnum);
 }
@@ -321,12 +408,12 @@ static HRESULT WINAPI InputProcessorProfiles_GetDefaultLanguageProfile(
         ITfInputProcessorProfiles *iface, LANGID langid, REFGUID catid,
         CLSID *pclsid, GUID *pguidProfile)
 {
+    InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
     WCHAR fullkey[168];
     WCHAR buf[39];
     HKEY hkey;
     DWORD count;
     ULONG res;
-    InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
 
     TRACE("%p) %x %s %p %p\n",This, langid, debugstr_guid(catid),pclsid,pguidProfile);
 
@@ -362,13 +449,13 @@ static HRESULT WINAPI InputProcessorProfiles_SetDefaultLanguageProfile(
         ITfInputProcessorProfiles *iface, LANGID langid, REFCLSID rclsid,
         REFGUID guidProfiles)
 {
+    InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
     WCHAR fullkey[168];
     WCHAR buf[39];
     HKEY hkey;
     GUID catid;
     HRESULT hr;
     ITfCategoryMgr *catmgr;
-    InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
     static const GUID * tipcats[3] = { &GUID_TFCAT_TIP_KEYBOARD,
                                        &GUID_TFCAT_TIP_SPEECH,
                                        &GUID_TFCAT_TIP_HANDWRITING };
@@ -412,10 +499,10 @@ static HRESULT WINAPI InputProcessorProfiles_ActivateLanguageProfile(
         ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
         REFGUID guidProfiles)
 {
+    InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
     HRESULT hr;
     BOOL enabled;
     TF_LANGUAGEPROFILE LanguageProfile;
-    InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
 
     TRACE("(%p) %s %x %s\n",This,debugstr_guid(rclsid),langid,debugstr_guid(guidProfiles));
 
@@ -438,18 +525,17 @@ static HRESULT WINAPI InputProcessorProfiles_ActivateLanguageProfile(
     LanguageProfile.clsid = *rclsid;
     LanguageProfile.langid = langid;
     LanguageProfile.guidProfile = *guidProfiles;
+    LanguageProfile.fActive = TRUE;
 
-    hr = add_active_textservice(&LanguageProfile);
-
-    return hr;
+    return add_active_textservice(&LanguageProfile);
 }
 
 static HRESULT WINAPI InputProcessorProfiles_GetActiveLanguageProfile(
         ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID *plangid,
         GUID *pguidProfile)
 {
+    InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
     TF_LANGUAGEPROFILE profile;
-    InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
 
     TRACE("(%p) %s %p %p\n",This,debugstr_guid(rclsid),plangid,pguidProfile);
 
@@ -473,7 +559,7 @@ static HRESULT WINAPI InputProcessorProfiles_GetLanguageProfileDescription(
         ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
         REFGUID guidProfile, BSTR *pbstrProfile)
 {
-    InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
+    InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
     FIXME("STUB:(%p)\n",This);
     return E_NOTIMPL;
 }
@@ -481,7 +567,7 @@ static HRESULT WINAPI InputProcessorProfiles_GetLanguageProfileDescription(
 static HRESULT WINAPI InputProcessorProfiles_GetCurrentLanguage(
         ITfInputProcessorProfiles *iface, LANGID *plangid)
 {
-    InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
+    InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
     TRACE("(%p) 0x%x\n",This,This->currentLanguage);
 
     if (!plangid)
@@ -495,19 +581,19 @@ static HRESULT WINAPI InputProcessorProfiles_GetCurrentLanguage(
 static HRESULT WINAPI InputProcessorProfiles_ChangeCurrentLanguage(
         ITfInputProcessorProfiles *iface, LANGID langid)
 {
+    InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
+    ITfLanguageProfileNotifySink *sink;
     struct list *cursor;
-    InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
     BOOL accept;
 
     FIXME("STUB:(%p)\n",This);
 
-    LIST_FOR_EACH(cursor, &This->LanguageProfileNotifySink)
+    SINK_FOR_EACH(cursor, &This->LanguageProfileNotifySink, ITfLanguageProfileNotifySink, sink)
     {
-        InputProcessorProfilesSink* sink = LIST_ENTRY(cursor,InputProcessorProfilesSink,entry);
         accept = TRUE;
-        ITfLanguageProfileNotifySink_OnLanguageChange(sink->interfaces.pITfLanguageProfileNotifySink, langid, &accept);
+        ITfLanguageProfileNotifySink_OnLanguageChange(sink, langid, &accept);
         if (!accept)
-            return  E_FAIL;
+            return E_FAIL;
     }
 
     /* TODO:  On successful language change call OnLanguageChanged sink */
@@ -517,7 +603,7 @@ static HRESULT WINAPI InputProcessorProfiles_ChangeCurrentLanguage(
 static HRESULT WINAPI InputProcessorProfiles_GetLanguageList(
         ITfInputProcessorProfiles *iface, LANGID **ppLangId, ULONG *pulCount)
 {
-    InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
+    InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
     FIXME("Semi-STUB:(%p)\n",This);
     *ppLangId = CoTaskMemAlloc(sizeof(LANGID));
     **ppLangId = This->currentLanguage;
@@ -529,22 +615,31 @@ static HRESULT WINAPI InputProcessorProfiles_EnumLanguageProfiles(
         ITfInputProcessorProfiles *iface, LANGID langid,
         IEnumTfLanguageProfiles **ppEnum)
 {
-    InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
+    InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
+    EnumTfLanguageProfiles *profenum;
+    HRESULT hr;
+
     TRACE("(%p) %x %p\n",This,langid,ppEnum);
-    return EnumTfLanguageProfiles_Constructor(langid, ppEnum);
+
+    if (!ppEnum)
+        return E_INVALIDARG;
+    hr = EnumTfLanguageProfiles_Constructor(langid, &profenum);
+    *ppEnum = &profenum->IEnumTfLanguageProfiles_iface;
+
+    return hr;
 }
 
 static HRESULT WINAPI InputProcessorProfiles_EnableLanguageProfile(
         ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
         REFGUID guidProfile, BOOL fEnable)
 {
+    InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
     HKEY key;
     WCHAR buf[39];
     WCHAR buf2[39];
     WCHAR fullkey[168];
     ULONG res;
 
-    InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
     TRACE("(%p) %s %x %s %i\n",This, debugstr_guid(rclsid), langid, debugstr_guid(guidProfile), fEnable);
 
     StringFromGUID2(rclsid, buf, 39);
@@ -568,13 +663,13 @@ static HRESULT WINAPI InputProcessorProfiles_IsEnabledLanguageProfile(
         ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
         REFGUID guidProfile, BOOL *pfEnable)
 {
+    InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
     HKEY key;
     WCHAR buf[39];
     WCHAR buf2[39];
     WCHAR fullkey[168];
     ULONG res;
 
-    InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
     TRACE("(%p) %s, %i, %s, %p\n",This,debugstr_guid(rclsid),langid,debugstr_guid(guidProfile),pfEnable);
 
     if (!pfEnable)
@@ -615,13 +710,13 @@ static HRESULT WINAPI InputProcessorProfiles_EnableLanguageProfileByDefault(
         ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
         REFGUID guidProfile, BOOL fEnable)
 {
+    InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
     HKEY key;
     WCHAR buf[39];
     WCHAR buf2[39];
     WCHAR fullkey[168];
     ULONG res;
 
-    InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
     TRACE("(%p) %s %x %s %i\n",This,debugstr_guid(rclsid),langid,debugstr_guid(guidProfile),fEnable);
 
     StringFromGUID2(rclsid, buf, 39);
@@ -645,18 +740,16 @@ static HRESULT WINAPI InputProcessorProfiles_SubstituteKeyboardLayout(
         ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
         REFGUID guidProfile, HKL hKL)
 {
-    InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
+    InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
     FIXME("STUB:(%p)\n",This);
     return E_NOTIMPL;
 }
 
-
-static const ITfInputProcessorProfilesVtbl InputProcessorProfiles_InputProcessorProfilesVtbl =
+static const ITfInputProcessorProfilesVtbl InputProcessorProfilesVtbl =
 {
     InputProcessorProfiles_QueryInterface,
     InputProcessorProfiles_AddRef,
     InputProcessorProfiles_Release,
-
     InputProcessorProfiles_Register,
     InputProcessorProfiles_Unregister,
     InputProcessorProfiles_AddLanguageProfile,
@@ -677,32 +770,150 @@ static const ITfInputProcessorProfilesVtbl InputProcessorProfiles_InputProcessor
     InputProcessorProfiles_SubstituteKeyboardLayout
 };
 
+static inline InputProcessorProfiles *impl_from_ITfInputProcessorProfileMgr(ITfInputProcessorProfileMgr *iface)
+{
+    return CONTAINING_RECORD(iface, InputProcessorProfiles, ITfInputProcessorProfileMgr_iface);
+}
+
+static HRESULT WINAPI InputProcessorProfileMgr_QueryInterface(ITfInputProcessorProfileMgr *iface, REFIID riid, void **ppv)
+{
+    InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
+    return ITfInputProcessorProfiles_QueryInterface(&This->ITfInputProcessorProfiles_iface, riid, ppv);
+}
+
+static ULONG WINAPI InputProcessorProfileMgr_AddRef(ITfInputProcessorProfileMgr *iface)
+{
+    InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
+    return ITfInputProcessorProfiles_AddRef(&This->ITfInputProcessorProfiles_iface);
+}
+
+static ULONG WINAPI InputProcessorProfileMgr_Release(ITfInputProcessorProfileMgr *iface)
+{
+    InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
+    return ITfInputProcessorProfiles_Release(&This->ITfInputProcessorProfiles_iface);
+}
+
+static HRESULT WINAPI InputProcessorProfileMgr_ActivateProfile(ITfInputProcessorProfileMgr *iface, DWORD dwProfileType,
+        LANGID langid, REFCLSID clsid, REFGUID guidProfile, HKL hkl, DWORD dwFlags)
+{
+    InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
+    FIXME("(%p)->(%d %x %s %s %p %x)\n", This, dwProfileType, langid, debugstr_guid(clsid),
+          debugstr_guid(guidProfile), hkl, dwFlags);
+    return E_NOTIMPL;
+}
+
+static HRESULT WINAPI InputProcessorProfileMgr_DeactivateProfile(ITfInputProcessorProfileMgr *iface, DWORD dwProfileType,
+        LANGID langid, REFCLSID clsid, REFGUID guidProfile, HKL hkl, DWORD dwFlags)
+{
+    InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
+    FIXME("(%p)->(%d %x %s %s %p %x)\n", This, dwProfileType, langid, debugstr_guid(clsid),
+          debugstr_guid(guidProfile), hkl, dwFlags);
+    return E_NOTIMPL;
+}
+
+static HRESULT WINAPI InputProcessorProfileMgr_GetProfile(ITfInputProcessorProfileMgr *iface, DWORD dwProfileType,
+        LANGID langid, REFCLSID clsid, REFGUID guidProfile, HKL hkl, TF_INPUTPROCESSORPROFILE *pProfile)
+{
+    InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
+    FIXME("(%p)->(%d %x %s %s %p %p)\n", This, dwProfileType, langid, debugstr_guid(clsid),
+          debugstr_guid(guidProfile), hkl, pProfile);
+    return E_NOTIMPL;
+}
+
+static HRESULT WINAPI InputProcessorProfileMgr_EnumProfiles(ITfInputProcessorProfileMgr *iface, LANGID langid,
+        IEnumTfInputProcessorProfiles **ppEnum)
+{
+    InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
+    EnumTfInputProcessorProfiles *enum_profiles;
+
+    TRACE("(%p)->(%x %p)\n", This, langid, ppEnum);
+
+    enum_profiles = HeapAlloc(GetProcessHeap(), 0, sizeof(*enum_profiles));
+    if(!enum_profiles)
+        return E_OUTOFMEMORY;
+
+    enum_profiles->IEnumTfInputProcessorProfiles_iface.lpVtbl = &EnumTfInputProcessorProfilesVtbl;
+    enum_profiles->ref = 1;
+
+    *ppEnum = &enum_profiles->IEnumTfInputProcessorProfiles_iface;
+    return S_OK;
+}
+
+static HRESULT WINAPI InputProcessorProfileMgr_ReleaseInputProcessor(ITfInputProcessorProfileMgr *iface, REFCLSID rclsid,
+        DWORD dwFlags)
+{
+    InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
+    FIXME("(%p)->(%s %x)\n", This, debugstr_guid(rclsid), dwFlags);
+    return E_NOTIMPL;
+}
+
+static HRESULT WINAPI InputProcessorProfileMgr_RegisterProfile(ITfInputProcessorProfileMgr *iface, REFCLSID rclsid,
+        LANGID langid, REFGUID guidProfile, const WCHAR *pchDesc, ULONG cchDesc, const WCHAR *pchIconFile,
+        ULONG cchFile, ULONG uIconIndex, HKL hklsubstitute, DWORD dwPreferredLayout, BOOL bEnabledByDefault,
+        DWORD dwFlags)
+{
+    InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
+    FIXME("(%p)->(%s %x %s %s %d %s %u %u %p %x %x %x)\n", This, debugstr_guid(rclsid), langid, debugstr_guid(guidProfile),
+          debugstr_w(pchDesc), cchDesc, debugstr_w(pchIconFile), cchFile, uIconIndex, hklsubstitute, dwPreferredLayout,
+          bEnabledByDefault, dwFlags);
+    return E_NOTIMPL;
+}
+
+static HRESULT WINAPI InputProcessorProfileMgr_UnregisterProfile(ITfInputProcessorProfileMgr *iface, REFCLSID rclsid,
+        LANGID langid, REFGUID guidProfile, DWORD dwFlags)
+{
+    InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
+    FIXME("(%p)->(%s %x %s %x)\n", This, debugstr_guid(rclsid), langid, debugstr_guid(guidProfile), dwFlags);
+    return E_NOTIMPL;
+}
+
+static HRESULT WINAPI InputProcessorProfileMgr_GetActiveProfile(ITfInputProcessorProfileMgr *iface, REFGUID catid,
+        TF_INPUTPROCESSORPROFILE *pProfile)
+{
+    InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
+    FIXME("(%p)->(%s %p)\n", This, debugstr_guid(catid), pProfile);
+    return E_NOTIMPL;
+}
+
+static const ITfInputProcessorProfileMgrVtbl InputProcessorProfileMgrVtbl = {
+    InputProcessorProfileMgr_QueryInterface,
+    InputProcessorProfileMgr_AddRef,
+    InputProcessorProfileMgr_Release,
+    InputProcessorProfileMgr_ActivateProfile,
+    InputProcessorProfileMgr_DeactivateProfile,
+    InputProcessorProfileMgr_GetProfile,
+    InputProcessorProfileMgr_EnumProfiles,
+    InputProcessorProfileMgr_ReleaseInputProcessor,
+    InputProcessorProfileMgr_RegisterProfile,
+    InputProcessorProfileMgr_UnregisterProfile,
+    InputProcessorProfileMgr_GetActiveProfile
+};
+
 /*****************************************************
  * ITfSource functions
  *****************************************************/
 static HRESULT WINAPI IPPSource_QueryInterface(ITfSource *iface, REFIID iid, LPVOID *ppvOut)
 {
-    InputProcessorProfiles *This = impl_from_ITfSourceVtbl(iface);
-    return InputProcessorProfiles_QueryInterface((ITfInputProcessorProfiles *)This, iid, *ppvOut);
+    InputProcessorProfiles *This = impl_from_ITfSource(iface);
+    return ITfInputProcessorProfiles_QueryInterface(&This->ITfInputProcessorProfiles_iface, iid, ppvOut);
 }
 
 static ULONG WINAPI IPPSource_AddRef(ITfSource *iface)
 {
-    InputProcessorProfiles *This = impl_from_ITfSourceVtbl(iface);
-    return InputProcessorProfiles_AddRef((ITfInputProcessorProfiles*)This);
+    InputProcessorProfiles *This = impl_from_ITfSource(iface);
+    return ITfInputProcessorProfiles_AddRef(&This->ITfInputProcessorProfiles_iface);
 }
 
 static ULONG WINAPI IPPSource_Release(ITfSource *iface)
 {
-    InputProcessorProfiles *This = impl_from_ITfSourceVtbl(iface);
-    return InputProcessorProfiles_Release((ITfInputProcessorProfiles *)This);
+    InputProcessorProfiles *This = impl_from_ITfSource(iface);
+    return ITfInputProcessorProfiles_Release(&This->ITfInputProcessorProfiles_iface);
 }
 
 static HRESULT WINAPI IPPSource_AdviseSink(ITfSource *iface,
         REFIID riid, IUnknown *punk, DWORD *pdwCookie)
 {
-    InputProcessorProfilesSink *ipps;
-    InputProcessorProfiles *This = impl_from_ITfSourceVtbl(iface);
+    InputProcessorProfiles *This = impl_from_ITfSource(iface);
 
     TRACE("(%p) %s %p %p\n",This,debugstr_guid(riid),punk,pdwCookie);
 
@@ -710,55 +921,30 @@ static HRESULT WINAPI IPPSource_AdviseSink(ITfSource *iface,
         return E_INVALIDARG;
 
     if (IsEqualIID(riid, &IID_ITfLanguageProfileNotifySink))
-    {
-        ipps = HeapAlloc(GetProcessHeap(),0,sizeof(InputProcessorProfilesSink));
-        if (!ipps)
-            return E_OUTOFMEMORY;
-        if (FAILED(IUnknown_QueryInterface(punk, riid, (LPVOID *)&ipps->interfaces.pITfLanguageProfileNotifySink)))
-        {
-            HeapFree(GetProcessHeap(),0,ipps);
-            return CONNECT_E_CANNOTCONNECT;
-        }
-        list_add_head(&This->LanguageProfileNotifySink,&ipps->entry);
-        *pdwCookie = generate_Cookie(COOKIE_MAGIC_IPPSINK, ipps);
-    }
-    else
-    {
-        FIXME("(%p) Unhandled Sink: %s\n",This,debugstr_guid(riid));
-        return E_NOTIMPL;
-    }
+        return advise_sink(&This->LanguageProfileNotifySink, &IID_ITfLanguageProfileNotifySink,
+                           COOKIE_MAGIC_IPPSINK, punk, pdwCookie);
 
-    TRACE("cookie %x\n",*pdwCookie);
-
-    return S_OK;
+    FIXME("(%p) Unhandled Sink: %s\n",This,debugstr_guid(riid));
+    return E_NOTIMPL;
 }
 
 static HRESULT WINAPI IPPSource_UnadviseSink(ITfSource *iface, DWORD pdwCookie)
 {
-    InputProcessorProfilesSink *sink;
-    InputProcessorProfiles *This = impl_from_ITfSourceVtbl(iface);
+    InputProcessorProfiles *This = impl_from_ITfSource(iface);
 
     TRACE("(%p) %x\n",This,pdwCookie);
 
     if (get_Cookie_magic(pdwCookie)!=COOKIE_MAGIC_IPPSINK)
         return E_INVALIDARG;
 
-    sink = (InputProcessorProfilesSink*)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 InputProcessorProfiles_SourceVtbl =
+static const ITfSourceVtbl InputProcessorProfilesSourceVtbl =
 {
     IPPSource_QueryInterface,
     IPPSource_AddRef,
     IPPSource_Release,
-
     IPPSource_AdviseSink,
     IPPSource_UnadviseSink,
 };
@@ -773,15 +959,16 @@ HRESULT InputProcessorProfiles_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut
     if (This == NULL)
         return E_OUTOFMEMORY;
 
-    This->InputProcessorProfilesVtbl= &InputProcessorProfiles_InputProcessorProfilesVtbl;
-    This->SourceVtbl = &InputProcessorProfiles_SourceVtbl;
+    This->ITfInputProcessorProfiles_iface.lpVtbl= &InputProcessorProfilesVtbl;
+    This->ITfSource_iface.lpVtbl = &InputProcessorProfilesSourceVtbl;
+    This->ITfInputProcessorProfileMgr_iface.lpVtbl = &InputProcessorProfileMgrVtbl;
     This->refCount = 1;
     This->currentLanguage = GetUserDefaultLCID();
 
     list_init(&This->LanguageProfileNotifySink);
 
-    TRACE("returning %p\n", This);
-    *ppOut = (IUnknown *)This;
+    *ppOut = (IUnknown *)&This->ITfInputProcessorProfiles_iface;
+    TRACE("returning %p\n", *ppOut);
     return S_OK;
 }
 
@@ -797,17 +984,17 @@ static void ProfilesEnumGuid_Destructor(ProfilesEnumGuid *This)
 
 static HRESULT WINAPI ProfilesEnumGuid_QueryInterface(IEnumGUID *iface, REFIID iid, LPVOID *ppvOut)
 {
-    ProfilesEnumGuid *This = (ProfilesEnumGuid *)iface;
+    ProfilesEnumGuid *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;
     }
 
@@ -817,13 +1004,13 @@ static HRESULT WINAPI ProfilesEnumGuid_QueryInterface(IEnumGUID *iface, REFIID i
 
 static ULONG WINAPI ProfilesEnumGuid_AddRef(IEnumGUID *iface)
 {
-    ProfilesEnumGuid *This = (ProfilesEnumGuid*)iface;
+    ProfilesEnumGuid *This = impl_from_IEnumGUID(iface);
     return InterlockedIncrement(&This->refCount);
 }
 
 static ULONG WINAPI ProfilesEnumGuid_Release(IEnumGUID *iface)
 {
-    ProfilesEnumGuid *This = (ProfilesEnumGuid *)iface;
+    ProfilesEnumGuid *This = impl_from_IEnumGUID(iface);
     ULONG ret;
 
     ret = InterlockedDecrement(&This->refCount);
@@ -838,7 +1025,7 @@ static ULONG WINAPI ProfilesEnumGuid_Release(IEnumGUID *iface)
 static HRESULT WINAPI ProfilesEnumGuid_Next( LPENUMGUID iface,
     ULONG celt, GUID *rgelt, ULONG *pceltFetched)
 {
-    ProfilesEnumGuid *This = (ProfilesEnumGuid *)iface;
+    ProfilesEnumGuid *This = impl_from_IEnumGUID(iface);
     ULONG fetched = 0;
 
     TRACE("(%p)\n",This);
@@ -870,7 +1057,7 @@ static HRESULT WINAPI ProfilesEnumGuid_Next( LPENUMGUID iface,
 
 static HRESULT WINAPI ProfilesEnumGuid_Skip( LPENUMGUID iface, ULONG celt)
 {
-    ProfilesEnumGuid *This = (ProfilesEnumGuid *)iface;
+    ProfilesEnumGuid *This = impl_from_IEnumGUID(iface);
     TRACE("(%p)\n",This);
 
     This->next_index += celt;
@@ -879,7 +1066,7 @@ static HRESULT WINAPI ProfilesEnumGuid_Skip( LPENUMGUID iface, ULONG celt)
 
 static HRESULT WINAPI ProfilesEnumGuid_Reset( LPENUMGUID iface)
 {
-    ProfilesEnumGuid *This = (ProfilesEnumGuid *)iface;
+    ProfilesEnumGuid *This = impl_from_IEnumGUID(iface);
     TRACE("(%p)\n",This);
     This->next_index = 0;
     return S_OK;
@@ -888,7 +1075,7 @@ static HRESULT WINAPI ProfilesEnumGuid_Reset( LPENUMGUID iface)
 static HRESULT WINAPI ProfilesEnumGuid_Clone( LPENUMGUID iface,
     IEnumGUID **ppenum)
 {
-    ProfilesEnumGuid *This = (ProfilesEnumGuid *)iface;
+    ProfilesEnumGuid *This = impl_from_IEnumGUID(iface);
     HRESULT res;
 
     TRACE("(%p)\n",This);
@@ -898,17 +1085,17 @@ static HRESULT WINAPI ProfilesEnumGuid_Clone( LPENUMGUID iface,
     res = ProfilesEnumGuid_Constructor(ppenum);
     if (SUCCEEDED(res))
     {
-        ProfilesEnumGuid *new_This = (ProfilesEnumGuid *)*ppenum;
+        ProfilesEnumGuid *new_This = impl_from_IEnumGUID(*ppenum);
         new_This->next_index = This->next_index;
     }
     return res;
 }
 
-static const IEnumGUIDVtbl IEnumGUID_Vtbl ={
+static const IEnumGUIDVtbl EnumGUIDVtbl =
+{
     ProfilesEnumGuid_QueryInterface,
     ProfilesEnumGuid_AddRef,
     ProfilesEnumGuid_Release,
-
     ProfilesEnumGuid_Next,
     ProfilesEnumGuid_Skip,
     ProfilesEnumGuid_Reset,
@@ -923,7 +1110,7 @@ static HRESULT ProfilesEnumGuid_Constructor(IEnumGUID **ppOut)
     if (This == NULL)
         return E_OUTOFMEMORY;
 
-    This->Vtbl= &IEnumGUID_Vtbl;
+    This->IEnumGUID_iface.lpVtbl= &EnumGUIDVtbl;
     This->refCount = 1;
 
     if (RegCreateKeyExW(HKEY_LOCAL_MACHINE, szwSystemTIPKey, 0, NULL, 0,
@@ -933,8 +1120,8 @@ static HRESULT ProfilesEnumGuid_Constructor(IEnumGUID **ppOut)
         return E_FAIL;
     }
 
-    TRACE("returning %p\n", This);
-    *ppOut = (IEnumGUID*)This;
+    *ppOut = &This->IEnumGUID_iface;
+    TRACE("returning %p\n", *ppOut);
     return S_OK;
 }
 
@@ -953,17 +1140,18 @@ static void EnumTfLanguageProfiles_Destructor(EnumTfLanguageProfiles *This)
 
 static HRESULT WINAPI EnumTfLanguageProfiles_QueryInterface(IEnumTfLanguageProfiles *iface, REFIID iid, LPVOID *ppvOut)
 {
-    EnumTfLanguageProfiles *This = (EnumTfLanguageProfiles *)iface;
+    EnumTfLanguageProfiles *This = impl_from_IEnumTfLanguageProfiles(iface);
+
     *ppvOut = NULL;
 
     if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_IEnumTfLanguageProfiles))
     {
-        *ppvOut = This;
+        *ppvOut = &This->IEnumTfLanguageProfiles_iface;
     }
 
     if (*ppvOut)
     {
-        IUnknown_AddRef(iface);
+        IEnumTfLanguageProfiles_AddRef(iface);
         return S_OK;
     }
 
@@ -973,13 +1161,13 @@ static HRESULT WINAPI EnumTfLanguageProfiles_QueryInterface(IEnumTfLanguageProfi
 
 static ULONG WINAPI EnumTfLanguageProfiles_AddRef(IEnumTfLanguageProfiles *iface)
 {
-    EnumTfLanguageProfiles *This = (EnumTfLanguageProfiles*)iface;
+    EnumTfLanguageProfiles *This = impl_from_IEnumTfLanguageProfiles(iface);
     return InterlockedIncrement(&This->refCount);
 }
 
 static ULONG WINAPI EnumTfLanguageProfiles_Release(IEnumTfLanguageProfiles *iface)
 {
-    EnumTfLanguageProfiles *This = (EnumTfLanguageProfiles *)iface;
+    EnumTfLanguageProfiles *This = impl_from_IEnumTfLanguageProfiles(iface);
     ULONG ret;
 
     ret = InterlockedDecrement(&This->refCount);
@@ -1046,7 +1234,7 @@ static INT next_LanguageProfile(EnumTfLanguageProfiles *This, CLSID clsid, TF_LA
 static HRESULT WINAPI EnumTfLanguageProfiles_Next(IEnumTfLanguageProfiles *iface,
     ULONG ulCount, TF_LANGUAGEPROFILE *pProfile, ULONG *pcFetch)
 {
-    EnumTfLanguageProfiles *This = (EnumTfLanguageProfiles *)iface;
+    EnumTfLanguageProfiles *This = impl_from_IEnumTfLanguageProfiles(iface);
     ULONG fetched = 0;
 
     TRACE("(%p)\n",This);
@@ -1088,14 +1276,14 @@ static HRESULT WINAPI EnumTfLanguageProfiles_Next(IEnumTfLanguageProfiles *iface
 
 static HRESULT WINAPI EnumTfLanguageProfiles_Skip( IEnumTfLanguageProfiles* iface, ULONG celt)
 {
-    EnumTfLanguageProfiles *This = (EnumTfLanguageProfiles *)iface;
+    EnumTfLanguageProfiles *This = impl_from_IEnumTfLanguageProfiles(iface);
     FIXME("STUB (%p)\n",This);
     return E_NOTIMPL;
 }
 
 static HRESULT WINAPI EnumTfLanguageProfiles_Reset( IEnumTfLanguageProfiles* iface)
 {
-    EnumTfLanguageProfiles *This = (EnumTfLanguageProfiles *)iface;
+    EnumTfLanguageProfiles *This = impl_from_IEnumTfLanguageProfiles(iface);
     TRACE("(%p)\n",This);
     This->tip_index = 0;
     if (This->langkey)
@@ -1108,17 +1296,17 @@ static HRESULT WINAPI EnumTfLanguageProfiles_Reset( IEnumTfLanguageProfiles* ifa
 static HRESULT WINAPI EnumTfLanguageProfiles_Clone( IEnumTfLanguageProfiles *iface,
     IEnumTfLanguageProfiles **ppenum)
 {
-    EnumTfLanguageProfiles *This = (EnumTfLanguageProfiles *)iface;
+    EnumTfLanguageProfiles *This = impl_from_IEnumTfLanguageProfiles(iface);
+    EnumTfLanguageProfiles *new_This;
     HRESULT res;
 
     TRACE("(%p)\n",This);
 
     if (ppenum == NULL) return E_POINTER;
 
-    res = EnumTfLanguageProfiles_Constructor(This->langid, ppenum);
+    res = EnumTfLanguageProfiles_Constructor(This->langid, &new_This);
     if (SUCCEEDED(res))
     {
-        EnumTfLanguageProfiles *new_This = (EnumTfLanguageProfiles *)*ppenum;
         new_This->tip_index = This->tip_index;
         lstrcpynW(new_This->szwCurrentClsid,This->szwCurrentClsid,39);
 
@@ -1131,22 +1319,23 @@ static HRESULT WINAPI EnumTfLanguageProfiles_Clone( IEnumTfLanguageProfiles *ifa
             res = RegOpenKeyExW(new_This->tipkey, fullkey, 0, KEY_READ | KEY_WRITE, &This->langkey);
             new_This->lang_index = This->lang_index;
         }
+        *ppenum = &new_This->IEnumTfLanguageProfiles_iface;
     }
     return res;
 }
 
-static const IEnumTfLanguageProfilesVtbl IEnumTfLanguageProfiles_Vtbl ={
+static const IEnumTfLanguageProfilesVtbl EnumTfLanguageProfilesVtbl =
+{
     EnumTfLanguageProfiles_QueryInterface,
     EnumTfLanguageProfiles_AddRef,
     EnumTfLanguageProfiles_Release,
-
     EnumTfLanguageProfiles_Clone,
     EnumTfLanguageProfiles_Next,
     EnumTfLanguageProfiles_Reset,
     EnumTfLanguageProfiles_Skip
 };
 
-static HRESULT EnumTfLanguageProfiles_Constructor(LANGID langid, IEnumTfLanguageProfiles **ppOut)
+static HRESULT EnumTfLanguageProfiles_Constructor(LANGID langid, EnumTfLanguageProfiles **out)
 {
     HRESULT hr;
     EnumTfLanguageProfiles *This;
@@ -1155,7 +1344,7 @@ static HRESULT EnumTfLanguageProfiles_Constructor(LANGID langid, IEnumTfLanguage
     if (This == NULL)
         return E_OUTOFMEMORY;
 
-    This->Vtbl= &IEnumTfLanguageProfiles_Vtbl;
+    This->IEnumTfLanguageProfiles_iface.lpVtbl= &EnumTfLanguageProfilesVtbl;
     This->refCount = 1;
     This->langid = langid;
 
@@ -1173,7 +1362,7 @@ static HRESULT EnumTfLanguageProfiles_Constructor(LANGID langid, IEnumTfLanguage
         return E_FAIL;
     }
 
-    TRACE("returning %p\n", This);
-    *ppOut = (IEnumTfLanguageProfiles*)This;
+    *out = This;
+    TRACE("returning %p\n", *out);
     return S_OK;
 }