我正在尝试在Go项目中使用专有DLL。
DLL的方法描述之一如下所示:
BYTE* Init(const BYTE* path, int id);
在我的测试Go项目中,我正在做类似的事情:
import (
"golang.org/x/sys/windows"
)
var (
lib = windows.MustLoadDLL("dllname.dll")
init = lib.MustFindProc("Init")
)
func main() {
path := "some"
bytePath = []byte(path)
init.Call(
uintptr(unsafe.Pointer(&bytePath)),
uintptr(9)
)
}
库被调用,有一条错误消息“路径不存在”,但我认为我的路径类型不对。这就是图书馆无法看到文件夹的原因。
也许还有更好的方法吗?也许这是一个糟糕的Go使用案例,我应该找到一些包甚至语言?
您的路径可能需要以NULL结尾:
import (
"golang.org/x/sys/windows"
)
var (
lib = windows.MustLoadDLL("dllname.dll")
init = lib.MustFindProc("Init")
)
func main() {
path := "some"
bytePath = []byte(path + "\x00")
init.Call(
uintptr(unsafe.Pointer(&bytePath[0])),
uintptr(9)
)
}