Node-FFI ref-struct 传递对象

问题描述

我被困在某个地方,需要你的帮助。

基本上我们要添加 Windows 网络凭据以连接网络共享文件夹.... 官方 Dll 文档是 here

而这个 WNetAddConnection2W 函数需要 4 个参数。我卡在这里了。因为第一个参数需要一个对象,我不能传递这个。

一个参数是 lpNetResource,我认为这是一个对象,所以我使用 ref-struct。其他参数很简单,因为它们需要字符串。

它正在运行,但我总是得到 67 - ERROR_BAD_NET_NAME,我尝试更改结构的每个部分,但它不起作用。

我的代码

var ref = require('ref');
var StructType = require('ref-struct')
var ffi = require('ffi');
var lpNetResource = StructType({
  dwType: ref.types.uint32,lpLocalName: 'string',lpRemoteName: 'string',lpProvider: 'string'
})
const obj = {
  dwType: "",dwdisplayType: "",lpLocalName : "",lpRemoteName: "\\\\172.20.0.110",lpProvider:''
}
var current = ffi.Library("./mpr.dll",{
  'WNetAddConnection2W': [ref.types.uint32,[lpNetResource,'string','int']],});

var add = current.WNetAddConnection2W(new lpNetResource(obj),"123456","root",4)
console.log(add) // 67 - ERROR_BAD_NET_NAME

DOCS IMAGE

DOCS URL

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)