How to call local .dll files in Electron App

2020-05-19 09:32发布

问题:

i have an issue how to call sample .dll files into my Electron App. I have sample .dll files in my folder, the thing is how to access my sample.dll file and how to call my sample.dll function and gets results. Any tutorials or steps to follow please sample code to start

回答1:

Calling into a .dll in Electron is no different to calling into one in plain NodeJS, which means you have two options, node-ffi or a native Node addon that links with your .dll and exposes a JavaScript API. If you decide to create a native Node addon you will need to build it to target Electron.

Here are some links that cover these topics:

  • node-ffi vs. node extension for accessing existing C++ functionality
  • Call C++ library from Node.js (Node addons / node-ffi)
  • https://github.com/node-ffi/node-ffi/wiki/Node-FFI-Tutorial
  • https://blog.scottfrees.com/calling-native-c-dlls-from-a-node-js-web-app
  • http://blog.scottfrees.com/building-an-asynchronous-c-addon-for-node-js-using-nan


回答2:

Electron-Edge helps to run .NET in Node.js on Electron.
You can find it on GitHub.
Here it is explained how to use dll files in it.(Scroll Down a little to find 'If you prefer to pre-compile your C# sources to a CLR assembly you can reference a CLR assembly from your Node.js code...'