@@ -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,15 +99,15 @@ 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
}
103
106
inst := GetModuleHandle (className )
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 )
0 commit comments