https://git.reactos.org/?p=reactos.git;a=commitdiff;h=eb72347672f6f5750c06aa74bba559f69e637ad7

commit eb72347672f6f5750c06aa74bba559f69e637ad7
Author:     Katayama Hirofumi MZ <katayama.hirofumi...@gmail.com>
AuthorDate: Sat Dec 23 09:34:41 2023 +0900
Commit:     Katayama Hirofumi MZ <katayama.hirofumi...@gmail.com>
CommitDate: Sat Dec 23 09:34:41 2023 +0900

    [CTFMON][MSCTFIME][SDK] Refactoring on Cicero design
    
    CORE-19362
---
 base/applications/ctfmon/ctfmon.cpp  |  6 +++
 dll/ime/msctfime/msctfime.cpp        | 62 +++++++++++------------
 sdk/include/reactos/cicero/cicbase.h | 96 ++++++++++++++++++++++++++++++++++++
 3 files changed, 133 insertions(+), 31 deletions(-)

diff --git a/base/applications/ctfmon/ctfmon.cpp 
b/base/applications/ctfmon/ctfmon.cpp
index c0da53c4cf4..71e7aeae2af 100644
--- a/base/applications/ctfmon/ctfmon.cpp
+++ b/base/applications/ctfmon/ctfmon.cpp
@@ -180,6 +180,9 @@ InitApp(
     g_bOnWow64  = cicIsWow64();   // Is the current process on WoW64?
     cicGetOSInfo(&g_uACP, &g_dwOsInfo); // Get OS info
 
+    // Initialize Cicero
+    TFInitLib();
+
     // Create a mutex for Cicero
     g_hCicMutex = TF_CreateCicLoadMutex(&g_fWinLogon);
     if (!g_hCicMutex)
@@ -234,6 +237,9 @@ UninitApp(VOID)
     // Close TIP Bar Popup
     ClosePopupTipbar();
 
+    // Release Cicero
+    TFUninitLib();
+
     // Close the mutex
     ::CloseHandle(g_hCicMutex);
     g_hCicMutex = NULL;
diff --git a/dll/ime/msctfime/msctfime.cpp b/dll/ime/msctfime/msctfime.cpp
index cfb29f4db17..6aa33c76490 100644
--- a/dll/ime/msctfime/msctfime.cpp
+++ b/dll/ime/msctfime/msctfime.cpp
@@ -120,13 +120,7 @@ IsInteractiveUserLogon(VOID)
     return bOK && IsMember;
 }
 
-typedef struct LIBTHREAD
-{
-    IUnknown *m_pUnknown1;
-    ITfDisplayAttributeMgr *m_pDisplayAttrMgr;
-} LIBTHREAD, *PLIBTHREAD;
-
-HRESULT InitDisplayAttrbuteLib(PLIBTHREAD pLibThread)
+HRESULT InitDisplayAttrbuteLib(PCIC_LIBTHREAD pLibThread)
 {
     if (!pLibThread)
         return E_FAIL;
@@ -141,7 +135,7 @@ HRESULT InitDisplayAttrbuteLib(PLIBTHREAD pLibThread)
     return E_NOTIMPL;
 }
 
-HRESULT UninitDisplayAttrbuteLib(PLIBTHREAD pLibThread)
+HRESULT UninitDisplayAttrbuteLib(PCIC_LIBTHREAD pLibThread)
 {
     if (!pLibThread)
         return E_FAIL;
@@ -155,23 +149,6 @@ HRESULT UninitDisplayAttrbuteLib(PLIBTHREAD pLibThread)
     return S_OK;
 }
 
-void TFUninitLib_Thread(PLIBTHREAD pLibThread)
-{
-    if (!pLibThread)
-        return;
-
-    if (pLibThread->m_pUnknown1)
-    {
-        pLibThread->m_pUnknown1->Release();
-        pLibThread->m_pUnknown1 = NULL;
-    }
-    if (pLibThread->m_pDisplayAttrMgr)
-    {
-        pLibThread->m_pDisplayAttrMgr->Release();
-        pLibThread->m_pDisplayAttrMgr = NULL;
-    }
-}
-
 /***********************************************************************
  *      Compartment
  */
@@ -542,7 +519,7 @@ public:
     DWORD m_dw3[19];
 
 public:
-    CicInputContext(TfClientId cliendId, LIBTHREAD *pLibThread, HIMC hIMC);
+    CicInputContext(TfClientId cliendId, PCIC_LIBTHREAD pLibThread, HIMC hIMC);
     virtual ~CicInputContext()
     {
     }
@@ -576,7 +553,7 @@ public:
 /**
  * @unimplemented
  */
-CicInputContext::CicInputContext(TfClientId cliendId, LIBTHREAD *pLibThread, 
HIMC hIMC)
+CicInputContext::CicInputContext(TfClientId cliendId, PCIC_LIBTHREAD 
pLibThread, HIMC hIMC)
 {
     m_hIMC = hIMC;
     m_guid = GUID_NULL;
@@ -1040,7 +1017,7 @@ protected:
     ITfDocumentMgr *m_pDocMgr;
     CThreadMgrEventSink *m_pThreadMgrEventSink;
     TfClientId m_cliendId;
-    LIBTHREAD m_LibThread;
+    CIC_LIBTHREAD m_LibThread;
     DWORD m_dw21;
 
     static BOOL CALLBACK EnumCreateInputContextCallback(HIMC hIMC, LPARAM 
lParam);
@@ -2833,6 +2810,22 @@ VOID DetachIME(VOID)
 /**
  * @unimplemented
  */
+VOID InitUIFLib(VOID)
+{
+    //FIXME
+}
+
+/**
+ * @unimplemented
+ */
+VOID DoneUIFLib(VOID)
+{
+    //FIXME
+}
+
+/**
+ * @implemented
+ */
 BOOL ProcessAttach(HINSTANCE hinstDLL)
 {
     g_hInst = hinstDLL;
@@ -2844,7 +2837,10 @@ BOOL ProcessAttach(HINSTANCE hinstDLL)
 
     cicGetOSInfo(&g_uACP, &g_dwOSInfo);
 
-    // FIXME
+    InitUIFLib();
+
+    if (!TFInitLib())
+        return FALSE;
 
     gfTFInitLib = TRUE;
     return AttachIME();
@@ -2857,14 +2853,18 @@ VOID ProcessDetach(HINSTANCE hinstDLL)
 {
     // FIXME
 
+    TF_DllDetachInOther();
+
     if (gfTFInitLib)
+    {
         DetachIME();
+        TFUninitLib();
+    }
 
     DeleteCriticalSection(&g_csLock);
     TLS::InternalDestroyTLS();
     TLS::Uninitialize();
-
-    // FIXME
+    DoneUIFLib();
 }
 
 /**
diff --git a/sdk/include/reactos/cicero/cicbase.h 
b/sdk/include/reactos/cicero/cicbase.h
index 9b934991e2d..805a8187d7b 100644
--- a/sdk/include/reactos/cicero/cicbase.h
+++ b/sdk/include/reactos/cicero/cicbase.h
@@ -49,6 +49,12 @@ inline void __cdecl operator delete(void* ptr, size_t size) 
noexcept
     cicMemFree(ptr);
 }
 
+typedef struct CIC_LIBTHREAD
+{
+    IUnknown *m_pUnknown1;
+    ITfDisplayAttributeMgr *m_pDisplayAttrMgr;
+} CIC_LIBTHREAD, *PCIC_LIBTHREAD;
+
 /* The flags of cicGetOSInfo() */
 #define CIC_OSINFO_NT     0x01
 #define CIC_OSINFO_2KPLUS 0x02
@@ -217,3 +223,93 @@ Failure:
     m_cchPath = 0;
     return FALSE;
 }
+
+// ole32!CoCreateInstance
+typedef HRESULT (WINAPI *FN_CoCreateInstance)(
+    REFCLSID rclsid,
+    LPUNKNOWN pUnkOuter,
+    DWORD dwClsContext,
+    REFIID iid,
+    LPVOID *ppv);
+
+static inline FN_CoCreateInstance
+_cicGetSetUserCoCreateInstance(FN_CoCreateInstance fnUserCoCreateInstance)
+{
+    static FN_CoCreateInstance s_fn = NULL;
+    if (fnUserCoCreateInstance)
+        s_fn = fnUserCoCreateInstance;
+    return s_fn;
+}
+
+/**
+ * @implemented
+ */
+static inline HRESULT
+cicCoCreateInstance(
+    REFCLSID rclsid,
+    LPUNKNOWN pUnkOuter,
+    DWORD dwClsContext,
+    REFIID iid,
+    LPVOID *ppv)
+{
+    FN_CoCreateInstance fnUserCoCreateInstance = 
_cicGetSetUserCoCreateInstance(NULL);
+    if (fnUserCoCreateInstance)
+        return fnUserCoCreateInstance(rclsid, pUnkOuter, dwClsContext, iid, 
ppv);
+
+    static HINSTANCE s_hOle32 = NULL;
+    static FN_CoCreateInstance s_fnCoCreateInstance = NULL;
+    if (!s_fnCoCreateInstance)
+    {
+        if (!s_hOle32)
+            s_hOle32 = cicLoadSystemLibrary(L"ole32.dll", FALSE);
+        if (!s_hOle32)
+            return E_NOTIMPL;
+        s_fnCoCreateInstance = (FN_CoCreateInstance)GetProcAddress(s_hOle32, 
"CoCreateInstance");
+        if (!s_fnCoCreateInstance)
+            return E_NOTIMPL;
+    }
+
+    return s_fnCoCreateInstance(rclsid, pUnkOuter, dwClsContext, iid, ppv);
+}
+
+/**
+ * @implemented
+ */
+static inline BOOL
+TFInitLib(FN_CoCreateInstance fnCoCreateInstance = NULL)
+{
+    if (fnCoCreateInstance)
+        _cicGetSetUserCoCreateInstance(fnCoCreateInstance);
+    return TRUE;
+}
+
+/**
+ * @unimplemented
+ */
+static inline VOID
+TFUninitLib(VOID)
+{
+    //FIXME
+}
+
+/**
+ * @implemented
+ */
+static inline VOID
+TFUninitLib_Thread(PCIC_LIBTHREAD pLibThread)
+{
+    if (!pLibThread)
+        return;
+
+    if (pLibThread->m_pUnknown1)
+    {
+        pLibThread->m_pUnknown1->Release();
+        pLibThread->m_pUnknown1 = NULL;
+    }
+
+    if (pLibThread->m_pDisplayAttrMgr)
+    {
+        pLibThread->m_pDisplayAttrMgr->Release();
+        pLibThread->m_pDisplayAttrMgr = NULL;
+    }
+}

Reply via email to