Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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=
Loading