-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError: error setting return value - buf.writeUInt8 is not a function when call EnumWindows #1
Comments
Either fix the project to support uint8 or use an int instead. I'd just use int instead of bool |
ok |
@lwahonen @xmszI've encountered the error 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 node-ffi-napi/node-ffi-napi#225 (comment)
And i change true to 1, false to 0, it works but no real a good solution
So how can i fix it
The text was updated successfully, but these errors were encountered: