mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
syscall: extract an ExampleLoadLibrary from comment
while we are at it, fix some out-of-date comments. R=golang-dev, dave, r CC=golang-dev https://golang.org/cl/6498054
This commit is contained in:
parent
db3474f1bb
commit
f78ead3ca4
4 changed files with 24 additions and 40 deletions
|
|
@ -49,3 +49,24 @@ func TestWin32finddata(t *testing.T) {
|
|||
t.Fatalf("memory corruption: want=%d got=%d", want, x.got)
|
||||
}
|
||||
}
|
||||
|
||||
func abort(funcname string, err error) {
|
||||
panic(funcname + " failed: " + err.Error())
|
||||
}
|
||||
|
||||
func ExampleLoadLibrary() {
|
||||
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)
|
||||
major := byte(r)
|
||||
minor := uint8(r >> 8)
|
||||
build := uint16(r >> 16)
|
||||
print("windows version ", major, ".", minor, " (Build ", build, ")\n")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue