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 |
I think you're getting confused between parameter types and instances.your attach_function call should be:attach_function :GetMyString, [ :long, :pointer, :pointer ], :voidAnd 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_refsize = size_ref.read_intstring = 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 ], :voidI got a "can't resolve type" error when I tried that.What's the correct way to do it?Thanks,Rob