[racket] Access c based dll through ffi

From: Danny Yoo (dyoo at hashcollision.org)
Date: Wed Feb 20 14:01:07 EST 2013

On Wed, Feb 20, 2013 at 7:01 AM, Matthew Flatt <mflatt at cs.utah.edu> wrote:
> If you load this DLL via DrRacket, then you won't see output, because
> stdout isn't connected to anything in particular in a GUI appplication.
> That is, stdout at the C level is not redirected to the Racket current
> output port.


That being said, here is an example to show how to access the
scheme_printf_utf8 function from the C side:

    https://github.com/dyoo/ffi-tutorial/tree/master/ffi/tutorial/examples/hello-2


The key part of this is allowing the C code to access the
scheme_printf_utf8 function:

    http://docs.racket-lang.org/inside/Ports_and_the_Filesystem.html?q=scheme_printf_utf8#%28cpp._scheme_printf%29


by pulling it from the FFI:

    https://github.com/dyoo/ffi-tutorial/blob/master/ffi/tutorial/examples/hello-2/hello.rkt#L17


and passing it along as a function pointer:

    https://github.com/dyoo/ffi-tutorial/blob/master/ffi/tutorial/examples/hello-2/hello.rkt#L29


where the C code can use it:


     https://github.com/dyoo/ffi-tutorial/blob/master/ffi/tutorial/examples/hello-2/src/hello.c#L3

Posted on the users mailing list.