[IMM32] Rewrite ImmGetIMEFileNameA/W (#3822)

- Rewrite ImmGetIMEFileNameA and ImmGetIMEFileNameW functions. CORE-11700
This commit is contained in:
Katayama Hirofumi MZ 2021-07-15 23:01:50 +09:00 committed by GitHub
parent 3714ee269b
commit b06b628f30
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2195,32 +2195,31 @@ DWORD WINAPI ImmGetGuideLineW(HIMC hIMC, DWORD dwIndex, LPWSTR lpBuf, DWORD dwBu
*/ */
UINT WINAPI ImmGetIMEFileNameA( HKL hKL, LPSTR lpszFileName, UINT uBufLen) UINT WINAPI ImmGetIMEFileNameA( HKL hKL, LPSTR lpszFileName, UINT uBufLen)
{ {
LPWSTR bufW = NULL; BOOL bDefUsed;
UINT wBufLen = uBufLen; IMEINFOEX info;
UINT rc; size_t cch;
if (uBufLen && lpszFileName) TRACE("ImmGetIMEFileNameA(%p, %p, %u)\n", hKL, lpszFileName, uBufLen);
bufW = HeapAlloc(GetProcessHeap(),0,uBufLen * sizeof(WCHAR));
else /* We need this to get the number of byte required */ if (!ImmGetImeInfoEx(&info, ImeInfoExKeyboardLayout, &hKL) || !IS_IME_HKL(hKL))
{ {
bufW = HeapAlloc(GetProcessHeap(),0,MAX_PATH * sizeof(WCHAR)); if (uBufLen > 0)
wBufLen = MAX_PATH; lpszFileName[0] = 0;
return 0;
} }
rc = ImmGetIMEFileNameW(hKL,bufW,wBufLen); StringCchLengthW(info.wszImeFile, _countof(info.wszImeFile), &cch);
if (rc > 0) cch = WideCharToMultiByte(CP_ACP, 0, info.wszImeFile, (INT)cch,
{ lpszFileName, uBufLen, NULL, &bDefUsed);
if (uBufLen && lpszFileName) if (uBufLen == 0)
rc = WideCharToMultiByte(CP_ACP, 0, bufW, -1, lpszFileName, return (UINT)cch;
uBufLen, NULL, NULL);
else /* get the length */
rc = WideCharToMultiByte(CP_ACP, 0, bufW, -1, NULL, 0, NULL,
NULL);
}
HeapFree(GetProcessHeap(),0,bufW); if (cch > uBufLen - 1)
return rc; 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) UINT WINAPI ImmGetIMEFileNameW(HKL hKL, LPWSTR lpszFileName, UINT uBufLen)
{ {
HKEY hkey; IMEINFOEX info;
DWORD length; size_t cch;
DWORD rc;
WCHAR regKey[ARRAY_SIZE(szImeRegFmt)+8];
wsprintfW( regKey, szImeRegFmt, (ULONG_PTR)hKL ); TRACE("ImmGetIMEFileNameW(%p, %p, %u)\n", hKL, lpszFileName, uBufLen);
rc = RegOpenKeyW( HKEY_LOCAL_MACHINE, regKey, &hkey);
if (rc != ERROR_SUCCESS) if (!ImmGetImeInfoEx(&info, ImeInfoExKeyboardLayout, &hKL) || !IS_IME_HKL(hKL))
{ {
SetLastError(rc); if (uBufLen > 0)
lpszFileName[0] = 0;
return 0; return 0;
} }
length = 0; StringCchLengthW(info.wszImeFile, _countof(info.wszImeFile), &cch);
rc = RegGetValueW(hkey, NULL, szImeFileW, RRF_RT_REG_SZ, NULL, NULL, &length); if (uBufLen == 0)
return (UINT)cch;
if (rc != ERROR_SUCCESS) StringCchCopyNW(lpszFileName, uBufLen, info.wszImeFile, cch);
{
RegCloseKey(hkey);
SetLastError(rc);
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); if (cch > uBufLen - 1)
cch = uBufLen - 1;
RegCloseKey(hkey); lpszFileName[cch] = 0;
return (UINT)cch;
return length / sizeof(WCHAR);
} }
/*********************************************************************** /***********************************************************************