1.开发问题: 使用C#的动态链库
2.开发环境: electron12 + vue2 + node14
{
"electron": "^12.2.3",
"vue": "^2.6.12",
"node": "^14.21.3"
}
*electron版本控制好,不然会有很多bug
3.解决问题:
1): npm 下载库 { "electron-edge-js": "^19.0.0" };
const edge = require('electron-edge-js');
//dll库的地址
const dll_url = process.env.NODE_ENV == "development"
? "./resources/dll/xx.dll" //开发路径
: process.resourcesPath + '/dll/xx.dll' //正式路径
//使用edge
const NationEcTrans = edge.func({
assemblyFile: dll_url,//dll地址
typeName: "Library1.Class1",// 类库名.类
methodName: "test1"//方法名
})
//如果没有 类库名.类 的话可能得重新写一个dll,去引入所需dll,按照下面示例
2): 动态库dll实例
using System;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using System.Text;
namespace Library1
{
public class Class1
{
public async Task<object> test1(string str)
{
return "参数" + str;
}
}
}
*electron 32位才能调用32位dll