Subject:
Re: [ruby-ffi] Re: Link to non-windows dlls
From:
Kevin Vanden Berge
Date:
10/23/10 10:51 AM
To:
ruby-ffi@googlegroups.com

I think I'm missing something...
"Traditionally with pointers you’ll have a method, like attach_function :GetForeGroundWindow, [ ], :pointer
What this returns to you is a pointer that, probably, some other library is managing. You don’t need to release this pointer or anything."

I took that to mean I don't have to do anything special for it.  Are you suggesting I do something like:

buf = MemoryPointer.new(1024)
buf = UsbLibrary.Receive(a,1000)

On Sat, Oct 23, 2010 at 11:41 AM, Luis Lavena <luislavena@gmail.com> wrote:
On Sat, Oct 23, 2010 at 12:33 PM, Kevin Vanden Berge
<kvandenberge@gmail.com> wrote:
> The SegFault occurs when I put the call of UsbLibrary.Receive(a,1000) in the
> test_usb.rb script.  Changing the Send parameter from :pointer to :string
> has no effect on the outcome.  As for why I did pointer instead of string, I
> have no good reason except that I saw an example of a wrapper to a C
> function that had a char* as parameter and it was done using :string and
> then another example showed it using :pointer another time.
>

For you to receive in a pointer you need to allocate memory for that buffer.

http://github.com/ffi/ffi/wiki/Pointers

--
Luis Lavena
AREA 17
-
Perfection in design is achieved not when there is nothing more to add,
but rather when there is nothing more to take away.
Antoine de Saint-Exupéry