调用动态链接库

runwu2204 Lv6

https://nongchatea.gitbook.io/koffi-chinese

example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const koffi = require('koffi');

// Load the shared library
const lib = koffi.load('user32.dll');

// Declare constants
const MB_OK = 0x0;
const MB_YESNO = 0x4;
const MB_ICONQUESTION = 0x20;
const MB_ICONINFORMATION = 0x40;
const IDOK = 1;
const IDYES = 6;
const IDNO = 7;

// Find functions
const MessageBoxA = lib.func('__stdcall', 'MessageBoxA', 'int', ['void *', 'str', 'str', 'uint']);
const MessageBoxW = lib.func('__stdcall', 'MessageBoxW', 'int', ['void *', 'str16', 'str16', 'uint']);

let ret = MessageBoxA(null, 'Do you want another message box?', 'Koffi', MB_YESNO | MB_ICONQUESTION);
if (ret == IDYES)
MessageBoxW(null, 'Hello World!', 'Koffi', MB_ICONINFORMATION);

module.exports = {
returnANumber() {
return dll.returnANumber();
}
}

较方便的调用

用类似于c函数声明的格式

1
2
3
const printf = lib.func('int printf(const char *fmt, ...)');
// The parameter name is not used by Koffi, and optional
const atoi = lib.func('int atoi(str)');
  • 标题: 调用动态链接库
  • 作者: runwu2204
  • 创建于 : 2024-05-07 16:37:37
  • 更新于 : 2024-05-07 18:51:37
  • 链接: https://runwu2204.github.io/2024/05/07/开发/Electron/调用动态链接库/
  • 版权声明: 本文章采用 CC BY-NC-SA 4.0 进行许可。
评论
目录
调用动态链接库