package main
import (
"syscall"
)
func abort(funcname string, err string) {
panic(funcname + " failed: "+err)
}
func print_version(v uint32) {
major := byte(v)
minor := uint8(v >> 8)
build := uint16(v >> 16)
print("windows version ", major, ".", minor, " (Build ", build, ")\n")
}
func main() {
h, err := syscall.LoadLibrary("kernel32.dll")
if err!=nil {
abort("LoadLibrary", err.Error())
}
defer syscall.FreeLibrary(h)
proc, err := syscall.GetProcAddress(h, "GetVersion")
if err!=nil {
abort("GetProcAddress", err.Error())
}
r, _, _ := syscall.Syscall(uintptr(proc), 0, 0, 0,0)
print_version(uint32(r))
}
//windows 7下调试通过
// 附 一个go站 http://golangwiki.org
//附 error 定义
type error interface { Error() string }
有疑问加站长微信联系(非本文作者)