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 Unverified
B5690EEEBB952194The 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 @@ | |||
| 3 | 3 | ||
| 4 | 4 | package main | |
| 5 | 5 | ||
| 6 | - | import "golang.org/x/sys/windows" | |
| 6 | + | import "syscall" | |
| 7 | 7 | ||
| 8 | 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 | 12 | return uintptr(handle), err | |
| 11 | 13 | } | |
| @@ -3,9 +3,11 @@ | |||||
| 3 | 3 | ||||
| 4 | package main | 4 | 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), err | 12 | return uintptr(handle), err | ||
| 11 | } | 13 | } | ||
M examples/window/main_windows.go +11 -8
| @@ -5,10 +5,9 @@ package main | |||
| 5 | 5 | ||
| 6 | 6 | import ( | |
| 7 | 7 | "runtime" | |
| 8 | + | "syscall" | |
| 8 | 9 | "unsafe" | |
| 9 | 10 | ||
| 10 | - | "golang.org/x/sys/windows" | |
| 11 | - | ||
| 12 | 11 | "github.com/ebitengine/purego" | |
| 13 | 12 | ) | |
| 14 | 13 | ||
| @@ -78,10 +77,14 @@ var ( | |||
| 78 | 77 | ) | |
| 79 | 78 | ||
| 80 | 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 | 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 | 88 | purego.RegisterLibFunc(&RegisterClassEx, user32, "RegisterClassExW") | |
| 86 | 89 | purego.RegisterLibFunc(&CreateWindowEx, user32, "CreateWindowExW") | |
| 87 | 90 | purego.RegisterLibFunc(&AdjustWindowRect, user32, "AdjustWindowRect") | |
| @@ -96,7 +99,7 @@ func init() { | |||
| 96 | 99 | } | |
| 97 | 100 | ||
| 98 | 101 | func main() { | |
| 99 | - | className, err := windows.UTF16PtrFromString("Sample Window Class") | |
| 102 | + | className, err := syscall.UTF16PtrFromString("Sample Window Class") | |
| 100 | 103 | if err != nil { | |
| 101 | 104 | panic(err) | |
| 102 | 105 | } | |
| @@ -104,7 +107,7 @@ func main() { | |||
| 104 | 107 | ||
| 105 | 108 | wc := WNDCLASSEX{ | |
| 106 | 109 | Size: uint32(unsafe.Sizeof(WNDCLASSEX{})), | |
| 107 | - | WndProc: windows.NewCallback(wndProc), | |
| 110 | + | WndProc: syscall.NewCallback(wndProc), | |
| 108 | 111 | Instance: inst, | |
| 109 | 112 | ClassName: className, | |
| 110 | 113 | } | |
| @@ -117,7 +120,7 @@ func main() { | |||
| 117 | 120 | Right: 320, | |
| 118 | 121 | Bottom: 240, | |
| 119 | 122 | } | |
| 120 | - | title, err := windows.UTF16PtrFromString("My Title") | |
| 123 | + | title, err := syscall.UTF16PtrFromString("My Title") | |
| 121 | 124 | if err != nil { | |
| 122 | 125 | panic(err) | |
| 123 | 126 | } | |
| @@ -130,7 +133,7 @@ func main() { | |||
| 130 | 133 | 0, 0, inst, nil, | |
| 131 | 134 | ) | |
| 132 | 135 | if hwnd == 0 { | |
| 133 | - | panic(windows.GetLastError()) | |
| 136 | + | panic(syscall.GetLastError()) | |
| 134 | 137 | } | |
| 135 | 138 | ||
| 136 | 139 | 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 @@ | |||
| 1 | 1 | module github.com/ebitengine/purego | |
| 2 | 2 | ||
| 3 | 3 | go 1.18 | |
| 4 | - | ||
| 5 | - | require golang.org/x/sys v0.23.0 | |
| @@ -1,5 +1,3 @@ | |||||
| 1 | module github.com/ebitengine/purego | 1 | module github.com/ebitengine/purego | ||
| 2 | 2 | ||||
| 3 | go 1.18 | 3 | go 1.18 | ||
| 4 | - | ||||
| 5 | - | require golang.org/x/sys v0.23.0 | |||