windows里编译node-ffi模块


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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM