[CTFMON][MSCTFIME][SDK] Renaming for Cicero (#6216)

Keep consistency with Cicero naming rule.
- s/CModulePath/CicSystemModulePath/.
- s/GetOSInfo/cicGetOSInfo/.
- s/IsWow64/cicIsWow64/.
- s/GetSystemModuleHandle/cicGetSystemModuleHandle/.
- s/LoadSystemLibrary/cicLoadSystemLibrary/.
- Move cicGetOSInfo and cicIsWow64
  to <cicero/cicbase.h>.
- Delete some Cicero headers.
- Adapt ctfmon and msctfime to
  these changes.
CORE-19360
This commit is contained in:
Katayama Hirofumi MZ 2023-12-21 19:05:33 +09:00 committed by GitHub
parent 814cb188c6
commit 7d6fc57ec9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 166 additions and 181 deletions

View file

@ -138,7 +138,7 @@ CRegWatcher::UpdateSpTip()
} }
// Get %WINDIR%/IME/sptip.dll!TF_CreateLangProfileUtil function // Get %WINDIR%/IME/sptip.dll!TF_CreateLangProfileUtil function
HINSTANCE hSPTIP = LoadSystemLibrary(L"IME\\sptip.dll", TRUE); HINSTANCE hSPTIP = cicLoadSystemLibrary(L"IME\\sptip.dll", TRUE);
FN_TF_CreateLangProfileUtil fnTF_CreateLangProfileUtil = FN_TF_CreateLangProfileUtil fnTF_CreateLangProfileUtil =
(FN_TF_CreateLangProfileUtil)::GetProcAddress(hSPTIP, "TF_CreateLangProfileUtil"); (FN_TF_CreateLangProfileUtil)::GetProcAddress(hSPTIP, "TF_CreateLangProfileUtil");
if (fnTF_CreateLangProfileUtil) if (fnTF_CreateLangProfileUtil)

View file

