Need to use some ffi napi in electron, and i trying to get it work, starting from small. Trying to understand and get ffi works, but cant get result. I know that i pass pointer to struct, into which the result will be written. But call return True and no result in the specified pointer. There is no new data. Please help with this.
const ffi = require("ffi-napi");
const ref = require("ref-napi");
const Struct = require("ref-struct-di")(ref);
const ABM_NEW = 0;
const ABM_QUERYPOS = 0x2;
const ABM_GETTASKBARPOS = 5; // 0x00000005
const ABM_GETSTATE = 0x4;
const ABEdgeLeft = 0;
const RECT_Struct = Struct({
left: "long",
top: "long",
right: "long",
bottom: "long",
});
const APPBARDATA_Struct = Struct({
cbSize: "uint32",
hWnd: "int",
uCallbackMessage: "uint32",
uEdge: "uint32",
rc: RECT_Struct,
lParam: "int64",
});
export const shell32 = ffi.Library("shell32.dll", {
SHAppBarMessage: ["long", ["int", APPBARDATA_Struct]],
});
export const user32 = ffi.Library("user32.dll", {
GetWindowRect: ["bool", ["long", RECT_Struct]],
});
const data = new APPBARDATA_Struct();
data.cbSize = APPBARDATA_Struct.size;
const result = shell32.SHAppBarMessage(ABM_GETTASKBARPOS, data);
const rect = new RECT_Struct();
const result2 = user32.GetWindowRect(0x20674, rect);
console.log(`result: ${JSON.stringify(result)}: ${JSON.stringify(data)}`);
console.log(`result2: ${JSON.stringify(result2)}: ${JSON.stringify(rect)}`);
with result
result: 1: {"cbSize":40,"hWnd":0,"uCallbackMessage":0,"uEdge":0,"rc":{"left":0,"top":0,"right":0,"bottom":0},"lParam":0}
result2: true: {"left":0,"top":0,"right":0,"bottom":0}
As i test, function call works - it return 1 (true) with hwnd existed window, and 0 if close. But i cant get result data from buffer and its make me mad.