-
Notifications
You must be signed in to change notification settings - Fork 75
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
How do I use complex data structures with ffi
, ref-struct
, and ref-array
?
#28
Comments
For instance 1, yes, use could use So your type for |
For instance 2, use const AUDIO_OS_DEVICES = StructType({
nNumberDevices: ref.types.int
})
AUDIO_OS_DEVICES.defineProperty('pDevices', RefArray(AUDIO_OS_DEVICES)) And then const osDevices = <?get os devices struct?>
const devices = osDevices.pDevices
devices.length = osDevices.nNumberDevices
console.log(devices) Let me know if that works out for you! |
Thanks mate! Instance 1 worked like a charm so I'm half-way there. I'm now working on Instance 2 and attempting to implement what you suggested. Here's what I've got: Struct definition
Usage
ResultWhen I run this code I get the following error:
I feel like this is so close! Thanks for all your help. |
Try changing: AUDIO_OS_DEVICES.defineProperty('pDevices', ArrayType(AUDIO_OS_DEVICES)); to AUDIO_OS_DEVICES.defineProperty('pDevices', ArrayType(ref.refType(AUDIO_OS_DEVICES))); |
Well ... that looked promising but Electron just crashes. I checked the crash report and saw:
Not sure how much of that log would be relevant. |
And I did this:
|
Sorry, I misread the struct. I didn't realize that there are 2 different ones. Try it like this: const AUDIO_OS_DEVICES = StructType({
nNumberDevices: ref.types.int,
pDevices: RefArray(AUDIO_OS_DEVICE),
}); |
Using Complex Data Structures with
ffi
,ref-struct
, andref-array
I am working on a project that uses
ffi
to interact with a compiled C library. I am trying to get some complex data structures to work and am having problems figuring out the proper way to get values inside these data structures. I have two instances I'm trying to figure out. I am not a C guy so I'm winging it on that end.Instance 1
There is a C
struct
that contains properties that are, what look like pointers to character arrays. Here's the C-code that defines thestruct
:Now, I've been able to successfully extract the
E_CALL_STATE
value and theBOOL
properties but I'm having difficulty getting the strings stores incPhoneNumber
,cName
,cCallId
, andcPreviousCallId
. Here's how I have the it setup usingref-struct
:Here's the Javascript that interprets this
struct
(for reference,RPC_CALL_STATE
is an externally definedenum
):If I look at the value stored on
callProgressStruct.cPhoneNumber
, I get0
. So, a few questions:ref.types
to use here?char
correct?cPhoneNumber
?ref-array
here?Instance 2
I have a C
struct
that is defined as such:In this code,
*pDevices
ends up being an array ofAUDIO_OS_DEVICE
structs. Those structs are defined in C as:In Javascript I have this setup using
ref-struct
:I have no idea what type to cast
pDevices
to here nor do I know how to extract the array ofAUDIO_OS_DEVICE
structs. I am also hitting the issue already described with character arrays.Any help would be appreciated. I'm at a dead-end until I can figure this out.
The text was updated successfully, but these errors were encountered: