var wRoot = new ctypes.unsigned_long();
var wParent = new ctypes.unsigned_long();
var wChild = new ctypes.unsigned_long.ptr();
var nChildren = new ctypes.unsigned_int();
var rez = XQueryTree(_disp, w, wRoot.address(), wParent.address(), wChild.address(), nChildren.address())
if(rez != 0) { //can probably test this against `None` instead of `0`
var nChildrenCasted = ctypes.cast(nChildren, ctypes.unsigned_int).value;
for(var i=0; i<nChildrenCasted; i++) {
searchForPidStartingAtWindow(wChild[i]);
}
} else {
console.warn('this window has no children, rez:', rez);
}
I sucessfully get the nChildrenCasted
it's 94.
However I can't access wChild
elements, it should be an array
So problem is on the line: searchForPidStartingAtWindow(wChild[i]);
how to pass wChild[i]
?
I tried:
var wChildCasted = ctypes.cast(wChild, ctypes.unsigned_long).contents;
console.log('wChildCasted:', wChildCasted);
I'm pretty sure its along those lines but i cant figure it out
full code, can be copy pasted and run from scratchpad:
You need to cast from the raw pointer type to an ArrayType pointer:
var wChildCasted = ctypes.cast(wChild, ctypes.ArrayType(ctypes.unsigned_long, nChildrenCasted).ptr).contents;