[plt-scheme] Using the FFI with a scheme aware dll

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Tue Jun 27 21:10:35 EDT 2006

At Tue, 27 Jun 2006 22:17:54 +0200, Hans Oesterholt-Dijkema wrote:
> Now I've ported the code to something that can be used with
> the FFI, but I still need the "scheme_malloc", "scheme_make_type",
> etc. functions.
> 
> How can I load these in, [...]?

Starting with the current SVN code for v350.2, you can access them via
`(ffi-lib #f)'.

For earlier versions, unfortunately, the result of `(ffi-lib #f)' only
searches the exports of the process's .exe, where it finds practically
nothing. Here's old code from "mzssl.ss" (now removed) that finds the
MzScheme DLL:

  (require (lib "filename-version.ss" "dynext"))

  (define (ffi-lib-xxxxxxx name)
    (let* ([f (format "~a~a" name filename-version-part)])
      (or (with-handlers ([exn? (lambda (x) #f)])
            (ffi-lib (format "~a~a" name filename-version-part)))
	  (ffi-lib (format "~axxxxxxx" name)))))

  (define 3m? (regexp-match #rx#"3m" (path->bytes (system-library-subpath))))

  (define libmz
    (case (system-type)
      [(windows)
       (ffi-lib-xxxxxxx (format "libmzsch~a" (if 3m? "3m" "")))]
      [else (ffi-lib #f)]))


Matthew



Posted on the users mailing list.