diff --git a/windows/syscall_windows.go b/windows/syscall_windows.go index e26da2bb4..1fa34fd17 100644 --- a/windows/syscall_windows.go +++ b/windows/syscall_windows.go @@ -213,8 +213,8 @@ func NewCallbackCDecl(fn interface{}) uintptr { //sys OpenProcess(desiredAccess uint32, inheritHandle bool, processId uint32) (handle Handle, err error) //sys ShellExecute(hwnd Handle, verb *uint16, file *uint16, args *uint16, cwd *uint16, showCmd int32) (err error) [failretval<=32] = shell32.ShellExecuteW //sys GetWindowThreadProcessId(hwnd HWND, pid *uint32) (tid uint32, err error) = user32.GetWindowThreadProcessId -//sys LoadKeyboardLayout(name *uint16, flags uint32) (hkl Handle) = user32.LoadKeyboardLayoutW -//sys UnloadKeyboardLayout(hkl Handle) (v bool) = user32.UnloadKeyboardLayout +//sys LoadKeyboardLayout(name *uint16, flags uint32) (hkl Handle, err error) [failretval==0] = user32.LoadKeyboardLayoutW +//sys UnloadKeyboardLayout(hkl Handle) (err error) = user32.UnloadKeyboardLayout //sys GetKeyboardLayout(tid uint32) (hkl Handle) = user32.GetKeyboardLayout //sys ToUnicodeEx(vkey uint32, scancode uint32, keystate *byte, pwszBuff *uint16, cchBuff int32, flags uint32, hkl Handle) (ret int32) = user32.ToUnicodeEx //sys GetShellWindow() (shellWindow HWND) = user32.GetShellWindow diff --git a/windows/syscall_windows_test.go b/windows/syscall_windows_test.go index 025e23538..cb80af62f 100644 --- a/windows/syscall_windows_test.go +++ b/windows/syscall_windows_test.go @@ -1289,11 +1289,18 @@ func TestGetKeyboardLayout(t *testing.T) { func TestToUnicodeEx(t *testing.T) { var utf16Buf [16]uint16 - ara, err := windows.UTF16PtrFromString("00000401") // ara layout 0x401 + + // Arabic (101) Keyboard Identifier + // See https://learn.microsoft.com/en-us/windows-hardware/manufacture/desktop/windows-language-pack-default-values + ara, err := windows.UTF16PtrFromString("00000401") if err != nil { t.Fatalf("UTF16PtrFromString failed: %v", err) } - araLayout := windows.LoadKeyboardLayout(ara, windows.KLF_ACTIVATE) + araLayout, err := windows.LoadKeyboardLayout(ara, windows.KLF_ACTIVATE) + if err != nil { + t.Fatalf("LoadKeyboardLayout failed: %v", err) + } + var keyState [256]byte ret := windows.ToUnicodeEx( 0x41, // 'A' vkCode @@ -1311,7 +1318,7 @@ func TestToUnicodeEx(t *testing.T) { if utf16Buf[0] != 'ش' { t.Errorf("ToUnicodeEx failed, wanted 'ش', got %q", utf16Buf[0]) } - if !windows.UnloadKeyboardLayout(araLayout) { - t.Errorf("UnloadKeyboardLayout failed") + if err := windows.UnloadKeyboardLayout(araLayout); err != nil { + t.Errorf("UnloadKeyboardLayout failed: %v", err) } } diff --git a/windows/zsyscall_windows.go b/windows/zsyscall_windows.go index 38cf9de2c..4f8448cc5 100644 --- a/windows/zsyscall_windows.go +++ b/windows/zsyscall_windows.go @@ -4116,9 +4116,12 @@ func IsWindowVisible(hwnd HWND) (isVisible bool) { return } -func LoadKeyboardLayout(name *uint16, flags uint32) (hkl Handle) { - r0, _, _ := syscall.Syscall(procLoadKeyboardLayoutW.Addr(), 2, uintptr(unsafe.Pointer(name)), uintptr(flags), 0) +func LoadKeyboardLayout(name *uint16, flags uint32) (hkl Handle, err error) { + r0, _, e1 := syscall.Syscall(procLoadKeyboardLayoutW.Addr(), 2, uintptr(unsafe.Pointer(name)), uintptr(flags), 0) hkl = Handle(r0) + if hkl == 0 { + err = errnoErr(e1) + } return } @@ -4137,9 +4140,11 @@ func ToUnicodeEx(vkey uint32, scancode uint32, keystate *byte, pwszBuff *uint16, return } -func UnloadKeyboardLayout(hkl Handle) (v bool) { - r0, _, _ := syscall.Syscall(procUnloadKeyboardLayout.Addr(), 1, uintptr(hkl), 0, 0) - v = r0 != 0 +func UnloadKeyboardLayout(hkl Handle) (err error) { + r1, _, e1 := syscall.Syscall(procUnloadKeyboardLayout.Addr(), 1, uintptr(hkl), 0, 0) + if r1 == 0 { + err = errnoErr(e1) + } return }