环境 win7  node9.9  npm6.3  node-gyp3.7.0

npm install node-gyp -g

1.github上下载最新ffi代码

https://github.com/node-ffi/node-ffi

2.用cpm安装ffi需要的模块

3.node-gyp configure

node-gyp build

4.编译好不出错后就可以拷到别处用了。下面代码可以测试编译好了么。调用windows里的user32.dll

 

var FFI = require('./node_modules/node-ffi');
function TEXT(text){
    return new Buffer(text, 'ucs2').toString('binary');
}
var user32 = new FFI.Library('user32', {
    'MessageBoxW':
        [
            'int32', [ 'int32', 'string', 'string', 'int32' ]
        ]
});
var OK_or_Cancel = user32.MessageBoxW(
    0, TEXT('I am Node.JS!'), TEXT('Hello, World!'), 1
);
console.log(OK_or_Cancel);

  

 

 

如果linux下就可以下载node-ffi直接npm i 然后 node-gyp configure   node-gyp build

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-02-24
  • 2021-08-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-09-03
  • 2022-01-31
  • 2022-12-23
  • 2021-09-20
  • 2023-03-06
  • 2021-04-21
相关资源
相似解决方案