detached 6580f25

examples: remove depdencies on golang.org/x/sys/windows (#278)

Closes #270
commit
6580f25cf0bbead00d44e3eea069bf2dae613eef
author
Hajime Hoshi · · 2024-09-03 15:08 UTC
committer
GitHub · · 2024-09-03 15:08 UTC
parent
552a4de
signature
GPG UnverifiedB5690EEEBB952194 The key is unknown
refs
tag: v0.8.0-alpha.6
4 files · +15 -14
M examples/libc/main_windows.go +4 -2
@@ -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 }
@@ -3,9 +3,11 @@
3 3
4 package main4 package main
5 5
6-import "golang.org/x/sys/windows"6+import "syscall"
7 7
8 func openLibrary(name string) (uintptr, error) {8 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)
10 return uintptr(handle), err12 return uintptr(handle), err
11 }13 }
M examples/window/main_windows.go +11 -8
@@ -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,7 +99,7 @@ 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 }
@@ -104,7 +107,7 @@ func main() {
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)
@@ -5,10 +5,9 @@ package main
5 5
6 import (6 import (
7 "runtime"7 "runtime"
8+ "syscall"
8 "unsafe"9 "unsafe"
9 10
10- "golang.org/x/sys/windows"
11-
12 "github.com/ebitengine/purego"11 "github.com/ebitengine/purego"
13 )12 )
14 13
@@ -78,10 +77,14 @@ var (
78 )77 )
79 78
80 func init() {79 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()
82 purego.RegisterLibFunc(&GetModuleHandle, kernel32, "GetModuleHandleW")83 purego.RegisterLibFunc(&GetModuleHandle, kernel32, "GetModuleHandleW")
83 84
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()
85 purego.RegisterLibFunc(&RegisterClassEx, user32, "RegisterClassExW")88 purego.RegisterLibFunc(&RegisterClassEx, user32, "RegisterClassExW")
86 purego.RegisterLibFunc(&CreateWindowEx, user32, "CreateWindowExW")89 purego.RegisterLibFunc(&CreateWindowEx, user32, "CreateWindowExW")
87 purego.RegisterLibFunc(&AdjustWindowRect, user32, "AdjustWindowRect")90 purego.RegisterLibFunc(&AdjustWindowRect, user32, "AdjustWindowRect")
@@ -96,7 +99,7 @@ func init() {
96 }99 }
97 100
98 func main() {101 func main() {
99- className, err := windows.UTF16PtrFromString("Sample Window Class")102+ className, err := syscall.UTF16PtrFromString("Sample Window Class")
100 if err != nil {103 if err != nil {
101 panic(err)104 panic(err)
102 }105 }
@@ -104,7 +107,7 @@ func main() {
104 107
105 wc := WNDCLASSEX{108 wc := WNDCLASSEX{
106 Size: uint32(unsafe.Sizeof(WNDCLASSEX{})),109 Size: uint32(unsafe.Sizeof(WNDCLASSEX{})),
107- WndProc: windows.NewCallback(wndProc),110+ WndProc: syscall.NewCallback(wndProc),
108 Instance: inst,111 Instance: inst,
109 ClassName: className,112 ClassName: className,
110 }113 }
@@ -117,7 +120,7 @@ func main() {
117 Right: 320,120 Right: 320,
118 Bottom: 240,121 Bottom: 240,
119 }122 }
120- title, err := windows.UTF16PtrFromString("My Title")123+ title, err := syscall.UTF16PtrFromString("My Title")
121 if err != nil {124 if err != nil {
122 panic(err)125 panic(err)
123 }126 }
@@ -130,7 +133,7 @@ func main() {
130 0, 0, inst, nil,133 0, 0, inst, nil,
131 )134 )
132 if hwnd == 0 {135 if hwnd == 0 {
133- panic(windows.GetLastError())136+ panic(syscall.GetLastError())
134 }137 }
135 138
136 ShowWindow(hwnd, SW_SHOW)139 ShowWindow(hwnd, SW_SHOW)
M go.mod +0 -2
@@ -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
@@ -1,5 +1,3 @@
1 module github.com/ebitengine/purego1 module github.com/ebitengine/purego
2 2
3 go 1.183 go 1.18
4-
5-require golang.org/x/sys v0.23.0
M go.sum +0 -2 generated file: collapsed

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 102

↑↓ moveenter openesc close