mirror of
https://github.com/reactos/reactos.git
synced 2025-04-05 05:01:03 +00:00
[IMM32] Rewrite ImmGetIMEFileNameA/W (#3822)
- Rewrite ImmGetIMEFileNameA and ImmGetIMEFileNameW functions. CORE-11700
This commit is contained in:
parent
3714ee269b
commit
b06b628f30
1 changed files with 34 additions and 51 deletions
|
@ -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];
|
||||
IMEINFOEX info;
|
||||
size_t cch;
|
||||
|
||||
wsprintfW( regKey, szImeRegFmt, (ULONG_PTR)hKL );
|
||||
rc = RegOpenKeyW( HKEY_LOCAL_MACHINE, regKey, &hkey);
|
||||
if (rc != ERROR_SUCCESS)
|
||||
TRACE("ImmGetIMEFileNameW(%p, %p, %u)\n", hKL, lpszFileName, uBufLen);
|
||||
|
||||
if (!ImmGetImeInfoEx(&info, ImeInfoExKeyboardLayout, &hKL) || !IS_IME_HKL(hKL))
|
||||
{
|
||||
SetLastError(rc);
|
||||
if (uBufLen > 0)
|
||||
lpszFileName[0] = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
length = 0;
|
||||
rc = RegGetValueW(hkey, NULL, szImeFileW, RRF_RT_REG_SZ, NULL, NULL, &length);
|
||||
StringCchLengthW(info.wszImeFile, _countof(info.wszImeFile), &cch);
|
||||
if (uBufLen == 0)
|
||||
return (UINT)cch;
|
||||
|
||||
if (rc != ERROR_SUCCESS)
|
||||
{
|
||||
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);
|
||||
}
|
||||
StringCchCopyNW(lpszFileName, uBufLen, info.wszImeFile, cch);
|
||||
|
||||
RegGetValueW(hkey, NULL, szImeFileW, RRF_RT_REG_SZ, NULL, lpszFileName, &length);
|
||||
if (cch > uBufLen - 1)
|
||||
cch = uBufLen - 1;
|
||||
|
||||
RegCloseKey(hkey);
|
||||
|
||||
return length / sizeof(WCHAR);
|
||||
lpszFileName[cch] = 0;
|
||||
return (UINT)cch;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
|
|
Loading…
Reference in a new issue