I'm posting here because there's no other proper place to review source code snips like this and doing it by email is not very efficient in my estimation.
Slay away --
(defun _Load_ODCL_Runtime ( / loaderp proc_arch arxname arxpath errmsg )
;; Let's be clear on the intent of the loader. When Joe User
;; loads up the parent application there is full intent to
;; run it, regardless whatever the demand load setting may be.
;; Speaking frankly if I may, the majority of users don't know
;; diddly about demand loading and I don't believe it's the
;; responsibility of this loader to edumacate 'em.
;;
;; What Joe thinks he knows when the application he intended to
;; run fails (because demand loading is disabled) is that it is
;; somehow broken (despite any lucid explainations about demand
;; loading that migh be provided) - "Yeah, I saw some cryptic
;; message about demand something or other ... maybe they will
;; fix that in the next version".
;;
;; Further, at our camp we want the applications to run. Period.
;; I acknowledge that this perspective won't necessarilly be
;; shared universally, but I'm making the attempt to explain my
;; rationale for what follows.
;;
;; Finally, if someone actually knows what they're doing and re-
;; quires a clean environment (one possible intent for disabling
;; demand loading) they'll know how to dump the OpenDCL runtime
;; via arxunload.
;;
;; With the above as a context this function is hereby designed.
;;
;; The loading attempt order (if not already loaded):
;;
;; 1. If OpenDCL has been installed on this machine via the
;; installer use the path to the runtime as specified in
;; the registry for demand loading -- but load via arxload
;; regardles the demand load setting.
;;
;; 2. If the OpenDCL runtime is found in the support path use
;; arxload to load said runtime.
;;
;; 3. If OpenDCL has been installed on this machine via the
;; installer *AND* demand loading is enabled force the load-
;; ing of the runtime via invoking the OpenDCL command.
;;
;; Verbosely / gratuitously annotated for noobs and bit weiners
;; alike.
(or
;; Already loaded, vacate now (return t to caller).
dcl_getversionex
;; SECTION 1. Attempt to load the runtime via arxload using
;; the path associated with the opendcl demand loader (the
;; intent: Use said path but do not use the OpenDCL command
;; to induce loading the arx). In other words don't use
;; command / vl-cmdf.
(and
;; Is demand loading is specified for OpenDCL?
(setq arxpath
(vl-registry-read
(strcat
"HKEY_LOCAL_MACHINE\\"
(vlax-product-key)
"\\Applications\\OpenDCL"
)
"Loader"
)
)
;; We'll use the following variable in SECTION 3.
(setq loaderp t)
;; Is she an arx file?
(wcmatch (strcase arxpath) "*`.ARX")
;; Was the load attempt successful?
(arxload arxpath nil)
;; Is core OpenDCL functionality now defined?
dcl_getversionex
)
;; SECTION 2. Attempt to arxload the runtime explicitly by
;; finding it in the support path.
(and
;; Determine the appropriate arx module for the pro-
;; cessor and the AutoCAD version.
(setq arxname
(strcat "OpenDCL"
(if
(and
(setq proc_arch
(getenv "PROCESSOR_ARCHITECTURE")
)
(< 1 (strlen proc_arch))
(eq "64"
(substr
proc_arch
(1- (strlen proc_arch))
)
)
)
".x64."
"."
)
(substr (getvar "acadver") 1 2)
".arx"
)
)
;; Is the arxfile in the support path somewhere?
(setq arxpath (findfile arxname))
;; Was the load attempt successful?
(arxload arxpath nil)
;; Is core OpenDCL functionality now defined?
dcl_getversionex
)
;; SECTION 3. If demand loading is enabled use the OpenDCL
;; command to induce the loading of the OpenDCL runtime.
;; If we got here it possibly means the runtime is no lon-
;; ger an arx file (maybe an exe) or the arxload attempt in
;; SECTION 1 failed for some reason. Regardless, it appears
;; a demand loader is still present, so let's try to use it
;; to load the OpenDCL runtime.
(and
;; The following variable 'loaderp' is initialized from
;; the first attempt to load the runtime in SECTION 1.
;; If null it means no OpenDCL loader is present on this
;; machine so there's no point in invoking the OpenDCL
;; command.
loaderp
;; A loader is defined but let's ensure demand loading
;; is enabled, lest the invocation of the OpenDCL com-
;; mand be pointless.
(< 1 (getvar "demandload"))
;; We're good, invoke the OpenDCL command ...
(vl-catch-all-apply 'vl-cmdf '("opendcl"))
;; Is core OpenDCL functionality now defined?
dcl_getversionex
)
;; If we got here the opendcl runtime was not loaded.
(progn
;; Inform the user of the sad news.
(princ
(strcat
"Error: "
(if arxpath
(strcat arxpath " <failed to load>")
"OpenDCL runtime <not found>"
)
".\n"
)
)
nil
)
)
dcl_getversion
)