https://git.reactos.org/?p=reactos.git;a=commitdiff;h=7507a8f1922bcd87180a53eb0acb90af6a1249f7

commit 7507a8f1922bcd87180a53eb0acb90af6a1249f7
Author:     Katayama Hirofumi MZ <[email protected]>
AuthorDate: Wed Aug 4 07:32:13 2021 +0900
Commit:     GitHub <[email protected]>
CommitDate: Wed Aug 4 07:32:13 2021 +0900

    [IMM32] Rewrite ImmInstallIMEA (#3873)
    
    Implementing Japanese input... CORE-11700
---
 dll/win32/imm32/imm.c | 34 +++++++++++++++++++++++-----------
 1 file changed, 23 insertions(+), 11 deletions(-)

diff --git a/dll/win32/imm32/imm.c b/dll/win32/imm32/imm.c
index 9c7aa19ec4a..62f1569c354 100644
--- a/dll/win32/imm32/imm.c
+++ b/dll/win32/imm32/imm.c
@@ -2808,21 +2808,33 @@ UINT WINAPI ImmGetVirtualKey(HWND hWnd)
 HKL WINAPI ImmInstallIMEA(
   LPCSTR lpszIMEFileName, LPCSTR lpszLayoutText)
 {
-    LPWSTR lpszwIMEFileName;
-    LPWSTR lpszwLayoutText;
-    HKL hkl;
+    INT cchFileName, cchLayoutText;
+    LPWSTR pszFileNameW, pszLayoutTextW;
+    HKL hKL;
 
-    TRACE ("(%s, %s)\n", debugstr_a(lpszIMEFileName),
-                         debugstr_a(lpszLayoutText));
+    TRACE("(%s, %s)\n", debugstr_a(lpszIMEFileName), 
debugstr_a(lpszLayoutText));
 
-    lpszwIMEFileName = strdupAtoW(lpszIMEFileName);
-    lpszwLayoutText = strdupAtoW(lpszLayoutText);
+    cchFileName = lstrlenA(lpszIMEFileName) + 1;
+    cchLayoutText = lstrlenA(lpszLayoutText) + 1;
 
-    hkl = ImmInstallIMEW(lpszwIMEFileName, lpszwLayoutText);
+    pszFileNameW = Imm32HeapAlloc(0, cchFileName * sizeof(WCHAR));
+    if (pszFileNameW == NULL)
+        return NULL;
 
-    HeapFree(GetProcessHeap(),0,lpszwIMEFileName);
-    HeapFree(GetProcessHeap(),0,lpszwLayoutText);
-    return hkl;
+    pszLayoutTextW = Imm32HeapAlloc(0, cchLayoutText * sizeof(WCHAR));
+    if (pszLayoutTextW == NULL)
+    {
+        HeapFree(g_hImm32Heap, 0, pszFileNameW);
+        return NULL;
+    }
+
+    MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, lpszIMEFileName, -1, 
pszFileNameW, cchFileName);
+    MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, lpszLayoutText, -1, 
pszLayoutTextW, cchLayoutText);
+
+    hKL = ImmInstallIMEW(pszFileNameW, pszLayoutTextW);
+    HeapFree(g_hImm32Heap, 0, pszFileNameW);
+    HeapFree(g_hImm32Heap, 0, pszLayoutTextW);
+    return hKL;
 }
 
 /***********************************************************************

Reply via email to