当前位置: 移动技术网 > IT编程>脚本编程>Go语言 > Go调用Delphi编写的DLL

Go调用Delphi编写的DLL

2019年07月29日  | 移动技术网IT编程  | 我要评论

参数整数没有问题,但是如果是字符串,要注意几个细节。

记录如下:

1.delphi定义函数的时候,字符串参数需要使用pchar类型

2.go传递参数的时候要将字符串转成utf16的指针,接收的时候采用uint16的切片。

 1     dll := syscall.mustloaddll("encryptdll.dll")
 2     defer syscall.freelibrary(dll.handle)
 3     f1 := dll.mustfindproc("test06")
 4     fmt.println("f1>>>>", f1)
 5 
 6     p1, _ := syscall.utf16ptrfromstring("sql")
 7     p2 := make([]uint16, 100) // pass word limited length! syscall.max_path
 8 
 9     r1, r2, err := f1.call(uintptr(unsafe.pointer(p1)), uintptr(unsafe.pointer(&p2)))
10     if err != nil {
11         fmt.println(r1, r2, p1, p2, err.error(), syscall.utf16tostring(p2))
12     }

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网