Demand Loading a LISP File


The registry demand loading feature in AutoCAD, Bricscad, and ZWCAD is a great method for loading ObjectARX/BRX/ZRX modules automatically at startup, and it's relatively easy to create the demand loading settings from an installation program or MSI file at install time. Unfortunately it only works for ARX/BRX/ZRX files (and also with .NET dlls in AutoCAD 2006 and later). Some years ago, I created a small ARX module called VLXLoad. The purpose of this module was to work as a stub to load an associated .vlx file of the same base name in the same folder. I've since renamed this small utility to LspLoad and expanded it so that it can load any type of LISP file. The idea is to rename the LspLoad.*.* file to the name of the associated .lsp/.vlx/.fas file (i.e. MyApp.18.arx will look for and load MyApp.vlx in the same directory), then create demand load registry settings to load the renamed LspLoad module. Voila, the associated LISP file gets loaded as if it was being demand loaded from the registry.

The LspLoad source code demonstrates an important technique that I often see questions about in Autodesk's ObjectARX discussion group: how to get the full path to the ARX file from code within the file. The secret is to use the Windows API function GetModuleFileName(), passing as its first argument the current module instance handle, which is available in an ObjectARX module as _hdllInstance (note that it's _hd, two lower case L's, then followed by an upper case I for Instance).

I've uploaded here the complete source code along with a solution file for Visual Studio 2017. The solution requires environment variables defined as described here. You'll need to have Daffodil for Visual Studio installed if you're using Visual Studio IDE version VS 2013 or earlier, and you'll additionally need the platform target version of Visual Studio installed to build the various projects targeting different platforms. If you just want the fully built modules, download the latest versions from my Freebies page.

Download: (68k)
Version 6.1 uploaded 2018-11-14

If you look at the source code, you'll notice that these modules define a lisp callable function named (GetPathOf<basefilename>) that returns the directory from where the LspLoad module loaded. This also demonstrates another technique: defining an ADS (Lisp callable) function by "calculating" the function name at runtime.