diff --git a/internal/glfwwin/api_windows.go b/internal/glfwwin/api_windows.go index 74102539b..11f496428 100644 --- a/internal/glfwwin/api_windows.go +++ b/internal/glfwwin/api_windows.go @@ -24,6 +24,12 @@ import ( "golang.org/x/sys/windows" ) +type handleError windows.Handle + +func (h handleError) Error() string { + return fmt.Sprintf("HANDLE(%d)", h) +} + // math.MaxUint was added at Go 1.17. See https://github.com/golang/go/issues/28538 const ( intSize = 32 << (^uint(0) >> 63) @@ -1312,7 +1318,7 @@ func _GetMonitorInfoW_Ex(hMonitor _HMONITOR) (_MONITORINFOEXW, bool) { func _GetDpiForMonitor(hmonitor _HMONITOR, dpiType _MONITOR_DPI_TYPE) (dpiX, dpiY uint32, err error) { r, _, _ := procGetDpiForMonitor.Call(uintptr(hmonitor), uintptr(dpiType), uintptr(unsafe.Pointer(&dpiX)), uintptr(unsafe.Pointer(&dpiY))) if uint32(r) != uint32(windows.S_OK) { - return 0, 0, fmt.Errorf("glfwwin: GetDpiForMonitor failed: %w", windows.Errno(uint32(r))) + return 0, 0, fmt.Errorf("glfwwin: GetDpiForMonitor failed: %w", handleError(windows.Handle(uint32(r)))) } return dpiX, dpiY, nil } @@ -1593,7 +1599,7 @@ func _SetProcessDPIAware() bool { func _SetProcessDpiAwareness(value _PROCESS_DPI_AWARENESS) error { r, _, _ := procSetProcessDpiAwareness.Call(uintptr(value)) if uint32(r) != uint32(windows.S_OK) { - return fmt.Errorf("glfwwin: SetProcessDpiAwareness failed: %w", windows.Errno(uint32(r))) + return fmt.Errorf("glfwwin: SetProcessDpiAwareness failed: %w", handleError(windows.Handle(uint32(r)))) } return nil } diff --git a/internal/glfwwin/win32init_windows.go b/internal/glfwwin/win32init_windows.go index ca0837f52..f4c683b5e 100644 --- a/internal/glfwwin/win32init_windows.go +++ b/internal/glfwwin/win32init_windows.go @@ -246,7 +246,7 @@ func platformInit() error { _ = _SetProcessDpiAwarenessContext(_DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2) } } else if _IsWindows8Point1OrGreater() { - if err := _SetProcessDpiAwareness(_PROCESS_PER_MONITOR_DPI_AWARE); err != nil && !errors.Is(err, windows.ERROR_ACCESS_DENIED) { + if err := _SetProcessDpiAwareness(_PROCESS_PER_MONITOR_DPI_AWARE); err != nil && !errors.Is(err, handleError(windows.E_ACCESSDENIED)) { return err } } else if _IsWindowsVistaOrGreater() { diff --git a/internal/graphicsdriver/directx/api_windows.go b/internal/graphicsdriver/directx/api_windows.go index 012069e05..d3de7bc3c 100644 --- a/internal/graphicsdriver/directx/api_windows.go +++ b/internal/graphicsdriver/directx/api_windows.go @@ -29,6 +29,12 @@ import ( const is64bit = unsafe.Sizeof(uintptr(0)) == 8 +type handleError windows.Handle + +func (h handleError) Error() string { + return fmt.Sprintf("HANDLE(%d)", h) +} + type ( _BOOL int32 ) @@ -639,7 +645,7 @@ const ( _DXGI_CREATE_FACTORY_DEBUG = 0x01 - _DXGI_ERROR_NOT_FOUND = windows.Errno(0x887A0002) + _DXGI_ERROR_NOT_FOUND = handleError(0x887A0002) _DXGI_MWA_NO_ALT_ENTER = 0x2 _DXGI_MWA_NO_WINDOW_CHANGES = 0x1 @@ -2464,7 +2470,7 @@ func (i *_IDXGIFactory4) EnumAdapters1(adapter uint32) (*_IDXGIAdapter1, error) var ptr *_IDXGIAdapter1 r, _, _ := syscall.Syscall(i.vtbl.EnumAdapters1, 3, uintptr(unsafe.Pointer(i)), uintptr(adapter), uintptr(unsafe.Pointer(&ptr))) if uint32(r) != uint32(windows.S_OK) { - return nil, fmt.Errorf("directx: IDXGIFactory4::EnumAdapters1 failed: HRESULT(%d)", uint32(r)) + return nil, fmt.Errorf("directx: IDXGIFactory4::EnumAdapters1 failed: %w", handleError(windows.Handle(uint32(r)))) } return ptr, nil }