凌的博客

您现在的位置是: 首页 > 学无止境 > Go > 

Go

go使用dll动态链接库

2023-10-25 Go 272

lib.go

package main

import "C"

//export HelloWorld
func HelloWorld() {
    println("Hello world!")
}

func main() {}

// go build -buildmode=c-shared -o lib.dll lib.go

//lib := syscall.NewLazyDLL("lib/plugin.dll") // 读取dll
//f := lib.NewProc("Sum") // 调用dll函数
//res, _, _ := f.Call(param) // 传值
//fmt.Println(res)

test.go

package main

import (
    "syscall"
)

func main() {
    lib := syscall.NewLazyDLL("lib.dll") // 读取dll
    f := lib.NewProc("HelloWorld")       // 调用dll函数
    f.Call()                             // 传值

}


image.png

文章评论

0条评论