[MSCTF] Sync with Wine Staging 3.3. CORE-14434
[reactos.git] / dll / win32 / msctf / inputprocessor.c
index f7561a9..fdeba38 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
+#include "config.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/unicode.h"
+
+#include "msctf.h"
 #include "msctf_internal.h"
 
+WINE_DEFAULT_DEBUG_CHANNEL(msctf);
+
 static const WCHAR szwLngp[] = {'L','a','n','g','u','a','g','e','P','r','o','f','i','l','e',0};
 static const WCHAR szwEnable[] = {'E','n','a','b','l','e',0};
 static const WCHAR szwTipfmt[] = {'%','s','\\','%','s',0};
@@ -30,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 {
     ITfInputProcessorProfiles ITfInputProcessorProfiles_iface;
     ITfSource ITfSource_iface;
-    /* const ITfInputProcessorProfileMgrVtbl *InputProcessorProfileMgrVtbl; */
+    ITfInputProcessorProfileMgr ITfInputProcessorProfileMgr_iface;
     /* const ITfInputProcessorProfilesExVtbl *InputProcessorProfilesExVtbl; */
     /* const ITfInputProcessorProfileSubstituteLayoutVtbl *InputProcessorProfileSubstituteLayoutVtbl; */
     LONG refCount;
@@ -75,8 +87,106 @@ 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)
 {
@@ -98,25 +208,11 @@ static inline EnumTfLanguageProfiles *impl_from_IEnumTfLanguageProfiles(IEnumTfL
     return CONTAINING_RECORD(iface, EnumTfLanguageProfiles, IEnumTfLanguageProfiles_iface);
 }
 
-static void free_sink(InputProcessorProfilesSink *sink)
-{
-        IUnknown_Release(sink->interfaces.pIUnknown);
-        HeapFree(GetProcessHeap(),0,sink);
-}
-
 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);
 }
 
@@ -149,28 +245,31 @@ 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 = impl_from_ITfInputProcessorProfiles(iface);
-    *ppvOut = NULL;
 
     if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfInputProcessorProfiles))
     {
-        *ppvOut = &This->ITfInputProcessorProfiles_iface;
+        *ppv = &This->ITfInputProcessorProfiles_iface;
+    }
+    else if (IsEqualIID(iid, &IID_ITfInputProcessorProfileMgr))
+    {
+        *ppv = &This->ITfInputProcessorProfileMgr_iface;
     }
     else if (IsEqualIID(iid, &IID_ITfSource))
     {
-        *ppvOut = &This->ITfSource_iface;
+        *ppv = &This->ITfSource_iface;
     }
-
-    if (*ppvOut)
+    else
     {
-        ITfInputProcessorProfiles_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)
@@ -227,8 +326,8 @@ static HRESULT WINAPI InputProcessorProfiles_Unregister(
     StringFromGUID2(rclsid, buf, 39);
     sprintfW(fullkey,szwTipfmt,szwSystemTIPKey,buf);
 
-    SHDeleteKeyW(HKEY_LOCAL_MACHINE, fullkey);
-    SHDeleteKeyW(HKEY_CURRENT_USER, fullkey);
+    RegDeleteTreeW(HKEY_LOCAL_MACHINE, fullkey);
+    RegDeleteTreeW(HKEY_CURRENT_USER, fullkey);
 
     return S_OK;
 }
@@ -426,10 +525,9 @@ 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(
@@ -484,18 +582,18 @@ static HRESULT WINAPI InputProcessorProfiles_ChangeCurrentLanguage(
         ITfInputProcessorProfiles *iface, LANGID langid)
 {
     InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
+    ITfLanguageProfileNotifySink *sink;
     struct list *cursor;
     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 */
@@ -518,8 +616,17 @@ static HRESULT WINAPI InputProcessorProfiles_EnumLanguageProfiles(
         IEnumTfLanguageProfiles **ppEnum)
 {
     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(
@@ -663,6 +770,125 @@ static const ITfInputProcessorProfilesVtbl InputProcessorProfilesVtbl =
     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
  *****************************************************/
@@ -688,7 +914,6 @@ static HRESULT WINAPI IPPSource_AdviseSink(ITfSource *iface,
         REFIID riid, IUnknown *punk, DWORD *pdwCookie)
 {
     InputProcessorProfiles *This = impl_from_ITfSource(iface);
-    InputProcessorProfilesSink *ipps;
 
     TRACE("(%p) %s %p %p\n",This,debugstr_guid(riid),punk,pdwCookie);
 
@@ -696,47 +921,23 @@ 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;
-    }
-
-    TRACE("cookie %x\n",*pdwCookie);
+        return advise_sink(&This->LanguageProfileNotifySink, &IID_ITfLanguageProfileNotifySink,
+                           COOKIE_MAGIC_IPPSINK, punk, 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)
 {
     InputProcessorProfiles *This = impl_from_ITfSource(iface);
-    InputProcessorProfilesSink *sink;
 
     TRACE("(%p) %x\n",This,pdwCookie);
 
     if (get_Cookie_magic(pdwCookie)!=COOKIE_MAGIC_IPPSINK)
         return E_INVALIDARG;
 
-    sink = 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 InputProcessorProfilesSourceVtbl =
@@ -760,6 +961,7 @@ HRESULT InputProcessorProfiles_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut
 
     This->ITfInputProcessorProfiles_iface.lpVtbl= &InputProcessorProfilesVtbl;
     This->ITfSource_iface.lpVtbl = &InputProcessorProfilesSourceVtbl;
+    This->ITfInputProcessorProfileMgr_iface.lpVtbl = &InputProcessorProfileMgrVtbl;
     This->refCount = 1;
     This->currentLanguage = GetUserDefaultLCID();
 
@@ -1095,16 +1297,16 @@ static HRESULT WINAPI EnumTfLanguageProfiles_Clone( IEnumTfLanguageProfiles *ifa
     IEnumTfLanguageProfiles **ppenum)
 {
     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);
 
@@ -1117,6 +1319,7 @@ 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;
 }
@@ -1132,7 +1335,7 @@ static const IEnumTfLanguageProfilesVtbl EnumTfLanguageProfilesVtbl =
     EnumTfLanguageProfiles_Skip
 };
 
-static HRESULT EnumTfLanguageProfiles_Constructor(LANGID langid, IEnumTfLanguageProfiles **ppOut)
+static HRESULT EnumTfLanguageProfiles_Constructor(LANGID langid, EnumTfLanguageProfiles **out)
 {
     HRESULT hr;
     EnumTfLanguageProfiles *This;
@@ -1159,7 +1362,7 @@ static HRESULT EnumTfLanguageProfiles_Constructor(LANGID langid, IEnumTfLanguage
         return E_FAIL;
     }
 
-    *ppOut = &This->IEnumTfLanguageProfiles_iface;
-    TRACE("returning %p\n", *ppOut);
+    *out = This;
+    TRACE("returning %p\n", *out);
     return S_OK;
 }