I use ffi(-napi) to run function, in a DLL, that returns a pointer on a C structure.
const structEl = new StructType({
label: string;
});
const structResult = StructType({
number_of_els: ref.types.int,
els: ref.refType(structEl);
});
I'm expecting els to be an array of structures. This question is about array of structures as a parameter but I could find no question about the returned value.
I am able to access the first element of the array, but I can't seem to access the following elements.
Am I doing anything wrong?
It took me a little while to figure this out because the full api doc of
refis missing.The buffer is allocated for only one structure by default (as it is a pointer), so you need to reallocate a buffer yourself, so that it not only points to the first element but goes further in the memory.
This is done using the
reinterpretmethod: