The integrated cross-platform development tool for ANSI Common Lisp LispWorks logo

Lisp Knowledgebase



Title: How to create a DLL from an image

ID: 10022


Product: LispWorks for Windows
Version: 4.1, 4.2
OS: All Windows platforms

Description:
There is a new keyword argument (:DLL-EXPORTS) to the SAVE-IMAGE and DELIVER functions which controls this.

Normally an executable is created by SAVE-IMAGE or DELIVER, but passing the :DLL-EXPORTS argument to these functions causes it to create a DLL instead The value of dll-exports should be a list of strings naming the externals of the DLL. Each external name must be defined as a Lisp function by using FLI:DEFINE-FOREIGN-CALLABLE.

You can use LoadLibrary from the main application to load the DLL and GetProcAddress to find the address of the external names. Lisp multiprocessing is started when the DLL is loaded, so any initialization operations can be done by adding process specifications to MP:*INITIAL-PROCESSES* before creating the DLL.

E.g. use the script below (with lispworks.exe -init hello.lisp) to create hello.dll and then run it using "rundll32 hello.dll,Hello" from the command line. To see the dialog, you may need click on the LispWorks splashscreen first.

(in-package "CL-USER")

;; 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)

(quit)

See Also:
Workaround:
Patch:

Hardware:N/A
Summary:How to create a DLL from an image.
Bug#:
Patch Enhancement#:
Reported:5538

Top | Back