一、為什么需要使用DLL
需要使用系統(tǒng) API 操作或擴(kuò)展應(yīng)用程序;
需要調(diào)用第三方的接口API,特別是與硬件設(shè)備進(jìn)行通信,而這些接口 API 基本上都是通過(guò) C++ 動(dòng)態(tài)鏈接庫(kù)(DLL)實(shí)現(xiàn)的;
需要調(diào)用C++實(shí)現(xiàn)的一些復(fù)雜算法等。
二、node-ffi 是什么
node-ffi:Node.js Foreign Function Interface
node-ffi
is a Node.js addon for loading and calling dynamic libraries using pure JavaScript. It can be used to create bindings to native libraries without writing any C++ code. It also simplifies the augmentation of node.js with C code as it takes care of handling the translation of types across JavaScript and C, which can add reams of boilerplate code to your otherwise simple C. See the example/factorial for an example of this use case.
WARNING: node-ffi
assumes you know what you're doing. You can pretty easily create situations where you will segfault the interpreter and unless you've got C debugger skills, you probably won't know what's going on.
上面是 node-ffi 的介紹,英語(yǔ)不好,就不翻譯了。
三、electron 使用 node-ffi
使用上一篇文章里的項(xiàng)目,在 package.json 的 dependencies 節(jié)點(diǎn)上加上node-ffi 依賴:
"dependencies": { "electron": "^1.6.11", "ffi": "2.2.0" }
然后安裝缺失的 npm 包(參考之前的
網(wǎng)友評(píng)論