[plt-scheme] 2 troubles with FFI

From: Ivan Boulanov (l00bis at mail.ru)
Date: Thu Mar 30 13:55:24 EST 2006

So, here is the first one:
When I try to call Scheme procedure from C I get a strange message from 
MzScheme.
The source is:

(require (lib "foreign.ss"))
(unsafe!)
(define my-lib
  (ffi-lib "mydll"))

;The function takes an expression, produces output and if something goes 
wrong calls error callback
(define calc
  (get-ffi-obj "Calculate" my-lib (_fun _string -> _double)))

;This function takes callback function as it`s input. Callback function 
takes an error message produced by C dll as the argument.
(define set-error-callback
  (get-ffi-obj "setErrorCallback" my-lib (_fun (_fun _string -> _void) -> 
_void)))

;The callback itself
(define (error-callback message)
  (display "Error message:")
  (display message)
  (newline))

(set-error-callback error-callback)

;Here is typo in the expression so callback with error message have to be 
called.
(calc "27 + 4y2")

Everything goes ok up to the last string where such an error message is 
produced:
"Scheme->C: expects argument of type <non-void-C-type>; given #<ctype>"

I don`t understand what does MzScheme complains of.


The second trouble is not so critical but rather annoying.
I haven`t found a way to unload foreign library. So every time I modify 
dll`s source I need to close DrScheme to unlock attached dlls. And only then 
I can compile my foreign library. Garbage collection does not help.

Thanks in advance, Ivan Boulanov 



Posted on the users mailing list.