[plt-scheme] passing a buffer to the FFI

From: Pedro Pinto (pedro.e.pinto at gmail.com)
Date: Thu Mar 15 01:52:36 EDT 2007

Hi there,

I am trying to wrap a MacOS api call which expects, among other  
arguments, a pointer to a pre-allocated array of bytes. Upon return  
the routine will fill the array with a utf-8 encoded string which I  
would like to convert to a Scheme string:

    CFIndex CFStringGetBytes (
      CFStringRef theString,
      CFRange range,
      CFStringEncoding encoding,
      UInt8 lossByte,
      Boolean isExternalRepresentation,
      UInt8 *buffer,                                // <----- Pre- 
allocated buffer
      CFIndex maxBufLen,
      CFIndex *usedBufLen

How do I do this with the FFI? The buffer size is not know until run- 

Thanks in advance,

Posted on the users mailing list.