Subject: [ruby-ffi] Dealing with pointers and in/out struct params |
From: Daniel Berger |
Date: 6/29/12 8:09 PM |
To: ruby-ffi |
Hi,
There's a function called ReadFileScatter in the Windows API that
takes an OVERLAPPED structure as its last (in/out) parameter. It looks
like this, keeping in mind that I've simplified it a bit to only
contain the bits I care about, and it is the right size - 20.
class Overlapped < FFI::Struct
layout(
:Internal, :pointer,
:InternalHigh, :pointer,
:Offset, :ulong,
:OffsetHigh, :ulong,
:hEvent, :ulong
)
end
The member I happen to care about specifically is :Internal, which the
MSDN docs will tell you is a ULONG_PTR (either an unsigned long or
unsigned int64, depending on whether or not you're x64).
I created an instance using Overlapped.new and passed it to
ReadFileScatter, which I can call successfully. The problem is that
the overlap[:Internal] member isn't populated after the call. I also
tried explicitly setting the :Internal member to an
FFI::MemoryPointer.new(:ulong) before passing the struct, but that
didn't seem to help.
How do I get FFI to populate my overlapped struct's pointer?
Regards,
Dan