package main import ( "syscall" ) func main(){ h, err := syscall.LoadLibrary("kernel32.dll") if err != nil { abort("LoadLibrary", err) } defer syscall.FreeLibrary(h) proc, err := syscall.GetProcAddress(h, "GetVersion") if err != nil { abort("GetProcAddress", err) } r, _, _ := syscall.Syscall(uintptr(proc), 0, 0, 0, 0) print_version(uint32(r)) } func abort(funcname string, err error) { panic(funcname + " failed: " + err.Error()) } func print_version(v uint32) { major := byte(v) minor := uint8(v >> 8) build := uint16(v >> 16) print("windows version ", major, ".", minor, " (Build ", build, ")\n") }
转自:http://bbs.studygolang.com/thread-277-1-1.html
有疑问加站长微信联系(非本文作者)