Skip to content

Commit c3f4c9c

Browse files
hajimehoshiTotallyGamerJet
authored andcommitted
examples: remove depdencies on golang.org/x/sys/windows (ebitengine#278)
Closes ebitengine#270
1 parent 5ad9415 commit c3f4c9c

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

examples/libc/main_windows.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33

44
package main
55

6-
import "golang.org/x/sys/windows"
6+
import "syscall"
77

88
func openLibrary(name string) (uintptr, error) {
9-
handle, err := windows.LoadLibrary(name)
9+
// Use [syscall.LoadLibrary] here to avoid external dependencies (#270).
10+
// For actual use cases, [golang.org/x/sys/windows.NewLazySystemDLL] is recommended.
11+
handle, err := syscall.LoadLibrary(name)
1012
return uintptr(handle), err
1113
}

examples/window/main_windows.go

+11-8
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ package main
55

66
import (
77
"runtime"
8+
"syscall"
89
"unsafe"
910

10-
"golang.org/x/sys/windows"
11-
1211
"github.com/ebitengine/purego"
1312
)
1413

@@ -78,10 +77,14 @@ var (
7877
)
7978

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

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

98101
func main() {
99-
className, err := windows.UTF16PtrFromString("Sample Window Class")
102+
className, err := syscall.UTF16PtrFromString("Sample Window Class")
100103
if err != nil {
101104
panic(err)
102105
}
103106
inst := GetModuleHandle(className)
104107

105108
wc := WNDCLASSEX{
106109
Size: uint32(unsafe.Sizeof(WNDCLASSEX{})),
107-
WndProc: windows.NewCallback(wndProc),
110+
WndProc: syscall.NewCallback(wndProc),
108111
Instance: inst,
109112
ClassName: className,
110113
}
@@ -117,7 +120,7 @@ func main() {
117120
Right: 320,
118121
Bottom: 240,
119122
}
120-
title, err := windows.UTF16PtrFromString("My Title")
123+
title, err := syscall.UTF16PtrFromString("My Title")
121124
if err != nil {
122125
panic(err)
123126
}
@@ -130,7 +133,7 @@ func main() {
130133
0, 0, inst, nil,
131134
)
132135
if hwnd == 0 {
133-
panic(windows.GetLastError())
136+
panic(syscall.GetLastError())
134137
}
135138

136139
ShowWindow(hwnd, SW_SHOW)

go.mod

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
module github.com/ebitengine/purego
22

33
go 1.18
4-
5-
require golang.org/x/sys v0.23.0

go.sum

-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +0,0 @@
1-
golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
2-
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=

0 commit comments

Comments
 (0)