[plt-scheme] Using FFI with complex structures and input/output parameters?

From: Eli Barzilay (eli at barzilay.org)
Date: Wed Jul 1 10:36:09 EDT 2009

On Jul  1, Elena Garrulo wrote:
> 2009/7/1 Eli Barzilay <eli at barzilay.org>:
> > The problem is here:
> >
> >                ;; OUT BYTE* pbRecvBuffer
> >                (pbRecvBuffer :  (_vector o _byte cbRecvLength))
> >                ;; IN OUT DWORD* pcbRecvLength
> >                (cbRecvLength :  (_ptr io _DWORD))
> >
> > You can't use `cbRecvLength' like that.  You can use the `::'
> > marker, where you put all the arguments to the wrapper explicitly
> > at the front, but it still wouldn't work because the value that
> > `cbRecvLength' will be bound to is a pointer.
> Then, my question boils down to: with current FFI, can you use an
> input/output parameter which holds the size of a buffer?  For
> instance, a function like:
> void fill_buffer (BYTE* buffer, DWORD* buffer_size);
> where buffer_size holds:
> - size of buffer on input;
> - size of written data on output;
> has a mapping in FFI?

No.  It might have been possible to use it if the order was swapped,
but as the above you can't really do that in a similar way that you
can't really compile `letrec' into an order that resolves dependencies
automatically.  But you can use a simple `cblock->vector' in the
wrapper code.

          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!

Posted on the users mailing list.