Subject: Re: [ruby-ffi] How to specify size for returned buffer? |
From: Matijs van Zuijlen |
Date: 8/21/11 12:58 PM |
To: ruby-ffi@googlegroups.com |
I'm trying to wrap FreeImage (http://freeimage.sourceforge.net/) and
it has this function:
DLL_API BOOL DLL_CALLCONV FreeImage_AcquireMemory(FIMEMORY *stream,
BYTE **data, DWORD *size_in_bytes);
The way this works is you hand FreeImage a pointer (data) which it
then allocates memory for and returns the size in the size_in_bytes
out parameter. I've attached example C code from the FreeImage docs
in case it helps.
So I'm not sure how to wrap this function. So far I have this:
FreeImage.attach_function('FreeImage_AcquireMemory',
[:pointer, :pointer, :uint], :bool)
buffer = MemoryPointer.new(:pointer)
size_ptr = MemoryPointer.new(:uint)
FreeImage.FreeImage_AcquireMemory(self, buffer, size);
What I would then like to do is something like:
buffer.size = size_ptr.read_pointer()
But buffer doesn't have any such API.
Any help appreciated.
Thanks,
Charlie