Subject:
[ruby-ffi] Re: attach_function syntax when input args are pointers to contain return values
From:
Rob Marshall
Date:
2/1/13 8:21 AM
To:
ruby-ffi@googlegroups.com

Yes, you're correct. And within minutes of hitting "SEND" on my post yesterday, I realized that...Sorry, must have been a "senior" moment :-)

Thanks,

Rob

On Thursday, January 31, 2013 6:12:32 PM UTC-5, Wayne Meissner wrote:
I think you're getting confused between parameter types and instances.

your attach_function call should be:

    attach_function :GetMyString, [ :long, :pointer, :pointer ], :void

And you would call it like:

    buffer = FFI::MemoryPointer.new(:char, 256)
    size_ref = FFI::MemoryPointer.new(:int, 1)

    MyGetString(x, buffer, size_ref)

    # in C: int size = *size_ref
    size = size_ref.read_int
    string = buffer.get_string(0, size)


On Friday, February 1, 2013 6:21:44 AM UTC+10, Rob Marshall wrote:
Hi,

My guess is that this has been asked before, but I didn't find it...not exactly sure what to search for...

Anyway, I am trying to attach functions that return :void but use the input parameters to hold the return values. e.g. A function that gets a value and returns it as a string and length. So say my C-function declaration is:

void GetMyString(const long reference, char *buffer, int *size)

My guess, and I'm sure it doesn't work because I tried it, was to do:

buffer = FFI::MemoryPointer.new(:char, 256)
size = FFI::MemoryPointer.new(:int,1)
attach_function :GetMyString, [ :long, buffer, size ], :void

I got a "can't resolve type" error when I tried that.

What's the correct way to do it?

Thanks,

Rob

--
 
---
You received this message because you are subscribed to the Google Groups "ruby-ffi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-ffi+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.