All Manuals > LispWorks User Guide and Reference Manual > 14 LispWorks as a dynamic library

NextPrevUpTopContentsIndex

14.2 Creating a dynamic library

To deliver a LispWorks runtime as a dynamic library supply a list value for dll-exports when calling deliver.

To save a LispWorks image as a dynamic library supply a list value for dll-exports when calling save-image.

Additionally on Linux, x86/x64 Solaris, Macintosh and FreeBSD platforms, you can supply a list value for dll-added-files to deliver or save a dynamic library.

Note: a LispWorks dynamic library is licensed in the same way as a LispWorks executable.

14.2.1 C functions provided by the system

When LispWorks is a dynamic library the functions described in Dynamic library C functions are automatically available. They allow the loading process control over relocation and unloading of the library.

14.2.2 C functions provided by the application

dll-exports specifies application-defined exported functions in a LispWorks dynamic library.

Exports can also be provided in the files named in dll-added-files, on Linux, x86/x64 Solaris, Macintosh and FreeBSD platforms.

14.2.3 Example

This script saves an image hello.dll which is a Windows DLL:

-------------------- hello.lisp -------------------------
(in-package "CL-USER")
(load-all-patches)
;; The signature of this function is suitable for use with
;; rundll32.exe.
(fli:define-foreign-callable ("Hello"
                              :calling-convention :stdcall)
    ((hwnd w:hwnd)
     (hinst w:hinstance)
     (string :pointer)
     (cmd-show :int))
  (capi:display-message "Hello world"))
 
(save-image "hello"
            :dll-exports '("Hello")
            :environment nil)
---------------------------------------------------------

Run the script by

lispworks-7-1-0-x86-win32.exe -build hello.lisp

on the command line, or use the Application Builder tool.

(See Saving a LispWorks image for more information about how to save an image.)

You can test the DLL by running

rundll32 hello.dll,Hello

on the command line.

To see the dialog, you may need to dismiss the LispWorks splashscreen first.


LispWorks User Guide and Reference Manual - 20 Sep 2017

NextPrevUpTopContentsIndex