https://git.reactos.org/?p=reactos.git;a=commitdiff;h=b06b628f30e2bf616991e…
commit b06b628f30e2bf616991e00b9cad13f0228b29fb
Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Thu Jul 15 23:01:50 2021 +0900
Commit: GitHub <noreply(a)github.com>
CommitDate: Thu Jul 15 23:01:50 2021 +0900
[IMM32] Rewrite ImmGetIMEFileNameA/W (#3822)
- Rewrite ImmGetIMEFileNameA and ImmGetIMEFileNameW functions. CORE-11700
---
dll/win32/imm32/imm.c | 85 +++++++++++++++++++++------------------------------
1 file changed, 34 insertions(+), 51 deletions(-)
diff --git a/dll/win32/imm32/imm.c b/dll/win32/imm32/imm.c
index 4bcc133ae66..8c40da91928 100644
--- a/dll/win32/imm32/imm.c
+++ b/dll/win32/imm32/imm.c
@@ -2195,32 +2195,31 @@ DWORD WINAPI ImmGetGuideLineW(HIMC hIMC, DWORD dwIndex, LPWSTR
lpBuf, DWORD dwBu
*/
UINT WINAPI ImmGetIMEFileNameA( HKL hKL, LPSTR lpszFileName, UINT uBufLen)
{
- LPWSTR bufW = NULL;
- UINT wBufLen = uBufLen;
- UINT rc;
+ BOOL bDefUsed;
+ IMEINFOEX info;
+ size_t cch;
- if (uBufLen && lpszFileName)
- bufW = HeapAlloc(GetProcessHeap(),0,uBufLen * sizeof(WCHAR));
- else /* We need this to get the number of byte required */
+ TRACE("ImmGetIMEFileNameA(%p, %p, %u)\n", hKL, lpszFileName, uBufLen);
+
+ if (!ImmGetImeInfoEx(&info, ImeInfoExKeyboardLayout, &hKL) ||
!IS_IME_HKL(hKL))
{
- bufW = HeapAlloc(GetProcessHeap(),0,MAX_PATH * sizeof(WCHAR));
- wBufLen = MAX_PATH;
+ if (uBufLen > 0)
+ lpszFileName[0] = 0;
+ return 0;
}
- rc = ImmGetIMEFileNameW(hKL,bufW,wBufLen);
+ StringCchLengthW(info.wszImeFile, _countof(info.wszImeFile), &cch);
- if (rc > 0)
- {
- if (uBufLen && lpszFileName)
- rc = WideCharToMultiByte(CP_ACP, 0, bufW, -1, lpszFileName,
- uBufLen, NULL, NULL);
- else /* get the length */
- rc = WideCharToMultiByte(CP_ACP, 0, bufW, -1, NULL, 0, NULL,
- NULL);
- }
+ cch = WideCharToMultiByte(CP_ACP, 0, info.wszImeFile, (INT)cch,
+ lpszFileName, uBufLen, NULL, &bDefUsed);
+ if (uBufLen == 0)
+ return (UINT)cch;
- HeapFree(GetProcessHeap(),0,bufW);
- return rc;
+ if (cch > uBufLen - 1)
+ cch = uBufLen - 1;
+
+ lpszFileName[cch] = 0;
+ return (UINT)cch;
}
/***********************************************************************
@@ -2228,45 +2227,29 @@ UINT WINAPI ImmGetIMEFileNameA( HKL hKL, LPSTR lpszFileName, UINT
uBufLen)
*/
UINT WINAPI ImmGetIMEFileNameW(HKL hKL, LPWSTR lpszFileName, UINT uBufLen)
{
- HKEY hkey;
- DWORD length;
- DWORD rc;
- WCHAR regKey[ARRAY_SIZE(szImeRegFmt)+8];
-
- wsprintfW( regKey, szImeRegFmt, (ULONG_PTR)hKL );
- rc = RegOpenKeyW( HKEY_LOCAL_MACHINE, regKey, &hkey);
- if (rc != ERROR_SUCCESS)
- {
- SetLastError(rc);
- return 0;
- }
+ IMEINFOEX info;
+ size_t cch;
- length = 0;
- rc = RegGetValueW(hkey, NULL, szImeFileW, RRF_RT_REG_SZ, NULL, NULL, &length);
+ TRACE("ImmGetIMEFileNameW(%p, %p, %u)\n", hKL, lpszFileName, uBufLen);
- if (rc != ERROR_SUCCESS)
+ if (!ImmGetImeInfoEx(&info, ImeInfoExKeyboardLayout, &hKL) ||
!IS_IME_HKL(hKL))
{
- RegCloseKey(hkey);
- SetLastError(rc);
+ if (uBufLen > 0)
+ lpszFileName[0] = 0;
return 0;
}
- if (length > uBufLen * sizeof(WCHAR) || !lpszFileName)
- {
- RegCloseKey(hkey);
- if (lpszFileName)
- {
- SetLastError(ERROR_INSUFFICIENT_BUFFER);
- return 0;
- }
- else
- return length / sizeof(WCHAR);
- }
- RegGetValueW(hkey, NULL, szImeFileW, RRF_RT_REG_SZ, NULL, lpszFileName,
&length);
+ StringCchLengthW(info.wszImeFile, _countof(info.wszImeFile), &cch);
+ if (uBufLen == 0)
+ return (UINT)cch;
+
+ StringCchCopyNW(lpszFileName, uBufLen, info.wszImeFile, cch);
- RegCloseKey(hkey);
+ if (cch > uBufLen - 1)
+ cch = uBufLen - 1;
- return length / sizeof(WCHAR);
+ lpszFileName[cch] = 0;
+ return (UINT)cch;
}
/***********************************************************************