Sunday, April 1, 2012

VLDB Code Example: Registry Functions

Basic examples of VLISP registry functions (vl-registry-write) and (vl-registry-read).  Note the double backslashes, which is common for escaped string characters in LISP...

(vl-registry-write "HKEY_CURRENT_USER\\Example1" "FOO" "123")

Result: "123"

(vl-registry-read "HKEY_CURRENT_USER\\Example1" "FOO")

Result: "123"

(vl-registry-read "HKEY_CURRENT_USER\\Example1")

Result: nil

(vl-registry-write "HKEY_CURRENT_USER\\Example2" "" "ABCDEF")

Result: "ABCDEF"

(vl-registry-read "HKEY_CURRENT_USER\\Example2")

Result: "ABCDEF"

A simple abstracted "get" and "set" function pair using a custom Registry base location...

(setq G$REGROOT "HKEY_CURRENT_USER\\Software\\MyApplication\\")

(defun RegGet (key default / val)
    (if (= nil (setq val (vl-registry-read (strcat G$REGROOT key))))
        (progn
            (RegSet key default)
            (setq val (vl-registry-read (strcat G$REGROOT key)))
        )
    )
    (if val val default)
)

(defun RegSet (key val)
    (vl-registry-write (strcat G$REGROOT key) "" val)
)

No comments: