Skip to content

Commit 2afe997

Browse files
committed
windows: return error on LoadKeyboardLayout/UnloadKeyboardLayout
1 parent fc5dda0 commit 2afe997

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

windows/syscall_windows.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ func NewCallbackCDecl(fn interface{}) uintptr {
213213
//sys OpenProcess(desiredAccess uint32, inheritHandle bool, processId uint32) (handle Handle, err error)
214214
//sys ShellExecute(hwnd Handle, verb *uint16, file *uint16, args *uint16, cwd *uint16, showCmd int32) (err error) [failretval<=32] = shell32.ShellExecuteW
215215
//sys GetWindowThreadProcessId(hwnd HWND, pid *uint32) (tid uint32, err error) = user32.GetWindowThreadProcessId
216-
//sys LoadKeyboardLayout(name *uint16, flags uint32) (hkl Handle) = user32.LoadKeyboardLayoutW
217-
//sys UnloadKeyboardLayout(hkl Handle) (v bool) = user32.UnloadKeyboardLayout
216+
//sys LoadKeyboardLayout(name *uint16, flags uint32) (hkl Handle, err error) [failretval==0] = user32.LoadKeyboardLayoutW
217+
//sys UnloadKeyboardLayout(hkl Handle) (err error) = user32.UnloadKeyboardLayout
218218
//sys GetKeyboardLayout(tid uint32) (hkl Handle) = user32.GetKeyboardLayout
219219
//sys ToUnicodeEx(vkey uint32, scancode uint32, keystate *byte, pwszBuff *uint16, cchBuff int32, flags uint32, hkl Handle) (ret int32) = user32.ToUnicodeEx
220220
//sys GetShellWindow() (shellWindow HWND) = user32.GetShellWindow

windows/syscall_windows_test.go

+11-4
Original file line numberDiff line numberDiff line change
@@ -1289,11 +1289,18 @@ func TestGetKeyboardLayout(t *testing.T) {
12891289

12901290
func TestToUnicodeEx(t *testing.T) {
12911291
var utf16Buf [16]uint16
1292-
ara, err := windows.UTF16PtrFromString("00000401") // ara layout 0x401
1292+
1293+
// Arabic (101) Keyboard Identifier
1294+
// See https://learn.microsoft.com/en-us/windows-hardware/manufacture/desktop/windows-language-pack-default-values
1295+
ara, err := windows.UTF16PtrFromString("00000401")
12931296
if err != nil {
12941297
t.Fatalf("UTF16PtrFromString failed: %v", err)
12951298
}
1296-
araLayout := windows.LoadKeyboardLayout(ara, windows.KLF_ACTIVATE)
1299+
araLayout, err := windows.LoadKeyboardLayout(ara, windows.KLF_ACTIVATE)
1300+
if err != nil {
1301+
t.Fatalf("LoadKeyboardLayout failed: %v", err)
1302+
}
1303+
12971304
var keyState [256]byte
12981305
ret := windows.ToUnicodeEx(
12991306
0x41, // 'A' vkCode
@@ -1311,7 +1318,7 @@ func TestToUnicodeEx(t *testing.T) {
13111318
if utf16Buf[0] != 'ش' {
13121319
t.Errorf("ToUnicodeEx failed, wanted 'ش', got %q", utf16Buf[0])
13131320
}
1314-
if !windows.UnloadKeyboardLayout(araLayout) {
1315-
t.Errorf("UnloadKeyboardLayout failed")
1321+
if err := windows.UnloadKeyboardLayout(araLayout); err != nil {
1322+
t.Errorf("UnloadKeyboardLayout failed: %v", err)
13161323
}
13171324
}

windows/zsyscall_windows.go

+10-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)