[cffi-devel] Dynamically call a certain function in a lib

Frank Goenninger frgo at me.com
Sun Dec 4 23:21:30 UTC 2011


Hi, 

I have:

(defun load-and-open-module (pathname)
  (let ((lib (cffi:load-foreign-library pathname)))
    (if lib
	(progn
	  (format t "~%LOAD-AND-OPEN-MODULE: ~s LOADED." lib)
	  (let ((handle (cffi:foreign-funcall `("open" :library ,lib) :pointer))) ;; <<--- Here's the challenge ...
	    (if (not (eql handle (cffi:null-pointer)))
	        (let ((module (make-instance 'pib-module
					     :lib (c-in lib)
					     :handle (c-in handle))))
		  (format t "~%LOAD-AND-OPEN-MODULE: module = ~s." module)
		  module)
		nil)
	  nil)))))

The marked line should load the "open" function in the just loaded foreign lib. As I intend to load multiple so-called modules where each module has an "open" function I /think/ I need to say which open() function to call (the loaded libs are C DLLs, mostly).

How do I name a certain foreign lib in the call to foreign-funcall when the library given is not evaluated ?

Thanks for any hints!

Cheers
    Frank





More information about the cffi-devel mailing list