Skip to content

Commit b498191

Browse files
committed
add module example
1 parent 7a93b82 commit b498191

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

examples/syscall/module/main.go

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package main
2+
3+
import (
4+
"golang.org/x/sys/windows"
5+
)
6+
7+
func main() {
8+
caption, err := windows.UTF16PtrFromString("Go Windows Programming")
9+
if err != nil {
10+
panic(err)
11+
}
12+
text, err := windows.UTF16PtrFromString("Calling MessageBox from Go!")
13+
if err != nil {
14+
panic(err)
15+
}
16+
17+
messageBox(0, text, caption, 0)
18+
}

examples/syscall/module/syscall.go

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package main
2+
3+
import (
4+
"unsafe"
5+
6+
"golang.org/x/sys/windows"
7+
)
8+
9+
var (
10+
libuser32 *windows.LazyDLL
11+
12+
procMessageBoxW *windows.LazyProc
13+
)
14+
15+
func init() {
16+
libuser32 = windows.NewLazySystemDLL("user32.dll")
17+
18+
procMessageBoxW = libuser32.NewProc("MessageBoxW")
19+
}
20+
21+
func messageBox(hWnd uintptr, lpText *uint16, lpCaption *uint16, uType uint32) int32 {
22+
r1, _, _ := procMessageBoxW.Call(uintptr(hWnd), uintptr(unsafe.Pointer(lpText)), uintptr(unsafe.Pointer(lpCaption)), uintptr(uType))
23+
return int32(r1)
24+
}

0 commit comments

Comments
 (0)