From 66829ebdb723453da3c92d15610adfe265c55164 Mon Sep 17 00:00:00 2001 From: Drew Weymouth Date: Sat, 3 Aug 2024 08:53:42 -0700 Subject: [PATCH] load our DLL procs only once --- internal/driver/glfw/driver_windows.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/internal/driver/glfw/driver_windows.go b/internal/driver/glfw/driver_windows.go index 2f60018e1f..4752ed2fc7 100644 --- a/internal/driver/glfw/driver_windows.go +++ b/internal/driver/glfw/driver_windows.go @@ -21,6 +21,15 @@ const ( ES_DISPLAY_REQUIRED ES = 0x00000002 ) +var ( + kernel32 = syscall.NewLazyDLL("kernel32.dll") + user32 = syscall.NewLazyDLL("user32.dll") + + executionState = kernel32.NewProc("SetThreadExecutionState") + MessageBox = user32.NewProc("MessageBoxW") + getDoubleClickTime = user32.NewProc("GetDoubleClickTime") +) + func toNativePtr(s string) *uint16 { pstr, err := syscall.UTF16PtrFromString(s) if err != nil { @@ -31,8 +40,6 @@ func toNativePtr(s string) *uint16 { // https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-messageboxw func messageBoxError(text, caption string) { - user32 := syscall.NewLazyDLL("user32.dll") - MessageBox := user32.NewProc("MessageBoxW") uType := MB_OK | MB_ICONERROR @@ -57,9 +64,6 @@ func logError(msg string, err error) { } func setDisableScreenBlank(disable bool) { - kernel32 := syscall.NewLazyDLL("kernel32.dll") - executionState := kernel32.NewProc("SetThreadExecutionState") - uType := ES_CONTINUOUS if disable { uType |= ES_DISPLAY_REQUIRED @@ -72,11 +76,6 @@ const defaultDoubleTapDelay = 300 * time.Millisecond func (g *gLDriver) DoubleTapDelay() time.Duration { // https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getdoubleclicktime - user32 := syscall.NewLazyDLL("user32.dll") - if user32 == nil { - return defaultDoubleTapDelay - } - getDoubleClickTime := user32.NewProc("GetDoubleClickTime") if getDoubleClickTime == nil { return defaultDoubleTapDelay }