electron调用dll文件
Posted 六道对穿肠
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了electron调用dll文件相关的知识,希望对你有一定的参考价值。
Electron 对系统层能力的使用可能比较弱,此时需要求助 Python、C++、C# 等语言,通过 ffi-napi 库可以让 Node.js 使用 C++ dll,通过 electron-edge-js 库可以让 Node.js 使用 C# dll
1. 先确定dll文件是用什么语言写的.
使用peid 应用查看- 这个是exe文件运行在windows电脑上.
2.软件查看结果,可以看到用的是c++ 开发的
查看nodejs是多少位
windows下: 打开cmd 输入命令 node 在输入process
3. 使用关键的库 ffi-napi 加上 ref-napi 调用dll
安装: https://github.com/node-ffi-napi/node-ffi-napi
npm install ffi-napi
npm install ref-napi
npm install ref-array-napi
npm install ref-array
如果出现安装报错
errorOut=warning ..\\..\\..\\..\\..\\package.json: No license field
gyp info it worked if it ends with ok
gyp info using node-gyp@9.1.0
gyp info using node@16.18.0 | win32 | x64
gyp info find Python using Python version 3.9.12 found at "C:\\ProgramData\\Miniconda3\\python.exe"
gyp info find VS using VS2022 (17.3.32929.385) found at:
gyp info find VS "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community"
gyp info find VS run with --verbose for detailed information
gyp info spawn C:\\ProgramData\\Miniconda3\\python.exe
gyp info spawn args [
gyp info spawn args 'C:\\\\Program Files\\\\nodejs\\\\node_modules\\\\npm\\\\node_modules\\\\node-gyp\\\\gyp\\\\gyp_main.py',
gyp info spawn args 'binding.gyp',
gyp info spawn args '-f',
gyp info spawn args 'msvs',
gyp info spawn args '-I',
gyp info spawn args 'C:\\\\Users\\\\liuda\\\\Documents\\\\GitHub\\\\pos-electron\\\\node_modules\\\\ref-napi\\\\build\\\\config.gypi',
gyp info spawn args '-I',
gyp info spawn args 'C:\\\\Program Files\\\\nodejs\\\\node_modules\\\\npm\\\\node_modules\\\\node-gyp\\\\addon.gypi',
gyp info spawn args '-I',
gyp info spawn args 'C:\\\\Users\\\\liuda\\\\.electron-gyp\\\\14.0.0\\\\include\\\\node\\\\common.gypi',
gyp info spawn args '-Dlibrary=shared_library',
gyp info spawn args '-Dvisibility=default',
gyp info spawn args '-Dnode_root_dir=C:\\\\Users\\\\liuda\\\\.electron-gyp\\\\14.0.0',
gyp info spawn args '-Dnode_gyp_dir=C:\\\\Program Files\\\\nodejs\\\\node_modules\\\\npm\\\\node_modules\\\\node-gyp',
gyp info spawn args '-Dnode_lib_file=C:\\\\\\\\Users\\\\\\\\liuda\\\\\\\\.electron-gyp\\\\\\\\14.0.0\\\\\\\\<(target_arch)\\\\\\\\node.lib',
gyp info spawn args '-Dmodule_root_dir=C:\\\\Users\\\\liuda\\\\Documents\\\\GitHub\\\\pos-electron\\\\node_modules\\\\ref-napi',
gyp info spawn args '-Dnode_engine=v8',
gyp info spawn args '--depth=.',
gyp info spawn args '--no-parallel',
gyp info spawn args '--generator-output',
gyp info spawn args 'C:\\\\Users\\\\liuda\\\\Documents\\\\GitHub\\\\pos-electron\\\\node_modules\\\\ref-napi\\\\build',
gyp info spawn args '-Goutput_dir=.'
gyp info spawn args ]
gyp: name 'openssl_fips' is not defined while evaluating condition 'openssl_fips != ""' in binding.gyp while trying to load binding.gyp
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack at ChildProcess.onCpExit (C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\lib\\configure.js:284:16)
gyp ERR! stack at ChildProcess.emit (node:events:513:28)
gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:293:12)
gyp ERR! System Windows_NT 10.0.19042
gyp ERR! command "C:\\\\Program Files\\\\nodejs\\\\node.exe" "C:\\\\Program Files\\\\nodejs\\\\node_modules\\\\npm\\\\node_modules\\\\node-gyp\\\\bin\\\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\\Users\\liuda\\Documents\\GitHub\\pos-electron\\node_modules\\ref-napi
gyp ERR! node -v v16.18.0
gyp ERR! node-gyp -v v9.1.0
gyp ERR! not ok
error Command failed with exit code 1.
command='C:\\Program Files\\nodejs\\node.exe' 'C:\\Users\\liuda\\AppData\\Roaming\\npm\\node_modules\\yarn\\bin\\yarn.js' run install
workingDir=C:\\Users\\liuda\\Documents\\GitHub\\pos-electron\\node_modules\\ref-napi
mac解决方案:
使用命令 xcode-select --install 解决问题
windwos解决方案
使用命令
// 以管理员身份运行终端执行命令
npm install --global --production windows-build-tools
安装好后继续使用上面的命令安装两个第三方库
windows环境(我用的虚拟机virtual box):
安装vs studio 桌面版C++
安装node 里面有个C++选项需要给选上
yarn build 打包报错:
全局安装cnpm
npm config set registry http://registry.npm.taobao.org/
npm i cnpm
安装windows平台编译环境
安装windows-build-tools
https://blog.csdn.net/weixin_46261309/article/details/105456830
virtualBox 复制粘贴功能
https://blog.csdn.net/weixin_41278720/article/details/79101590
其他
C# 安装 读取dll文件
项目地址 https://github.com/agracio/electron-edge-js
electron-edge-js
npm install electron-edge-js
以上是关于electron调用dll文件的主要内容,如果未能解决你的问题,请参考以下文章