我想从节点 js 加载一个 dll 文件。这是头文件:
#pragma once
#ifdef __cplusplus
#define EXAMPLE __declspec(dllexport)
extern "C" {
EXAMPLE int Add(int, int);
}
#endif
在编译为,我选择“编译为 C 代码”
在主动解决方案平台,我选择x64
然后,我使用 ffi 模块来加载它:
var ffi = require('ffi');
var Lib = ffi.Library('test', {'Add' : ['int',['int','int']]});
但我得到一个错误:
C:\Users\TheHai\node_modules\ffi\lib\dynamic_library.js:112
throw new Error('Dynamic Symbol Retrieval Error: ' + this.error())
^
Error: Dynamic Symbol Retrieval Error: Win32 error 127
at DynamicLibrary.get (C:\Users\TheHai\node_modules\ffi\lib\dynamic_library.js:112:11)
at C:\Users\TheHai\node_modules\ffi\lib\library.js:50:19
at Array.forEach (native)
at Object.Library (C:\Users\TheHai\node_modules\ffi\lib\library.js:47:28)
at Object.<anonymous> (C:\Users\TheHai\Downloads\Compressed\nodejs-websocket-master\samples\chat\server.js:8:15)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)