diff --git a/internal/glfwwin/api_windows.go b/internal/glfwwin/api_windows.go index 7fa869cfa..cdac582be 100644 --- a/internal/glfwwin/api_windows.go +++ b/internal/glfwwin/api_windows.go @@ -1181,6 +1181,10 @@ func _EnumDisplayDevicesW(device string, iDevNum uint32, dwFlags uint32) (_DISPL return displayDevice, true } +func _EnumDisplayDevicesW_Available() bool { + return procEnumDisplayDevicesW.Find() == nil +} + func _EnumDisplayMonitors(hdc _HDC, lprcClip *_RECT, lpfnEnum uintptr, dwData _LPARAM) error { r, _, e := procEnumDisplayMonitors.Call(uintptr(hdc), uintptr(unsafe.Pointer(lprcClip)), uintptr(lpfnEnum), uintptr(dwData)) if int32(r) == 0 { @@ -1533,6 +1537,10 @@ func _RegisterDeviceNotificationW(hRecipient windows.Handle, notificationFilter return _HDEVNOTIFY(r), nil } +func _RegisterDeviceNotificationW_Available() bool { + return procRegisterDeviceNotificationW.Find() == nil +} + func _RegisterRawInputDevices(pRawInputDevices []_RAWINPUTDEVICE) error { r, _, e := procRegisterRawInputDevices.Call(uintptr(unsafe.Pointer(&pRawInputDevices[0])), uintptr(len(pRawInputDevices)), unsafe.Sizeof(pRawInputDevices[0])) if int32(r) == 0 { diff --git a/internal/glfwwin/win32init_windows.go b/internal/glfwwin/win32init_windows.go index 78d5e9d17..af6c46d31 100644 --- a/internal/glfwwin/win32init_windows.go +++ b/internal/glfwwin/win32init_windows.go @@ -185,23 +185,25 @@ func createHelperWindow() error { // process passed along a STARTUPINFO, so clear that with a no-op call _ShowWindow(_glfw.win32.helperWindowHandle, _SW_HIDE) - _GUID_DEVINTERFACE_HID := windows.GUID{ - Data1: 0x4d1e55b2, - Data2: 0xf16f, - Data3: 0x11cf, - Data4: [...]byte{0x88, 0xcb, 0x00, 0x11, 0x11, 0x00, 0x00, 0x30}, - } - // Register for HID device notifications - var dbi _DEV_BROADCAST_DEVICEINTERFACE_W - dbi.dbcc_size = uint32(unsafe.Sizeof(dbi)) - dbi.dbcc_devicetype = _DBT_DEVTYP_DEVICEINTERFACE - dbi.dbcc_classguid = _GUID_DEVINTERFACE_HID - notify, err := _RegisterDeviceNotificationW(windows.Handle(_glfw.win32.helperWindowHandle), unsafe.Pointer(&dbi), _DEVICE_NOTIFY_WINDOW_HANDLE) - if err != nil { - return err + if _RegisterDeviceNotificationW_Available() { + _GUID_DEVINTERFACE_HID := windows.GUID{ + Data1: 0x4d1e55b2, + Data2: 0xf16f, + Data3: 0x11cf, + Data4: [...]byte{0x88, 0xcb, 0x00, 0x11, 0x11, 0x00, 0x00, 0x30}, + } + + var dbi _DEV_BROADCAST_DEVICEINTERFACE_W + dbi.dbcc_size = uint32(unsafe.Sizeof(dbi)) + dbi.dbcc_devicetype = _DBT_DEVTYP_DEVICEINTERFACE + dbi.dbcc_classguid = _GUID_DEVINTERFACE_HID + notify, err := _RegisterDeviceNotificationW(windows.Handle(_glfw.win32.helperWindowHandle), unsafe.Pointer(&dbi), _DEVICE_NOTIFY_WINDOW_HANDLE) + if err != nil { + return err + } + _glfw.win32.deviceNotificationHandle = notify } - _glfw.win32.deviceNotificationHandle = notify var msg _MSG for _PeekMessageW(&msg, _glfw.win32.helperWindowHandle, 0, 0, _PM_REMOVE) { diff --git a/internal/glfwwin/win32monitor_windows.go b/internal/glfwwin/win32monitor_windows.go index c49e7b275..e57629012 100644 --- a/internal/glfwwin/win32monitor_windows.go +++ b/internal/glfwwin/win32monitor_windows.go @@ -102,6 +102,10 @@ func createMonitor(adapter *_DISPLAY_DEVICEW, display *_DISPLAY_DEVICEW) (*Monit } func pollMonitorsWin32() error { + if !_EnumDisplayDevicesW_Available() { + return nil + } + disconnected := make([]*Monitor, len(_glfw.monitors)) copy(disconnected, _glfw.monitors)