> (import (ironscheme ffi)) > (define dlload (pinvoke-call kernel32 LoadLibrary intptr (string))) > (define dlsym (pinvoke-call kernel32 GetProcAddress intptr (intptr string))) > (define ffitestlib (dlload "ffitest")) > (define cb (dlsym ffitestlib "fnfficallback")) > (define cb-sig (ffi-callout int32 (intptr))) > (define fnfficallback (cb-sig cb)) > (define fxplus ((ffi-callback int32 (int32 int32)) . (lambda (x y) . (printf "I got ~a and ~a\n" x y) . (fx+ x y)))) > > (fnfficallback fxplus) I got 10 and 30 40 > (define fxplus ((make-ffi-callback 'int32 '(int32 int32)) ; procedural interface . (lambda (x y) . (printf "I got ~a and ~a\n" x y) . (fx+ x y)))) > (fnfficallback fxplus) I got 10 and 30 40 > >
The C code is:
typedef int fxplus(int,int);
int fnfficallback(fxplus p)
{
return p(10,30);
}