Skip to content

Commit

Permalink
windows: return error on LoadKeyboardLayout/UnloadKeyboardLayout
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Jul 14, 2024
1 parent fc5dda0 commit 2afe997
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
4 changes: 2 additions & 2 deletions windows/syscall_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 11 additions & 4 deletions windows/syscall_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
}
15 changes: 10 additions & 5 deletions windows/zsyscall_windows.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2afe997

Please sign in to comment.