Skip to content
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

[Question] Struct width function in his fields #33

Open
Romakita opened this issue Aug 20, 2018 · 0 comments
Open

[Question] Struct width function in his fields #33

Romakita opened this issue Aug 20, 2018 · 0 comments

Comments

@Romakita
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant