Dll files are dynamic link libraries that are often used in desktop software.

    The library is not integrated into the framework because many tools are installed. However, this article provides complete installation instructions for your reference.

    1:Prepare the environment

    1. # Compiler
    2. npm i -g node-gyp
    3. # C + + build tools
    4. 1. Open PowerShell in administrator mode
    5. 2. npm --vs2015 i -g --production windows-build-tools
    6. or npm i -g --production windows-build-tools
    7. # External interface call library
    8. 1. npm install ref-napi // Basic type
    9. 2. npm install ref-array-napi // Array type
    10. 3. npm install ref-struct-napi // Structure type
    11. 4. npm install ffi-napi // Connecting C code and JS code
    12. # Compile ref-napi Library
    13. 1. cd ./node_modules/ref-napi
    14. 2. node-gyp configure
    15. 3. node-gyp build
    1. test Code ``` const ffi = require(‘ffi-napi’); var ref = require(‘ref-napi’); var ArrayType = require(‘ref-array-napi’);

    /**

    • exec dll file */ async execDll () { // Resource path let dllPath = ‘’; const dllFile = ‘myDllDemo.dll’; if (electronApp.isPackaged) { // After packing
      dllPath = path.join(this.app.config.execDir, “resources”, “extraResources”, “dll”, dllFile); } else { // Before packing dllPath = path.join(this.app.config.execDir, “build”, “extraResources”, “dll”, dllFile); }

      // Mapping to C language int array type var IntArray = ArrayType(ref.types.int);

      // Load the DLL file without writing the extension, and map the functions in the DLL to JS methods const MyDellDemo = new ffi.Library(dllPath, { // Method name must be consistent with C function name add: [ ‘int’, // Corresponding C function return type [‘int’, ‘int’] // C function parameter list ], // Use the shorthand type of the built-in type in FFI addPtr: [‘void’, [‘int’, ‘int’, ‘int*’]],

      initArray: [‘void’, [IntArray, ‘int’]] });

      const res = MyDellDemo.add(1, 2); console.log(add method result of 1 + 2 is: + res);

      var intBuf = ref.alloc(ref.types.int, 100); console.log(‘addPtr Data before call>>’, ref.deref(intBuf)); MyDellDemo.addPtr(2, 2, intBuf); console.log(‘addPtr Post call data>>’, ref.deref(intBuf));

      let myArray = new IntArray(8); MyDellDemo.initArray(myArray, 8); console.log(‘Initialization array execution result:’); for (var i = 0; i < myArray.length; i++) { console.log(myArray[i]); }

      return true; } ```

    1. the location of the dll file used for the test:
      1. ./build/extraResources/dll/myDllDemo.dll

    注:引用 https://blog.csdn.net/paopao_wu/article/details/107507225