internal/gamepad: fix SetWindowLongPtrW crash on 32-bit Windows (#1999)

Closes #1998
This commit is contained in:
divVerent 2022-02-23 09:18:20 -05:00 committed by GitHub
parent cc1fd437a1
commit 476f4e3f9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -146,7 +146,9 @@ var (
procGetActiveWindow = user32.NewProc("GetActiveWindow") procGetActiveWindow = user32.NewProc("GetActiveWindow")
procGetRawInputDeviceInfoW = user32.NewProc("GetRawInputDeviceInfoW") procGetRawInputDeviceInfoW = user32.NewProc("GetRawInputDeviceInfoW")
procGetRawInputDeviceList = user32.NewProc("GetRawInputDeviceList") procGetRawInputDeviceList = user32.NewProc("GetRawInputDeviceList")
procSetWindowLongPtrW = user32.NewProc("SetWindowLongPtrW")
procSetWindowLongW = user32.NewProc("SetWindowLongW") // 32-Bit Windows version.
procSetWindowLongPtrW = user32.NewProc("SetWindowLongPtrW") // 64-Bit Windows version.
) )
func getCurrentThreadId() uint32 { func getCurrentThreadId() uint32 {
@ -198,7 +200,15 @@ func getRawInputDeviceList(pRawInputDeviceList *_RAWINPUTDEVICELIST, puiNumDevic
} }
func setWindowLongPtrW(hWnd uintptr, nIndex int32, dwNewLong uintptr) (uintptr, error) { func setWindowLongPtrW(hWnd uintptr, nIndex int32, dwNewLong uintptr) (uintptr, error) {
h, _, e := procSetWindowLongPtrW.Call(hWnd, uintptr(nIndex), dwNewLong) var p *windows.LazyProc
if procSetWindowLongPtrW.Find() == nil {
// 64-Bit Windows.
p = procSetWindowLongPtrW
} else {
// 32-Bit Windows.
p = procSetWindowLongW
}
h, _, e := p.Call(hWnd, uintptr(nIndex), dwNewLong)
if h == 0 { if h == 0 {
if e != nil && e != windows.ERROR_SUCCESS { if e != nil && e != windows.ERROR_SUCCESS {
return 0, fmt.Errorf("gamepad: SetWindowLongPtrW failed: %w", e) return 0, fmt.Errorf("gamepad: SetWindowLongPtrW failed: %w", e)