環境 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