Skip to content

Commit

Permalink
examples: remove depdencies on golang.org/x/sys/windows (#278)
Browse files Browse the repository at this point in the history
Closes #270
  • Loading branch information
hajimehoshi authored Sep 3, 2024
1 parent 552a4de commit 6580f25
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
6 changes: 4 additions & 2 deletions examples/libc/main_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

package main

import "golang.org/x/sys/windows"
import "syscall"

func openLibrary(name string) (uintptr, error) {
handle, err := windows.LoadLibrary(name)
// Use [syscall.LoadLibrary] here to avoid external dependencies (#270).
// For actual use cases, [golang.org/x/sys/windows.NewLazySystemDLL] is recommended.
handle, err := syscall.LoadLibrary(name)
return uintptr(handle), err
}
19 changes: 11 additions & 8 deletions examples/window/main_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ package main

import (
"runtime"
"syscall"
"unsafe"

"golang.org/x/sys/windows"

"github.com/ebitengine/purego"
)

Expand Down Expand Up @@ -78,10 +77,14 @@ var (
)

func init() {
kernel32 := windows.NewLazySystemDLL("kernel32.dll").Handle()
// Use [syscall.NewLazyDLL] here to avoid external dependencies (#270).
// For actual use cases, [golang.org/x/sys/windows.NewLazySystemDLL] is recommended.
kernel32 := syscall.NewLazyDLL("kernel32.dll").Handle()
purego.RegisterLibFunc(&GetModuleHandle, kernel32, "GetModuleHandleW")

user32 := windows.NewLazySystemDLL("user32.dll").Handle()
// Use [syscall.NewLazyDLL] here to avoid external dependencies (#270).
// For actual use cases, [golang.org/x/sys/windows.NewLazySystemDLL] is recommended.
user32 := syscall.NewLazyDLL("user32.dll").Handle()
purego.RegisterLibFunc(&RegisterClassEx, user32, "RegisterClassExW")
purego.RegisterLibFunc(&CreateWindowEx, user32, "CreateWindowExW")
purego.RegisterLibFunc(&AdjustWindowRect, user32, "AdjustWindowRect")
Expand All @@ -96,15 +99,15 @@ func init() {
}

func main() {
className, err := windows.UTF16PtrFromString("Sample Window Class")
className, err := syscall.UTF16PtrFromString("Sample Window Class")
if err != nil {
panic(err)
}
inst := GetModuleHandle(className)

wc := WNDCLASSEX{
Size: uint32(unsafe.Sizeof(WNDCLASSEX{})),
WndProc: windows.NewCallback(wndProc),
WndProc: syscall.NewCallback(wndProc),
Instance: inst,
ClassName: className,
}
Expand All @@ -117,7 +120,7 @@ func main() {
Right: 320,
Bottom: 240,
}
title, err := windows.UTF16PtrFromString("My Title")
title, err := syscall.UTF16PtrFromString("My Title")
if err != nil {
panic(err)
}
Expand All @@ -130,7 +133,7 @@ func main() {
0, 0, inst, nil,
)
if hwnd == 0 {
panic(windows.GetLastError())
panic(syscall.GetLastError())
}

ShowWindow(hwnd, SW_SHOW)
Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module github.com/ebitengine/purego

go 1.18

require golang.org/x/sys v0.23.0
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=

0 comments on commit 6580f25

Please sign in to comment.