@ -9,10 +9,6 @@
#include "CRegWatcher.h" #include "CRegWatcher.h"
#include "CLoaderWnd.h" #include "CLoaderWnd.h"
// ntdll!NtQueryInformationProcess
typedef NTSTATUS (WINAPI *FN_NtQueryInformationProcess)(HANDLE, PROCESSINFOCLASS, PVOID, ULONG, PULONG);
FN_NtQueryInformationProcess g_fnNtQueryInformationProcess = NULL;
// kernel32!SetProcessShutdownParameters // kernel32!SetProcessShutdownParameters
typedef BOOL (WINAPI *FN_SetProcessShutdownParameters)(DWORD, DWORD); typedef BOOL (WINAPI *FN_SetProcessShutdownParameters)(DWORD, DWORD);
FN_SetProcessShutdownParameters g_fnSetProcessShutdownParameters = NULL; FN_SetProcessShutdownParameters g_fnSetProcessShutdownParameters = NULL;
@ -29,31 +25,9 @@ HANDLE g_hCicMutex = NULL; // The Cicero mutex
BOOL g_bOnWow64 = FALSE; // Is the app running on WoW64? BOOL g_bOnWow64 = FALSE; // Is the app running on WoW64?
BOOL g_fNoRunKey = FALSE; // Don't write registry key "Run"? BOOL g_fNoRunKey = FALSE; // Don't write registry key "Run"?
BOOL g_fJustRunKey = FALSE; // Just write registry key "Run"? BOOL g_fJustRunKey = FALSE; // Just write registry key "Run"?
DWORD g_dwOsInfo = 0; // The OS version info. See GetOSInfo DWORD g_dwOsInfo = 0; // The OS version info. See cicGetOSInfo
CLoaderWnd* g_pLoaderWnd = NULL; // TIP Bar loader window CLoaderWnd* g_pLoaderWnd = NULL; // TIP Bar loader window
// Is the current process on WoW64?
static BOOL
IsWow64(VOID)
{
HMODULE hNTDLL = GetSystemModuleHandle(L"ntdll.dll", FALSE);
if (!hNTDLL)
return FALSE;
g_fnNtQueryInformationProcess =
(FN_NtQueryInformationProcess)::GetProcAddress(hNTDLL, "NtQueryInformationProcess");
if (!g_fnNtQueryInformationProcess)
return FALSE;
ULONG_PTR Value = 0;
NTSTATUS Status = g_fnNtQueryInformationProcess(::GetCurrentProcess(), ProcessWow64Information,
&Value, sizeof(Value), NULL);
if (!NT_SUCCESS(Status))
return FALSE;
return !!Value;
}
static VOID static VOID
ParseCommandLine( ParseCommandLine(
_In_ LPCWSTR pszCmdLine) _In_ LPCWSTR pszCmdLine)
@ -107,7 +81,7 @@ WriteRegRun(VOID)
return; return;
// Write the module path // Write the module path
CModulePath ModPath; CicSystemModulePath ModPath;
if (ModPath.Init(L"ctfmon.exe", FALSE)) if (ModPath.Init(L"ctfmon.exe", FALSE))
{ {
DWORD cbData = (ModPath.m_cchPath + 1) * sizeof(WCHAR); DWORD cbData = (ModPath.m_cchPath + 1) * sizeof(WCHAR);
@ -172,7 +146,7 @@ CheckX64System(
} }
// Get GetSystemWow64DirectoryW function // Get GetSystemWow64DirectoryW function
g_hKernel32 = GetSystemModuleHandle(L"kernel32.dll", FALSE); g_hKernel32 = cicGetSystemModuleHandle(L"kernel32.dll", FALSE);
g_fnGetSystemWow64DirectoryW = g_fnGetSystemWow64DirectoryW =
(FN_GetSystemWow64DirectoryW)::GetProcAddress(g_hKernel32, "GetSystemWow64DirectoryW"); (FN_GetSystemWow64DirectoryW)::GetProcAddress(g_hKernel32, "GetSystemWow64DirectoryW");
if (!g_fnGetSystemWow64DirectoryW) if (!g_fnGetSystemWow64DirectoryW)
@ -204,8 +178,8 @@ InitApp(
g_hInst = hInstance; // Save the instance handle g_hInst = hInstance; // Save the instance handle
g_uACP = ::GetACP(); // Save the active codepage g_uACP = ::GetACP(); // Save the active codepage
g_bOnWow64 = IsWow64(); // Is the current process on WoW64? g_bOnWow64 = cicIsWow64(); // Is the current process on WoW64?
g_dwOsInfo = GetOSInfo(); // Get OS info g_dwOsInfo = cicGetOSInfo(); // Get OS info
// Create a mutex for Cicero // Create a mutex for Cicero
g_hCicMutex = TF_CreateCicLoadMutex(&g_fWinLogon); g_hCicMutex = TF_CreateCicLoadMutex(&g_fWinLogon);
@ -218,7 +192,7 @@ InitApp(
// Call SetProcessShutdownParameters if possible // Call SetProcessShutdownParameters if possible
if (g_dwOsInfo & OSINFO_NT) if (g_dwOsInfo & OSINFO_NT)
{ {
g_hKernel32 = GetSystemModuleHandle(L"kernel32.dll", FALSE); g_hKernel32 = cicGetSystemModuleHandle(L"kernel32.dll", FALSE);
g_fnSetProcessShutdownParameters = g_fnSetProcessShutdownParameters =
(FN_SetProcessShutdownParameters) (FN_SetProcessShutdownParameters)
::GetProcAddress(g_hKernel32, "SetProcessShutdownParameters"); ::GetProcAddress(g_hKernel32, "SetProcessShutdownParameters");

View file

@ -9,7 +9,6 @@
#define WIN32_NO_STATUS #define WIN32_NO_STATUS
#include <windows.h> #include <windows.h>
#include <ndk/pstypes.h>
#include <shellapi.h> #include <shellapi.h>
#include <shlwapi.h> #include <shlwapi.h>
#include <stdlib.h> #include <stdlib.h>
@ -17,10 +16,7 @@
#include <msctf.h> #include <msctf.h>
#include <ctfutb.h> #include <ctfutb.h>
#include <ctffunc.h> #include <ctffunc.h>
#include <cicero/cicbase.h> #include <cicero/cicbase.h>
#include <cicero/osinfo.h>
#include <cicero/CModulePath.h>
#include "resource.h" #include "resource.h"

View file

@ -88,7 +88,7 @@ DllShutDownInProgress(VOID)
if (s_fnDllShutDownInProgress) if (s_fnDllShutDownInProgress)
return s_fnDllShutDownInProgress(); return s_fnDllShutDownInProgress();
hNTDLL = GetSystemModuleHandle(L"ntdll.dll", FALSE); hNTDLL = cicGetSystemModuleHandle(L"ntdll.dll", FALSE);
s_fnDllShutDownInProgress = s_fnDllShutDownInProgress =
(FN_DllShutDownInProgress)GetProcAddress(hNTDLL, "RtlDllShutdownInProgress"); (FN_DllShutDownInProgress)GetProcAddress(hNTDLL, "RtlDllShutdownInProgress");
if (!s_fnDllShutDownInProgress) if (!s_fnDllShutDownInProgress)
@ -2841,7 +2841,7 @@ BOOL ProcessAttach(HINSTANCE hinstDLL)
if (!TLS::Initialize()) if (!TLS::Initialize())
return FALSE; return FALSE;
g_dwOSInfo = GetOSInfo(); g_dwOSInfo = cicGetOSInfo();
// FIXME // FIXME

View file

@ -24,9 +24,7 @@
#include <cicero/cicbase.h> #include <cicero/cicbase.h>
#include <cicero/cicarray.h> #include <cicero/cicarray.h>
#include <cicero/osinfo.h> #include <cicero/cicimc.h>
#include <cicero/CModulePath.h>
#include <cicero/imclock.h>
class CicInputContext; class CicInputContext;

View file

@ -1,90 +0,0 @@
/*
* PROJECT: ReactOS Cicero
* LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
* PURPOSE: Manipulate module path
* COPYRIGHT: Copyright 2023 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
*/
#pragma once
struct CModulePath
{
WCHAR m_szPath[MAX_PATH];
SIZE_T m_cchPath;
CModulePath()
{
m_szPath[0] = UNICODE_NULL;
m_cchPath = 0;
}
BOOL Init(_In_ LPCWSTR pszFileName, _In_ BOOL bSysWinDir);
};
// Get an instance handle that is already loaded
static inline HINSTANCE
GetSystemModuleHandle(
_In_ LPCWSTR pszFileName,
_In_ BOOL bSysWinDir)
{
CModulePath ModPath;
if (!ModPath.Init(pszFileName, bSysWinDir))
return NULL;
return GetModuleHandleW(ModPath.m_szPath);
}
// Load a system library
static inline HINSTANCE
LoadSystemLibrary(
_In_ LPCWSTR pszFileName,
_In_ BOOL bSysWinDir)
{
CModulePath ModPath;
if (!ModPath.Init(pszFileName, bSysWinDir))
return NULL;
return ::LoadLibraryW(ModPath.m_szPath);
}
/******************************************************************************/
inline BOOL
CModulePath::Init(
_In_ LPCWSTR pszFileName,
_In_ BOOL bSysWinDir)
{
SIZE_T cchPath;
if (bSysWinDir)
{
// Usually C:\Windows or C:\ReactOS
cchPath = ::GetSystemWindowsDirectory(m_szPath, _countof(m_szPath));
}
else
{
// Usually C:\Windows\system32 or C:\ReactOS\system32
cchPath = ::GetSystemDirectoryW(m_szPath, _countof(m_szPath));
}
m_szPath[_countof(m_szPath) - 1] = UNICODE_NULL; // Avoid buffer overrun
if ((cchPath == 0) || (cchPath > _countof(m_szPath) - 2))
goto Failure;
// Add backslash if necessary
if ((cchPath > 0) && (m_szPath[cchPath - 1] != L'\\'))
{
m_szPath[cchPath + 0] = L'\\';
m_szPath[cchPath + 1] = UNICODE_NULL;
}
// Append pszFileName
if (FAILED(StringCchCatW(m_szPath, _countof(m_szPath), pszFileName)))
goto Failure;
m_cchPath = wcslen(m_szPath);
return TRUE;
Failure:
m_szPath[0] = UNICODE_NULL;
m_cchPath = 0;
return FALSE;
}

View file

@ -7,6 +7,10 @@
#pragma once #pragma once
#ifndef __cplusplus
#error Cicero needs C++.
#endif
static inline LPVOID cicMemAlloc(SIZE_T size) static inline LPVOID cicMemAlloc(SIZE_T size)
{ {
return LocalAlloc(0, size); return LocalAlloc(0, size);
@ -30,7 +34,6 @@ static inline void cicMemFree(LPVOID ptr)
LocalFree(ptr); LocalFree(ptr);
} }
#ifdef __cplusplus
inline void* __cdecl operator new(size_t size) noexcept inline void* __cdecl operator new(size_t size) noexcept
{ {
return cicMemAllocClear(size); return cicMemAllocClear(size);
@ -45,7 +48,6 @@ inline void __cdecl operator delete(void* ptr, size_t size) noexcept
{ {
cicMemFree(ptr); cicMemFree(ptr);
} }
#endif // __cplusplus
// FIXME: Use msutb.dll and header // FIXME: Use msutb.dll and header
static inline void ClosePopupTipbar(void) static inline void ClosePopupTipbar(void)
@ -56,3 +58,155 @@ static inline void ClosePopupTipbar(void)
static inline void GetPopupTipbar(HWND hwnd, BOOL fWinLogon) static inline void GetPopupTipbar(HWND hwnd, BOOL fWinLogon)
{ {
} }
/* The flags of cicGetOSInfo() */
#define OSINFO_NT 0x01
#define OSINFO_CJK 0x10
#define OSINFO_IMM 0x20
#define OSINFO_DBCS 0x40
static inline DWORD
cicGetOSInfo(VOID)
{
DWORD dwOsInfo = 0;
/* Check OS version info */
OSVERSIONINFOW VerInfo = { sizeof(VerInfo) };
GetVersionExW(&VerInfo);
if (VerInfo.dwPlatformId == DLLVER_PLATFORM_NT)
dwOsInfo |= OSINFO_NT;
/* Check codepage */
switch (GetACP())
{
case 932: /* Japanese (Japan) */
case 936: /* Chinese (PRC, Singapore) */
case 949: /* Korean (Korea) */
case 950: /* Chinese (Taiwan, Hong Kong) */
dwOsInfo |= OSINFO_CJK;
break;
}
if (GetSystemMetrics(SM_IMMENABLED))
dwOsInfo |= OSINFO_IMM;
if (GetSystemMetrics(SM_DBCSENABLED))
dwOsInfo |= OSINFO_DBCS;
/* I'm not interested in other flags */
return dwOsInfo;
}
struct CicSystemModulePath
{
WCHAR m_szPath[MAX_PATH];
SIZE_T m_cchPath;
CicSystemModulePath()
{
m_szPath[0] = UNICODE_NULL;
m_cchPath = 0;
}
BOOL Init(_In_ LPCWSTR pszFileName, _In_ BOOL bSysWinDir);
};
// Get an instance handle that is already loaded
static inline HINSTANCE
cicGetSystemModuleHandle(
_In_ LPCWSTR pszFileName,
_In_ BOOL bSysWinDir)
{
CicSystemModulePath ModPath;
if (!ModPath.Init(pszFileName, bSysWinDir))
return NULL;
return GetModuleHandleW(ModPath.m_szPath);
}
// Load a system library
static inline HINSTANCE
cicLoadSystemLibrary(
_In_ LPCWSTR pszFileName,
_In_ BOOL bSysWinDir)
{
CicSystemModulePath ModPath;
if (!ModPath.Init(pszFileName, bSysWinDir))
return NULL;
return ::LoadLibraryW(ModPath.m_szPath);
}
#include <ndk/pstypes.h> /* for PROCESSINFOCLASS */
/* ntdll!NtQueryInformationProcess */
typedef NTSTATUS (WINAPI *FN_NtQueryInformationProcess)(HANDLE, PROCESSINFOCLASS, PVOID, ULONG, PULONG);
/* Is the current process on WoW64? */
static inline BOOL cicIsWow64(VOID)
{
static FN_NtQueryInformationProcess s_fnNtQueryInformationProcess = NULL;
ULONG_PTR Value;
NTSTATUS Status;
if (!s_fnNtQueryInformationProcess)
{
HMODULE hNTDLL = cicGetSystemModuleHandle(L"ntdll.dll", FALSE);
if (!hNTDLL)
return FALSE;
s_fnNtQueryInformationProcess =
(FN_NtQueryInformationProcess)GetProcAddress(hNTDLL, "NtQueryInformationProcess");
if (!s_fnNtQueryInformationProcess)
return FALSE;
}
Value = 0;
Status = s_fnNtQueryInformationProcess(GetCurrentProcess(), ProcessWow64Information,
&Value, sizeof(Value), NULL);
if (!NT_SUCCESS(Status))
return FALSE;
return !!Value;
}
inline BOOL
CicSystemModulePath::Init(
_In_ LPCWSTR pszFileName,
_In_ BOOL bSysWinDir)
{
SIZE_T cchPath;
if (bSysWinDir)
{
// Usually C:\Windows or C:\ReactOS
cchPath = ::GetSystemWindowsDirectory(m_szPath, _countof(m_szPath));
}
else
{
// Usually C:\Windows\system32 or C:\ReactOS\system32
cchPath = ::GetSystemDirectoryW(m_szPath, _countof(m_szPath));
}
m_szPath[_countof(m_szPath) - 1] = UNICODE_NULL; // Avoid buffer overrun
if ((cchPath == 0) || (cchPath > _countof(m_szPath) - 2))
goto Failure;
// Add backslash if necessary
if ((cchPath > 0) && (m_szPath[cchPath - 1] != L'\\'))
{
m_szPath[cchPath + 0] = L'\\';
m_szPath[cchPath + 1] = UNICODE_NULL;
}
// Append pszFileName
if (FAILED(StringCchCatW(m_szPath, _countof(m_szPath), pszFileName)))
goto Failure;
m_cchPath = wcslen(m_szPath);
return TRUE;
Failure:
m_szPath[0] = UNICODE_NULL;
m_cchPath = 0;
return FALSE;
}

View file

@ -1,47 +0,0 @@
/*
* PROJECT: ReactOS Cicero
* LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
* PURPOSE: Getting OS information
* COPYRIGHT: Copyright 2023 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
*/
#pragma once
/* The flags of GetOSInfo() */
#define OSINFO_NT 0x01
#define OSINFO_CJK 0x10
#define OSINFO_IMM 0x20
#define OSINFO_DBCS 0x40
static inline DWORD
GetOSInfo(VOID)
{
DWORD dwOsInfo = 0;
/* Check OS version info */
OSVERSIONINFOW VerInfo = { sizeof(VerInfo) };
GetVersionExW(&VerInfo);
if (VerInfo.dwPlatformId == DLLVER_PLATFORM_NT)
dwOsInfo |= OSINFO_NT;
/* Check codepage */
switch (GetACP())
{
case 932: /* Japanese (Japan) */
case 936: /* Chinese (PRC, Singapore) */
case 949: /* Korean (Korea) */
case 950: /* Chinese (Taiwan, Hong Kong) */
dwOsInfo |= OSINFO_CJK;
break;
}
if (GetSystemMetrics(SM_IMMENABLED))
dwOsInfo |= OSINFO_IMM;
if (GetSystemMetrics(SM_DBCSENABLED))
dwOsInfo |= OSINFO_DBCS;
/* I'm not interested in other flags */
return dwOsInfo;
}