Subject: Re: [ruby-ffi] Pointer to a struct - how to cast? |
From: Chuck Remes |
Date: 5/20/10 1:48 PM |
To: ruby-ffi@googlegroups.com |
On May 20, 2010, at 1:00 PM, DA wrote:
Here's how I'm getting the array: // c struct: typedef struct { UIntT len; F_TextItemT *val; } F_TextItemsT; // ruby def: class FTextItemsT < FFI::Struct layout :len, :uint, :val, :pointer end // ruby code: tis = FM.FApiGetText(docid, flowid, (FM.FTIString | FM.FTILineEnd)); parr = tis[:val].read_array_of_pointer(tis[:len]) puts "tis len: #{tis[:len]}" The tis[:len] gives me the same value as calling this code in c, so I'm pretty sure the FApiGetText call is working and I'm getting a valid struct returned. Am I using read_array_of_pointer wrong?
That looks kind of funky to me. In the F_TextItemsT C struct, it shows *val which is just a single pointer. There is no array of pointers to read from at that location. I believe the syntax for arrays of pointers are more like: struct { int len; item_t **list; } Note the double-asterisk. Have you written this in C to see how to get each F_TextItemT? cr