There are two ways to invoke DLL files in NodeJS:
If you have experience in c++ development, you can directly watch Electron call a DLL using the NodeJS extension module
Second: through node-ffi module, the following content is about through this module to call, suitable for front-end development of students
- Switch to Taobao source and install relevant environment dependencies
- Python (v2.7, 3.x not supported);
- Visual C++ Build Tools visual C++ Build Tools
- .NET Framework 4.5.1 or implementation (recommended)
Install –global –production Windows-build-tools NPM install –global –production Windows-build-tools
- Installation node – gyp
npm install -g node-gyp
Then installnpm install ffi --save
Here we go:
- Cannot find moudule(There is a problem with the path of the environment variable)
Other users of Node-gyp have suggested a solution to this problem. There are two possible solutions to this problem. One is to roll back the node version to 8, and the other is to set the path to the variable.
Windows: >set npm_config_node_gyp=C:\Program Files\nodejs\node_modules\ NPM \node_modules\node-gyp\bin\node-gyp.js// I can't use it in powershell, the command doesn't work, CMD can, set your actual path here)
- TLS authentication error
Github.com/nodejs/node…(Solution, cancel TLS certificate verification)
setNODE_TLS_REJECT_UNAUTHORIZED=0 // Run another onesetThe commandCopy the code
- Error :MSB4019: Imported project not found… (Path again)
Instead of executing the NPM install ffi –save command, I’ll pull the module directly from the Git repository. (Skip this step if there is no such problem.)
git clone git://github.com/node-ffi/node-ffi.git
cdNode-ffi node-gyp rebuild // If this is to be used in electron, add parametersCopy the code
Create a new app.js file in the current directory as follows:
const ffi = require("node-ffi");
const User32 = ffi.Library('user32', {
'GetWindowLongPtrW': ['int'['int'.'int']],
'SetWindowLongPtrW': ['int'['int'.'int'.'long']],
'GetSystemMenu': ['int'['int'.'bool']],
'DestroyWindow': ['bool'['int']] }) console.log(User32.DestroyWindow(1000)); / / returnfalse
Copy the code
Nodeapp.js = ref ref-struct = ref ref-struct = bingdings Ref and FFI both need to execute node-gyp rebuild in the current directory and then copy the folder to the nodemodules directory.
-
Error: App.js error: App.js error: App.js error: app.js
The Node version of the rebuild package is different from the Node version of the electron package. You should specify the electron version when compiling these packages. perform
Node - gyp rebuild - target = holdings - arch = x64 - dist - url = HTTP: / / https://atom.io/download/electron
Then put the corresponding package into nodemoudles. But don’t look directly at the package.json when you specify the electron version. I’m showing ^4.0.1 here. The downloaded module version is >=4.0.1 so it’s not the actual version number. -
In package.json, add the dependency package information after the rebuild. Otherwise, an error will be reported. According to other netizens, these dependencies will be downloaded again when packaging
The relevant data
Blog.csdn.net/liyangyang0…
Blog.csdn.net/wang8393059…