go调用动态链接库dll/so

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)
}

你可能感兴趣的:(----Go)