Subject:
[ruby-ffi] basic question: function expects pointer to string buffer, returns string
From:
Stephen Bannasch
Date:
12/12/09 12:06 PM
To:
ruby-ffi@googlegroups.com

I've started working on a Ruby FFI interface to the Vernier GoIO sensor interface products.

See:

  http://www.vernier.com/go/
  http://www.vernier.com/downloads/gosdk.html   *the SDK is public domain

I've got a very basic question FFI question.

I have a C++ function that expects a pointer to a string buffer and a int32 specifying the size of the buffer.

The result of calling the function is a name of a connected device in the string buffer.

How should the call be setup and then processed on return to generate a Ruby string.

Here's the state of the code so far:  http://gist.github.com/254981

This is the specific function I have the question about:

GOIO_DLL_INTERFACE_DECL gtype_int32 GoIO_GetNthAvailableDeviceName(
  char *pBuf,            // [out] ptr to buffer to store device name string.
  gtype_int32 bufSize,   // [in] number of bytes in buffer pointed to by pBuf.
                         // Strlen(pBuf) < bufSize, because the string is NULL terminated.
  gtype_int32 vendorId,  // [in] USB vendor id
  gtype_int32 productId, //[in] USB product id
  gtype_int32 N);        //[in] index into list of known devices, 0 => first device in list.

Also, is there any rdoc for FFI?