There is a struct in .h
file:
struct usb_relay_device_info
{
char *serial_number;
char *device_path;
intptr_t /*enum usb_relay_device_type*/ type;
struct usb_relay_device_info* next;
};
and typedef
:
typedef struct usb_relay_device_info *pusb_relay_device_info_t;
and header of function I want to call:
pusb_relay_device_info_t USBRL_API usb_relay_device_enumerate(void);
I'm trying to call this function with node-ffi
, so I've made:
var ref = require('ref');
var ffi = require('ffi');
var Struct = require('ref-struct');
var charPtr = ref.refType(ref.types.char);
var intPtr = ref.refType(ref.types.int);
var deviceInfo = Struct()
var deviceInfoPtr = ref.refType(deviceInfo);
deviceInfo.defineProperty('serial_number', charPtr);
deviceInfo.defineProperty('device_path', charPtr);
deviceInfo.defineProperty('type', intPtr);
deviceInfo.defineProperty('next', deviceInfoPtr);
var pusb_relay_device_info_t = ref.refType(deviceInfo);
var usbLib = ffi.Library('USB_RELAY_DEVICE_64.dll', {
'usb_relay_device_enumerate': [pusb_relay_device_info_t, []]
});
Calling function usbLib.usb_relay_device_enumerate()
returns buffer <Buffer@0x000002AB786E2100 28 21 6e 78 ab 02 00 00 40 24 bd 99 fb 7f 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00>
, but I don't know how can I cast this result to javascript object, and read serial_number
or device_path
properties.