golang cgo调用dll - Tue, Nov 19, 2019
golang cgo调用dll
package main
import (
"syscall"
)
func main(){
h, err := syscall.LoadLibrary("kernel32.dll")
if err != nil {
panic("LoadLibrary failed: " + err.Error())
}
defer syscall.FreeLibrary(h)
proc, err := syscall.GetProcAddress(h, "GetVersion")
if err != nil {
panic("GetProcAddress failed: " + err.Error())
}
r, _, _ := syscall.Syscall(uintptr(proc), 0, 0, 0, 0)
major := byte(uint32(r))
minor := uint8(uint32(r) >> 8)
build := uint16(uint32(r) >> 16)
print("windows version ", major, ".", minor, " (Build ", build, ")\n")
}
output
GOROOT=C:\Go #gosetup
GOPATH=E:\kaisawind\go #gosetup
C:\Go\bin\go.exe build -o C:\Users\kaisa\AppData\Local\Temp\___go_build_github_com_kaisawind_ffmpeg_go_examples_avio_dir_cmd.exe github.com/kaisawind/ffmpeg.go/examples/avio_dir_cmd #gosetup
C:\Users\kaisa\AppData\Local\Temp\___go_build_github_com_kaisawind_ffmpeg_go_examples_avio_dir_cmd.exe #gosetup
windows version 6.2 (Build 9200)
Process finished with exit code 0