electron+vue使用electronedge.dll换桌面壁纸

首先npm安装electron-edge-js依赖,使用方法如下

const edge = require('electron-edge-js')
console.info('call c#')

var DemoDll = edge.func({
  assemblyFile: 'electronedge.dll',
  typeName: 'electronedge.Class1',
  methodName: 'Invoke2'
})

module.exports.DemoDll = {
  demo: DemoDll
}

然后在main.js中引用

function init () {
  const DemoDll = require('./目标文件.js')
  return {
    demo: DemoDll.DemoDll.demo
    // demo2: DemoDll.DemoDll.demo2
  }
}
const initRequire = init()
initRequire.demo('需要设置的壁纸', (err, value) => {
  console.log(err, value)
})

很重要的一个文件,electronedge.dll,放置位置不能错,

否则会报错

此时需要检查文件路径是否正确。

最后运行,相关electronedge.dll文件可以到我的资源中查看下载

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
要在Electron + TypeScript + Vite项目中调用Everything.dll实现快速搜索,可以按照以下步骤进行操作: 1. 安装Everything软件并启动它,确保Everything.dll已经被正确安装。 2. 在项目中安装node-ffi和ref-napi,这两个模块可以帮助我们在Node.js中调用DLL函数。可以使用以下命令进行安装: ```bash npm install node-ffi ref-napi ``` 3. 创建一个名为everything.ts的TypeScript模块,并在其中定义我们要调用的Everything.dll函数。可以参考以下代码: ```typescript import { FFI } from 'ffi-napi'; /** * Everything.dll中的函数声明 */ export interface EverythingDLL extends FFI.Library { Everything_SetSearchW: (search: Buffer) => void; Everything_QueryW: (wait: number) => void; Everything_GetNumResults: () => number; Everything_GetResultFullPathNameW: (index: number, buf: Buffer, size: number) => number; Everything_CleanUp: () => void; } /** * 加载Everything.dll */ const everythingDll: EverythingDLL = FFI.Library('Everything.dll', { Everything_SetSearchW: ['void', ['pointer']], Everything_QueryW: ['void', ['int']], Everything_GetNumResults: ['int', []], Everything_GetResultFullPathNameW: ['int', ['int', 'pointer', 'int']], Everything_CleanUp: ['void', []], }); export default everythingDll; ``` 4. 在项目中使用everything.ts模块来进行搜索。可以参考以下代码: ```typescript import everythingDll from './everything'; /** * 搜索文件 * @param search 搜索关键字 * @returns 搜索结果数组 */ export function searchFiles(search: string): string[] { // 将搜索关键字转为UTF-16编码的Buffer const searchBuffer = Buffer.from(search, 'ucs2'); // 设置搜索关键字 everythingDll.Everything_SetSearchW(searchBuffer); // 执行搜索 everythingDll.Everything_QueryW(1); // 获取搜索结果数量 const resultCount = everythingDll.Everything_GetNumResults(); // 获取搜索结果 const results: string[] = []; for (let i = 0; i < resultCount; i++) { const buf = Buffer.alloc(4096); everythingDll.Everything_GetResultFullPathNameW(i, buf, buf.length); const result = buf.toString('ucs2'); results.push(result); } // 清理搜索结果 everythingDll.Everything_CleanUp(); return results; } ``` 5. 在Electron应用程序中使用searchFiles函数进行搜索。可以参考以下代码: ```typescript import { app, BrowserWindow } from 'electron'; import { searchFiles } from './everything'; function createWindow() { const win = new BrowserWindow({ width: 800, height: 600, webPreferences: { nodeIntegration: true, }, }); win.loadFile('index.html'); // 在渲染进程中使用searchFiles函数进行搜索 win.webContents.on('did-finish-load', () => { const results = searchFiles('test'); console.log(results); }); } app.whenReady().then(() => { createWindow(); app.on('activate', () => { if (BrowserWindow.getAllWindows().length === 0) { createWindow(); } }); }); app.on('window-all-closed', () => { if (process.platform !== 'darwin') { app.quit(); } }); ``` 这样就可以在Electron + TypeScript + Vite项目中调用Everything.dll实现快速搜索了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值