Closed zgpio closed 5 months ago
复现方法
ts-node .\winapi_reproduce.ts
// ts-node .\winapi_reproduce.ts import { funcConstructor, load, DataType, open } from "ffi-rs";
open({ library: "user32", // key path: "user32.dll", // path });
const HWND = DataType.U64; const LPARAM = DataType.I32; export async function enumChildWindows(hwnd: number) { const rv: Array = []; const func = (a: number, b: any) => { console.log(a=${a} b=${b}); rv.push(a); }; const rr = await load({ library: "user32", funcName: "EnumChildWindows", runInNewThread: true, retType: DataType.U64, paramsType: [ HWND, funcConstructor({ paramsType: [HWND, LPARAM], retType: DataType.Boolean, }), LPARAM, ], paramsValue: [hwnd, func, 0], }); return rv; } enumChildWindows(0);
a=${a} b=${b}
funcConstructor创建的函数不会被自动释放,readme中有提到。下个版本将会提供手动释放指针数据内存的函数
参考最新的test.js中关于funconstructor的部分有提到如何释放内存
复现方法
ts-node .\winapi_reproduce.ts
,运行之后程序没有自动终止open({ library: "user32", // key path: "user32.dll", // path });
const HWND = DataType.U64; const LPARAM = DataType.I32; export async function enumChildWindows(hwnd: number) { const rv: Array = [];
const func = (a: number, b: any) => {
console.log(
a=${a} b=${b}
); rv.push(a); }; const rr = await load({ library: "user32", funcName: "EnumChildWindows", runInNewThread: true, retType: DataType.U64, paramsType: [ HWND, funcConstructor({ paramsType: [HWND, LPARAM], retType: DataType.Boolean, }), LPARAM, ], paramsValue: [hwnd, func, 0], }); return rv; } enumChildWindows(0);