[Question] Struct width function in his fields
Romakita opened this issue · comments
Romain Lenzotti commented
Hello guys,
To begin, thanks for your awesome library :D.
I works libphoto2 integration inside nodejs module, and one the function used by libphoto2 require a complex structure like that:
typedef struct _CameraFileHandler {
// int (*size) (uint64_t *size); /* only for read? */
int (*read) ( unsigned char *data, uint64_t *len);
// int (*write) ( unsigned char *data, uint64_t *len);
} CameraFileHandler;
I tried to define a StructType like that:
const {refType} = require("ref");
const RefCB = refType("void");
const ffi = require("ffi-napi");
const StructCameraFileHandler = StructType({
read: RefCB
});
const driver = ffi.Library("libgphoto2", {
gp_file_new_from_handler: ["int", [refType(StructCameraFileHandler)]],
});
const file = new StructCameraFileHandler();
file.read = ffi.Callback("int", [StructPriv, types.CString, "int"], (data, length) => {
console.log(data, length);
});
driver.gp_file_new_from_handler(file.ref());
But, my callback is never called. I'm not sure if the structure is correctly configured with ffi and ref-struct.
Do you have any idea ?
Thanks in advance ;)
See you,
Romain