https://git.reactos.org/?p=reactos.git;a=commitdiff;h=9d495475f027ad64a70d6…
commit 9d495475f027ad64a70d619284db31a7c6d242bc
Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Wed Dec 20 17:51:37 2023 +0900
Commit: GitHub <noreply(a)github.com>
CommitDate: Wed Dec 20 17:51:37 2023 +0900
[MSCTFIME][MSCTF][SDK] Add compartment helper functions (#6202)
- Implement GetCompartment,
SetCompartmentDWORD,
GetCompartmentDWORD,
SetCompartmentUnknown, and
ClearCompartment helper functions.
- Add TF_DllDetachInOther prototype
to "msctf.idl".
CORE-19360
---
dll/ime/msctfime/msctfime.cpp | 144 +++++++++++++++++++++++++++++++++++++++++-
dll/win32/msctf/msctf.spec | 2 +-
sdk/include/psdk/msctf.idl | 1 +
3 files changed, 144 insertions(+), 3 deletions(-)
diff --git a/dll/ime/msctfime/msctfime.cpp b/dll/ime/msctfime/msctfime.cpp
index db9c0fe352b..044a6bc8cb2 100644
--- a/dll/ime/msctfime/msctfime.cpp
+++ b/dll/ime/msctfime/msctfime.cpp
@@ -164,6 +164,146 @@ void TFUninitLib_Thread(PLIBTHREAD pLibThread)
}
}
+HRESULT
+GetCompartment(
+ IUnknown *pUnknown,
+ REFGUID rguid,
+ ITfCompartment **ppComp,
+ BOOL bThread)
+{
+ ITfThreadMgr *pThreadMgr = NULL;
+ ITfCompartmentMgr *pCompMgr = NULL;
+
+ *ppComp = NULL;
+ HRESULT hr;
+ if (bThread)
+ {
+ hr = pUnknown->QueryInterface(IID_ITfThreadMgr, (void **)&pThreadMgr);
+ if (FAILED(hr))
+ return hr;
+
+ hr = pThreadMgr->GetGlobalCompartment(&pCompMgr);
+ }
+ else
+ {
+ hr = pUnknown->QueryInterface(IID_ITfCompartmentMgr, (void **)&pCompMgr);
+ }
+
+ if (SUCCEEDED(hr))
+ {
+ if (pCompMgr)
+ hr = pCompMgr->GetCompartment(rguid, ppComp);
+ else
+ hr = E_FAIL;
+ }
+
+ if (pThreadMgr)
+ pThreadMgr->Release();
+
+ return hr;
+}
+
+HRESULT
+SetCompartmentDWORD(
+ TfEditCookie cookie,
+ IUnknown *pUnknown,
+ REFGUID rguid,
+ VARTYPE type,
+ BOOL bThread)
+{
+ ITfCompartment *pComp = NULL;
+ HRESULT hr = GetCompartment(pUnknown, rguid, &pComp, bThread);
+ if (FAILED(hr))
+ return hr;
+
+ VARIANT vari;
+ V_I4(&vari) = type;
+ V_VT(&vari) = VT_I4;
+ hr = pComp->SetValue(cookie, &vari);
+ pComp->Release();
+
+ return hr;
+}
+
+HRESULT
+GetCompartmentDWORD(
+ IUnknown *pUnknown,
+ REFGUID rguid,
+ ITfCompartment *pComp,
+ BOOL bThread)
+{
+ HRESULT hr = GetCompartment(pUnknown, rguid, &pComp, bThread);
+ if (FAILED(hr))
+ return hr;
+
+ VARIANT vari;
+ hr = pComp->GetValue(&vari);
+ pComp->Release();
+
+ return hr;
+}
+
+HRESULT
+SetCompartmentUnknown(
+ TfEditCookie cookie,
+ IUnknown *pUnknown,
+ REFGUID rguid,
+ IUnknown *pUnknown2)
+{
+ ITfCompartment *pComp = NULL;
+ HRESULT hr = GetCompartment(pUnknown, rguid, &pComp, FALSE);
+ if (FAILED(hr))
+ return hr;
+
+ VARIANT vari;
+ V_UNKNOWN(&vari) = pUnknown2;
+ V_VT(&vari) = VT_UNKNOWN;
+ hr = pComp->SetValue(cookie, &vari);
+ pComp->Release();
+
+ return hr;
+}
+
+HRESULT
+ClearCompartment(
+ TfClientId tid,
+ IUnknown *pUnknown,
+ REFGUID rguid,
+ BOOL bThread)
+{
+ ITfCompartmentMgr *pCompMgr = NULL;
+ ITfThreadMgr *pThreadMgr = NULL;
+
+ HRESULT hr;
+ if (bThread)
+ {
+ hr = pUnknown->QueryInterface(IID_ITfThreadMgr, (void **)&pThreadMgr);
+ if (FAILED(hr))
+ return hr;
+
+ hr = pThreadMgr->GetGlobalCompartment(&pCompMgr);
+ }
+ else
+ {
+ hr = pUnknown->QueryInterface(IID_ITfCompartmentMgr, (void **)&pCompMgr);
+ }
+
+ if (SUCCEEDED(hr))
+ {
+ hr = E_FAIL;
+ if (pCompMgr)
+ {
+ hr = pCompMgr->ClearCompartment(tid, rguid);
+ pCompMgr->Release();
+ }
+ }
+
+ if (pThreadMgr)
+ pThreadMgr->Release();
+
+ return hr;
+}
+
/* FIXME */
class CicInputContext : public ITfContextOwnerCompositionSink
{
@@ -2155,7 +2295,7 @@ VOID ProcessDetach(HINSTANCE hinstDLL)
}
/**
- * @unimplemented
+ * @implemented
*/
EXTERN_C BOOL WINAPI
DllMain(
@@ -2182,7 +2322,7 @@ DllMain(
}
case DLL_THREAD_DETACH:
{
- // FIXME
+ TF_DllDetachInOther();
CtfImeThreadDetach();
TLS::InternalDestroyTLS();
break;
diff --git a/dll/win32/msctf/msctf.spec b/dll/win32/msctf/msctf.spec
index 779ef12c79f..a38e8d7da2b 100644
--- a/dll/win32/msctf/msctf.spec
+++ b/dll/win32/msctf/msctf.spec
@@ -15,7 +15,7 @@
@ stdcall TF_CreateLangBarItemMgr(ptr)
@ stdcall TF_CreateLangBarMgr(ptr)
@ stdcall TF_CreateThreadMgr(ptr)
-@ stub TF_DllDetachInOther
+@ stdcall -stub TF_DllDetachInOther()
@ stdcall -stub TF_GetGlobalCompartment(ptr)
@ stub TF_GetInputScope
@ stub TF_GetLangIcon
diff --git a/sdk/include/psdk/msctf.idl b/sdk/include/psdk/msctf.idl
index ea487273a5b..4a4425f95fb 100644
--- a/sdk/include/psdk/msctf.idl
+++ b/sdk/include/psdk/msctf.idl
@@ -40,6 +40,7 @@ cpp_quote("EXTERN_C HRESULT WINAPI TF_CreateLangBarItemMgr(_Out_
ITfLangBarItemM
cpp_quote("EXTERN_C HANDLE WINAPI TF_CreateCicLoadMutex(_Out_ LPBOOL
pfWinLogon);")
cpp_quote("EXTERN_C HRESULT WINAPI TF_InvalidAssemblyListCache(VOID);")
cpp_quote("EXTERN_C HRESULT WINAPI TF_InvalidAssemblyListCacheIfExist(VOID);")
+cpp_quote("EXTERN_C HRESULT WINAPI TF_DllDetachInOther(VOID);")
cpp_quote("EXTERN_C const GUID GUID_PROP_TEXTOWNER;")
cpp_quote("EXTERN_C const GUID GUID_PROP_ATTRIBUTE;")