Open xmsz opened 1 year ago
Either fix the project to support uint8 or use an int instead. I'd just use int instead of bool
Either fix the project to support uint8 or use an int instead. I'd just use int instead of bool
ok
Either fix the project to support uint8 or use an int instead. I'd just use int instead of bool Here’s the translation of your request:
I've encountered the error Error: TypeError: error setting return value - buf.writeUInt8 is not a function
and am unsure how to resolve it.
Below is the related code:
const ffi = require("@breush/ffi-napi");
const ref = require("@breush/ref-napi");
function getUser32() {
if (user32) {
return user32;
}
user32 = ffi.Library("user32", {
EnumWindows: ["bool", ["pointer", "int32"]],
FindWindowW: ["int32", ["string", "string"]],
EnumChildWindows: ["bool", ["int32", "pointer", "int32"]],
GetWindowRect: ["bool", ["int32", "pointer"]],
GetClassNameW: ["int32", ["int32", "pointer", "int32"]],
IsWindowVisible: ["bool", ["int32"]],
EnumDisplayMonitors: ["bool", ["pointer", "pointer", "pointer", "int32"]],
GetMonitorInfoW: ["bool", ["int32", "pointer"]],
});
return user32;
}
// Method to get handles for all displays
function getAllDisplays() {
const monitors = [];
// Define MONITORINFO structure
const MONITORINFO = Buffer.alloc(40);
MONITORINFO.writeInt32LE(40, 0); // cbSize
const monitorEnumProc = ffi.Callback(
"bool",
["int32", "pointer", "pointer", "int32"],
(hMonitor) => {
if (getUser32().GetMonitorInfoW(hMonitor, MONITORINFO)) {
const left = MONITORINFO.readInt32LE(4);
const top = MONITORINFO.readInt32LE(8);
const right = MONITORINFO.readInt32LE(12);
const bottom = MONITORINFO.readInt32LE(16);
monitors.push({
...convertToXYWH({ rect: { left, top, right, bottom } }),
isPrimaryMonitor: isPrimaryMonitor(hMonitor),
workArea: convertToXYWH({ rect: getMonitorWorkArea(hMonitor) }),
});
}
return true; // Continue enumeration
}
);
getUser32().EnumDisplayMonitors(null, null, monitorEnumProc, 0);
return monitors;
}
console error
Error: TypeError: error setting return value - buf.writeUInt8 is not a function
at Object.proxy [as EnumDisplayMonitors] (D:\project\electron-screenshot\node_modules\@breush\ffi-napi\lib\_foreign_function.js:61:14)
at Object.getAllDisplays (D:\project\electron-screenshot\main\desktopWindows.js:76:15)
at MessagePort.<anonymous> (D:\project\electron-screenshot\main\worker-display.js:9:10)
at [nodejs.internal.kHybridDispatch] (node:internal/event_target:647:20)
at exports.emitMessage (node:internal/per_context/messageport:23:28)
]
How should I proceed to fix this?
code:
result
I saw this issuse https://github.com/node-ffi-napi/node-ffi-napi/issues/225#issuecomment-1361275385
And i change true to 1, false to 0, it works but no real a good solution
So how can i fix it