golang 以加载windows系统动态库的方式
代码package main
import (
"syscall"
"time"
"unsafe"
)
func IntPtr(n int) uintptr {
return uintptr(n)
}
func StrPtr(s string) uintptr {
return uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(s)))
}
//windows下的另一种DLL方法调用
func ShowMessage2(tittle, text string) {
user32dll, _ := syscall.LoadLibrary("user32.dll")
user32 := syscall.NewLazyDLL("user32.dll")
MessageBoxW := user32.NewProc("MessageBoxW")
MessageBoxW.Call(IntPtr(0), StrPtr(text), StrPtr(tittle), IntPtr(0))
defer syscall.FreeLibrary(user32dll)
}
func main() {
go func() {
for {
ShowMessage2("当前列车遇到障碍物!", "第5列TC1")
time.Sleep(3 * time.Second)
}
}()
select {}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)