使用node-ffi加载本地dll:没有这样的文件

问题描述 投票:0回答:2

我尝试根据stackoverflownode-ffi文档上的示例加载本地.dll。 但我收到错误 ENOENT:没有这样的文件或目录,打开“../test/user32.dll.so”。该文件就在那里(也不例外)。 扩展名“.so”会自动添加。知道我做错了什么吗?该代码依赖于平台吗?我在 Debian。

const path = require('path');
const fs = require('fs');
const ffi = require('ffi');

function setCursor() {
    const dllFile = path.join('../test', 'user32.dll');
    if (!fs.existsSync(dllFile)) {
        throw (new Error('dll does not exist'));
    }

    const user32 = ffi.Library(dllFile, {
        "SetCursorPos": [
            "bool", ["int32", "int32"]
        ]
    });

    console.log(user32.SetCursorPos(0, 0));
}

setCursor();
javascript dll node-ffi
2个回答
1
投票

看起来路径无法将

../test
识别为父文件夹。我认为
path.join(__dirname, '..', 'test', 'user32.dll');
应该带你到正确的地方。


0
投票

我最终使用了https://www.npmjs.com/package/koffi而不是node-ffi。

© www.soinside.com 2019 - 2024. All rights reserved.