Skip to content

Commit

Permalink
load our DLL procs only once
Browse files Browse the repository at this point in the history
  • Loading branch information
dweymouth committed Aug 3, 2024
1 parent e1e1198 commit 66829eb
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions internal/driver/glfw/driver_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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
}
Expand Down

0 comments on commit 66829eb

Please sign in to comment.