Using RDNZL

NOTE: this tutorial may no longer work with recent versions of Allegro Common Lisp. This software is supported by Franz, Inc.

Go to the tutorial main page.

RDNZL (pronounced "Redunzl") is a Common Lisp interface to .NET. The software was developed by Dr. Edi Weitz and runs in several different Common Lisp implementations. This tutorial describes how to use RDNZL in Allegro CL.

Prerequisites

Quick Start 1: Install and Load RDNZL

  1. Download and install RDNZL.

    At this writing, RDNZL can be downloaded via the following link: http://weitz.de/files/rdnzl.tar.gz

    This file is an archive of the RDNZL files stored in "tar" format and compressed in "gzip" format. Various utilities exist to extract the contents from these types of archives. WinZip (http://www.winzip.com) is one such utility.

    If you already have the capability to extract the files, please do so now into the Allegro CL installation directory. Typically, this will be the following:

    c:\Program Files\aclxx

    Thus, the extracted files will be in the directory

    c:\Program Files\aclxx\rdnzl-xx

    (where 'xx' means version information).

    If you do not have the capability to extract the files using a third party utility, then you can do so with Allegro CL as follows.

    (require :inflate)
    (require :tar)
    
    ;; Here is where we specify the location of the downloaded file.
    ;;
    (defparameter *downloaded-rdnzl-file* "c:/temp/rdnzl.tar.gz")
    
    ;; Creates c:\Program Files\aclxx\rdnzl-xx
    ;;
    (let ((tar-file (sys:make-temp-file-name "tgze")))
      (unwind-protect
          (progn
    	(with-open-file (in *downloaded-rdnzl-file*)
    			(util.zip:skip-gzip-header in)
    			(with-open-file (out tar-file :direction :output)
    					(util.zip:inflate in out)))
    	(with-open-file (in tar-file)
    			(util.tar:extract-tar in :directory #p"sys:" :verbose t)))
        (delete-file tar-file)))
    

    At this point, you should have a directory

    c:\Program Files\aclxx\rdnzl-xx

    (where 'xx' means version information).

  2. Move RDNZL.dll

    The extracted RDNZL files should include a file named RDNZL.dll. This file needs to be moved or copied to a place where Lisp can load it automatically. The best place is to have RDNZL.dll be in the Allegro CL installation directory. This can be accomplished within Lisp as follows:

    (let ((*default-pathname-defaults*
           (translate-logical-pathname #p"sys:")))
      (sys:copy-file #p"rdnzl-xx/RDNZL.dll"
           #p"RDNZL.dll"))
    

    where 'xx' is the rdnzl version information.

    At this point, RDNZL is installed and ready to use.

  3. Load RDNZL

    The following loads RDNZL into Lisp:

    (let ((*default-pathname-defaults*
           (translate-logical-pathname #p"sys:")))
      (load #p"rdnzl-xx/load.lisp"))
    

    where 'xx' is the rdnzl version information.

Example 1: Displaying a message box

(in-package :rdnzl-user)

(enable-rdnzl-syntax)

(import-types "System.Windows.Forms"
	      "MessageBox" "MessageBoxButtons" "DialogResult")

(use-namespace "System.Windows.Forms")

(defun message-box (text &optional (caption "RDNZL"))
  ;; check if the "OK" button was pressed
  [Equals [MessageBox.Show text caption
		      ;; we want the message box to have "OK" and
		      ;; "Cancel" buttons
		      [$MessageBoxButtons.OKCancel]]
	  [$DialogResult.OK]])

(message-box "Hello World!") ;; user presses "OK" button
  [returns] t

(message-box "Hello World!") ;; user presses "Cancel" button
  [returns] nil

Example 2: Apropos dialog

This example uses a .NET assembly called AproposGui.dll. This file and its source, AproposGui.cs, are located in the RDNZL examples/ directory.

AproposGui.dll needs to be moved or copied to a place where Lisp can load it automatically. The best place is to have AproposGui.dll be in the Allegro CL installation directory. This can be accomplished within Lisp as follows:

(let ((*default-pathname-defaults*
       (translate-logical-pathname #p"sys:")))
  (sys:copy-file #p"rdnzl-xx/examples/AproposGui.dll"
       #p"AproposGui.dll"))

where 'xx' is the rdnzl version information.

You can then load examples/apropos.lisp as follows:

(let ((*default-pathname-defaults*
       (translate-logical-pathname #p"sys:")))
  (load #p"rdnzl-xx/examples/apropos.lisp"))

You can run the apropos example as follows:

(in-package :rdnzl-user)
   
(run-apropos-form)

This function returns when the window (apropos dialog) is closed. You can run this function in a separate Lisp process as follows:

(mp:process-run-function "apropos" #'run-apropos-form)

Other RDNZL Examples

The rdnzl examples folder contains further examples including how to interface to Microsoft Office if you happen to have it installed on your computer.

Return to the tutorial main page.