[racket] Access c based dll through ffi

From: Danny Yoo (dyoo at hashcollision.org)
Date: Thu Feb 14 16:09:31 EST 2013

the errno are not so descriptiv. By the way, how can I make a printf
in dll visible through rackets ffi. When I make this for my function
>
> (define-dreamlog DisplayHelloFromDLL (_fun  -> (r : _void)))
>
> and eval (DisplayHelloFromDLL)
>
> I get nothing or I rewrite the function which returns a char or whatever, isnt it so?

Have you tried flushing the output buffer in your C code?


Since Racket's not aware of the output buffers on the foreign side of
things, you will probably not see the output of your program on the
DLL side of things until something like "exit" happens.

For example, in:

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

If I rip out the 'fflush' in:

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

and run the test program,

    https://github.com/dyoo/ffi-tutorial/blob/master/ffi/tutorial/examples/hello/test-hello.rkt

then I can get very strange-looking results:

########################
$ racket test-hello.rkt
before
after
Danny says: hello!
########################

The fflush, then, is necessary, since Racket doesn't know at all about
the foreign output buffering.

Posted on the users mailing list.