Closed barbara012 closed 4 months ago
不需要加wrapPointer
不需要加wrapPointer
const pointer = createPointer({
paramsType: [Point],
paramsValue: [point],
});
这样吗? 还是闪退
不需要加 ffiTypeTag: DataType.StackStruct,
不需要加 ffiTypeTag: DataType.StackStruct,
const point = {
x: 0,
y: 0,
}
const Point = {
x: DataType.I32,
y: DataType.I32,
}
const pointer = createPointer({
paramsType: [Point],
paramsValue: [point],
});
const pos = load({
library: "user32",
funcName: "GetCaretPos",
retType: DataType.Boolean,
paramsValue: pointer,
paramsType: [DataType.External]
});
还是同样的问题
const Point = { x: DataType.I64, y: DataType.I64, } const pos = load({ library: "user32", funcName: "GetCaretPos", retType: DataType.Boolean, paramsValue: wrapPointer(pointer), paramsType: [DataType.External] });
给出完整代码
给出完整代码
let timer;
const point = {
x: 0,
y: 0,
}
const Point = {
x: DataType.I64,
y: DataType.I64,
}
const pointer = createPointer({
paramsType: [Point],
paramsValue: [point],
});
const getForegroundWindow = async () => {
const hwnd = load(
{
library: 'user32',
funcName: 'GetForegroundWindow',
retType: DataType.I32,
paramsType: [],
paramsValue: []
}
)
return hwnd
}
const getCaretPos = async () => {
const pos = load({
library: "user32",
funcName: "GetCaretPos",
retType: DataType.Boolean,
paramsValue: wrapPointer(pointer),
paramsType: [DataType.External]
});
return pos;
}
const loop = () => {
open({
library: 'user32', // key
path: 'user32.dll' // path
})
if (timer) {
clearInterval(timer);
}
timer = setInterval(async () => {
const hwnd = await this.getForegroundWindow();
console.log('hwnd', hwnd);
if (hwnd) {
const isCatch = await this.getCaretPos();
const p = restorePointer({
paramsValue: pointer,
retType: [Point],
})
console.log(isCatch, point, p);
// console.log(p)
}
}, 2000);
}
loop()
这里
给出完整代码
let timer; const point = { x: 0, y: 0, } const Point = { x: DataType.I64, y: DataType.I64, } const pointer = createPointer({ paramsType: [Point], paramsValue: [point], }); const getForegroundWindow = async () => { const hwnd = load( { library: 'user32', funcName: 'GetForegroundWindow', retType: DataType.I32, paramsType: [], paramsValue: [] } ) return hwnd } const getCaretPos = async () => { const pos = load({ library: "user32", funcName: "GetCaretPos", retType: DataType.Boolean, paramsValue: wrapPointer(pointer), paramsType: [DataType.External] }); return pos; } const loop = () => { open({ library: 'user32', // key path: 'user32.dll' // path }) if (timer) { clearInterval(timer); } timer = setInterval(async () => { const hwnd = await this.getForegroundWindow(); console.log('hwnd', hwnd); if (hwnd) { const isCatch = await this.getCaretPos(); const p = restorePointer({ paramsValue: pointer, retType: [Point], }) console.log(isCatch, point, p); // console.log(p) } }, 2000); } loop()
这里
结果输出的坐标和原始值一样{x: 0, y: 0}
看起来没什么问题,你应该根据GetCaretPos的返回值以及调用load方法时设置errno:true来自行debug
看起来没什么问题,你应该根据GetCaretPos的返回值以及调用load方法时设置errno:true来自行debu
看起来没什么问题,你应该根据GetCaretPos的返回值以及调用load方法时设置errno:true来自行debu 加上了,GetCaretPos 的返回值是 true,也没有报错。就是 pointer 的值没发生变化
getcarepos的返回值是int而不是boolean,你应该去查询这个函数的文档来根据errno信息debug
谢谢,我会了
问题定位了吗
Current ffi-rs version
Current Node.js arch
x64 win32
Descibe your problem in detail
这行 restorePointer 会导致程序闪退(提示: [12828:0704/002445.028:ERROR:crashpad_client_win.cc(868)] not connected)
What's your expect result
期望得到 caret 的坐标,如果有的话
The reproduction repo address