Passing a pointer to a struct via Win32API to C Function

Hi

New to coding in Ruby and trying to pass a pointer to a struct into a
Win32API dll.

The C Function I’m calling is to read an array of struct values +
time-stamps + statuses from a hardware rotary encoder. When I try to
pass a pointer to this struct to the API, I get the following error:
“C:/Ruby193/lib/ruby/1.9.1/Win32API.rb:22:in `pack’: can’t convert Class
into String (TypeError)”.

Other calls to this API can be made successfully.

How should I be calling this function from the within Ruby? And how
should I be unpacking what’s returned?

Thanks

The C Function description is as follows:

ReadFIFOBufferStruct

Description:
This function reads the FIFO buffer records and copies the data into the
user allocated array of FIFOBufferRecord structure. The user is
responsible for creating the array and passing it’s pointer to this
function.

The plSize parameter identifies the number of records to read.

The allocated array of FIFOBufferRecord structure must be at least
plSize in length.

If the specified number of records are greater than the number of
records in the FIFO buffer,then only the records in the FIFO buffer are
read and copied. The plSize parameter will be changed to the number of
records that were copied.

This function returns when:
(a) the number of records read equals piSize or
(b) the FIFO buffer is empty or
© the timeout interval specified by ulReadTimeout has expired

C Language Function Prototype

int _stdcall ReadFIFOBufferStruct(short iDeviceNo, long *plSize,

FIFOBufferRecord *pFBR, unsigned long ulReadTimeout);

Returns:
Result code as an integer: See error code section for values other than
zero. Zero implies function call is successful.

Parameters:
iDeviceNo: identifies the USB4 device (zero based).
plSize: refer to description above.
pCBR: an array of FIFOBufferRecord.
ulReadTimeout: read timeout interval in milliseconds

Definition of Channel Buffer Record

struct USB4_FIFOBufferRecord { unsigned char Header[6]; unsigned char Input; unsigned char EStop; unsigned long Time; unsigned long Count[4]; unsigned char Status[4]; unsigned short ADC[4]; };

Maybe you can use ffi-swig-generator automatic convert c header file to
ruby code.

2014-03-10 10:33 GMT+08:00 Philip A. [email protected]: