[plt-scheme] PLT Scheme FFI on Win32: handling structures and byte arrays

From: Jakub Piotr Cłapa (jpc-ml at zenburn.net)
Date: Wed Aug 6 07:41:18 EDT 2008

Elena Garrulo wrote:
> I'm trying out PLT Scheme FFI on WIn32. Examples included into the 
> distribution show only simpler cases.

IMHO the distribution could use some more elaborate examples. It's just 
that there is little code in the wild using the PLT Scheme FFI.

>             (pioSendPci : _SCARD_I0_REQUEST-pointer) ;; ERROR: expand: unbound variable in module in: __SCARD_I0_REQUEST-pointer

I guess it should be IO instead of I0.

>             (pbSendBuffer : (_cvector i _byte)) ;; ERROR: expand: unbound variable in module in: i

Should be _vector here, not _cvector.

>             (pbRecvBuffer :  (_cvector o _byte )) ;; ERROR: expand: unbound variable in module in: o

For output vectors you need the length so try this:
(pbRecvBuffer : (_vector o _byte cbRecvLength))
(cbRecvLength : (_ptr io _DWORD))

Quote from the manual:

The optional len argument is needed for output values where it is used 
in the post code, and in the pre code of an output mode to allocate the 
block. In either case, it can refer to a previous binding for the length 
of the list which the C function will most likely require.

Btw. Eli, as can be seen here we can refer to a following binding as 
well. Maybe the docs could use some clarification?

> And what about byte aligned, word aligned, double word aligned  
> structures? What about calling conventions?

Everything is handled by libffi.

Jakub Piotr Cłapa

Posted on the users mailing list.