##方法1:调用动态链接库dll(c++写的)
electron桌面应用开发下调用:
###1.1 准备工作
编译软件:(编译c++/c的插件)
- 安装npm install -g node-gyp
管理员身份运行:
如果本机已经装过vs2017,会失败,不建议这样。
1.- npm install --global --production windows-build-tools
2.手动安装
- Visual C++ Build Environment: Visual Studio Build Tools
- Install Python 2.7
nodejs8:
- 安装node(64/32位根据dll选择)
https://nodejs.org/zh-cn/
python2.7:
- 安装python:
https://www.python.org/ftp/python/2.7.15/python-2.7.15.msi
- 安装ffi
```
npm install --save ffi
```
注意:此时ffi不能使用需重新编译
```
- 重新下载ffi源码:https://github.com/node-ffi/node-ffi,然后把项目下./node-modules/ffi目录中的内容清空替换为我们刚下载的源码。
- 然后依次进入ffi和ref目录下,手动执行node-gyp命令进行编译:
node-gyp rebuild --arch=ia32 --dist-url=https://atom.io/download/electron --runtime=electron --target=3.0.7
--arch参数代表要编译的系统平台,ia32代表32位,x64代表64位
--target参数代表当前使用的electron版本号
```
###1.2 使用ffi链接dll
demo:一个demo,快速入门
```
var ffi = require('ffi');
var libm = ffi.Library('libm', {
'ceil': [ 'double', [ 'double' ] ]
});
libm.ceil(1.5);
```
1. 路径不对:window.__devices =
// "extraResources": {
// "from": "src/renderer/",
// "to": "",
// "filter": ["**/*","!**/*.js","!**/*.vue","!**/*.png","!**/*.scss","!**/idcard/*"]
// },
,
{
from: path.join(__dirname, '../src/renderer'),
to: path.join(__dirname, '../dist/electron/'),
ignore: ['**/*.js','**/*.vue','**/*.scss','**/*.png','**/idcard/*.*']
}
