go 동적 링크 라이브러리 dll/so 호출
582 단어 ----Go
package main
import "syscall"
func main() {
// test.dll
// int add(int x, int y)
h, err := syscall.LoadLibrary("test.dll")
if (err != nil){
panic(err.Error())
}
defer syscall.FreeLibrary(h)
proc, err := syscall.GetProcAddress(h, "add")
if (err != nil) {
panic(err.Error())
}
r, _, _ := syscall.Syscall(uintptr(proc), 2, 1, 1, 0)
println("r=", r)
dll := syscall.NewLazyDLL("test.dll")
add := dll.NewProc("add")
ret, _, _ := add.Call(uintptr(1), uintptr(1))
println("1+1=", ret)
}