Subject:
[ruby-ffi] ffi-swig generating a :string instead of a :pointer ??
From:
Stephen Bannasch
Date:
12/12/09 9:15 PM
To:
ruby-ffi@googlegroups.com

I have a C++ function that takes a pointer to a buffer where the function stores a C-string.

This is what I wrote and got working.

  attach_function :GoIO_GetNthAvailableDeviceName, [:pointer, :int, :int, :int, :int], :int

However if I use ffi-swig it generates a :string as the first parameter.

  attach_function :GoIO_GetNthAvailableDeviceName, [ :string, :int, :int, :int, :int ], :int

Is there anyway this could work? The function needs an address to a location to store a C-string.

Here's the C++ function:

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.