TheSwamp
Code Red => .NET => Topic started by: Kerry on December 03, 2009, 10:57:08 AM
-
AutoLoading .NET dll's
Thought I'd posted this previously, but looks likely I didn't
Autoloading .NET dll's
This works for me ..... a simple autoload defined in LISP in the partial menu MNL OR one of the AutoCAD files which load for each session.
... only loads the .NET dll when needed, so startup time in minimised ( similar to demand loading)
The function command name should be the same as the .NET command name.
This Command definition is overwritten when the dll is Netloaded.
(defun c:CMD_Doit ()
;;// Codehimbelonga kwb@theSwamp 20070509
;;(findfile "F:\\_VS2008Projects\\Projects\\ACAD-Managed\\CsMgdAcad-ColorLab\\bin\\Release\\CsMgdAcad-ColorLab.dll")
(command
"_NETLOAD"
"F:\\_.VS2008Projects\\Projects\\ACAD-Managed\\CsMgdAcad-ColorLab\\bin\\Release\\CsMgdAcad-ColorLab.dll"
)
(command "CMD_Doit")
)
Command: cmd1
Concept Code For AC2008, MSVS2005 :: kwb@theSwamp 20070509 ->> ...
<dll netloads and program runs first instance>
Command: CMD1
<program runs subsequent instances>
Regards
Kerry
edit:
This is the CsMgdAcad-ColorLab.dll referenced :)
http://www.theswamp.org/index.php?topic=14977.0
-
Thanks Kerry, I'll give it a shot.
Just to be clear (I'm lisp ignorant :) ), I can put this in any lisp that gets loaded from say the start up suite?
-
Yes Mick.
or in an MNL file with the same name as a menu you use.
-
Thanks.
-
Hi,
By my side, I use some LISP routine to register or unregister DLLs
;;; NetAutoLoad
;;; Register a DLL for autoload at startup
;;;
;;; Arguments
;;; key : the application key (string)
;;; descr : a description (string)
;;; filename : the dll complete filename (string)
;;;
;;; Example: (NetAutoLoad "MyApp" "Loads my application" "C:\\gile\\NET applications\\MyApp.dll")
(defun NetAutoLoad (key descr filename)
(vl-load-com)
(mapcar
'(lambda (k v)
(vl-registry-write
(strcat "HKEY_CURRENT_USER\\"
(vlax-product-key)
"\\Applications\\"
key
)
k
v
)
)
'("DESCRIPTION" "LOADCTRLS" "LOADER" "MANAGED")
(list descr 2 filename 1)
)
)
;;;====================================;;;
;;; NetDemandLoad
;;; Register a DLL for load on command calling
;;;
;;; Arguments
;;; key : the application key (string)
;;; descr : a description (string)
;;; filename : the dll complete filename (string)
;;; commands : the list of command names (list)
;;;
;;; Example: (NetDemandLoad "MyApp2" "Loads my application" "C:\\gile\\NET applications\\MyApp2.dll" '("CMD1" "CMD2"))
(defun NetDemandLoad (key descr filename commands / regpath)
(vl-load-com)
(mapcar
'(lambda (k v)
(vl-registry-write
(setq regpath (strcat "HKEY_CURRENT_USER\\"
(vlax-product-key)
"\\Applications\\"
key
)
)
k
v
)
)
'("DESCRIPTION" "LOADCTRLS" "LOADER" "MANAGED")
(list descr 12 filename 1)
)
(foreach c commands
(vl-registry-write (strcat regpath "\\Commands") c c)
)
)
;;;====================================;;;
;;; NetUnReg
;;; Deletes a key and all subkeys in the register table
;;;
;;; Arguments
;;; key : the application key (string)
;;;
;;; Example: (NetUnReg "MyApp2")
(defun NetUnReg (key / regpath)
(vl-load-com)
(setq regpath (strcat "HKEY_CURRENT_USER\\"
(vlax-product-key)
"\\Applications\\"
key
)
)
(foreach k (vl-registry-descendents regpath)
(vl-registry-delete (strcat regpath "\\" k))
)
(vl-registry-delete regpath)
)
-
Hi,
By my side, I use some LISP routine to register or unregister DLLs
;;; NetAutoLoad
;;; Register a DLL for autoload at startup
;;;
;;; Arguments
;;; key : the application key (string)
;;; descr : a description (string)
;;; filename : the dll complete filename (string)
;;;
;;; Example: (NetAutoLoad "MyApp" "Loads my application" "C:\\gile\\NET applications\\MyApp.dll")
(defun NetAutoLoad (key descr filename)
(vl-load-com)
(mapcar
'(lambda (k v)
(vl-registry-write
(strcat "HKEY_CURRENT_USER\\"
(vlax-product-key)
"\\Applications\\"
key
)
k
v
)
)
'("DESCRIPTION" "LOADCTRLS" "LOADER" "MANAGED")
(list descr 2 filename 1)
)
)
;;;====================================;;;
;;; NetDemandLoad
;;; Register a DLL for load on command calling
;;;
;;; Arguments
;;; key : the application key (string)
;;; descr : a description (string)
;;; filename : the dll complete filename (string)
;;; commands : the list of command names (list)
;;;
;;; Example: (NetDemandLoad "MyApp2" "Loads my application" "C:\\gile\\NET applications\\MyApp2.dll" '("CMD1" "CMD2"))
(defun NetDemandLoad (key descr filename commands / regpath)
(vl-load-com)
(mapcar
'(lambda (k v)
(vl-registry-write
(setq regpath (strcat "HKEY_CURRENT_USER\\"
(vlax-product-key)
"\\Applications\\"
key
)
)
k
v
)
)
'("DESCRIPTION" "LOADCTRLS" "LOADER" "MANAGED")
(list descr 12 filename 1)
)
(foreach c commands
(vl-registry-write (strcat regpath "\\Commands") c c)
)
)
;;;====================================;;;
;;; NetUnReg
;;; Deletes a key and all subkeys in the register table
;;;
;;; Arguments
;;; key : the application key (string)
;;;
;;; Example: (NetUnReg "MyApp2")
(defun NetUnReg (key / regpath)
(vl-load-com)
(setq regpath (strcat "HKEY_CURRENT_USER\\"
(vlax-product-key)
"\\Applications\\"
key
)
)
(foreach k (vl-registry-descendents regpath)
(vl-registry-delete (strcat regpath "\\" k))
)
(vl-registry-delete regpath)
)
Thanks Gille
It's very useful fo me
~'J'~
-
You're welcome fixo, I'm glad it helps :-)
-
Kerry, I learned how to demand load .Net dlls through the registry at AU. When I get back I will send you the info
-
CmdrDuh,
The 'NetDemandLoad' LISP routine I posted does it.
I learned it from Kean Walmsley's blog, here (http://through-the-interface.typepad.com/through_the_interface/2006/09/automatic_loadi.html)
-
I am not sure about a LISP routine you are referring to, however, Keans post is the method I was referring to.
-
I am not sure about a LISP routine you are referring to, however, Keans post is the method I was referring to.
Just up there, reply #4.
-
..... I learned how to demand load .Net dlls through the registry at AU. When I get back I will send you the info
Hope you enjoyed it David.
... a little less crowded this year ?
Any especially good classes ?
-
Hi,
By my side, I use some LISP routine to register or unregister DLLs
;;; NetAutoLoad
;;; Register a DLL for autoload at startup
;;;
gile,
good solution.
I like that the VL functions determine the relevant product codes.
my method was meant more for quick debug testing ... ' cause I keep forgetting to unregister the temporary demand load settings :|
-
Kerry, I took a bunch of C# classes, which all reinforced what I have been relearning. I cant seem to get enough time in code wise to remember everything I have been studying. 2 of the classes I took were on WPF, which was UBBER cool. Fenton Webb taught both classes, and showed some amazing stuff in autocad. Then I took a LINQ class so I could try and spend some dedicated time learning LINQ. What a cool addition they added. AND, I learned about Lambda expressions which are replacing something or another, I will have to dig through my notes. I took the .Net 4.0 class, but learned that there is a pretty major bug which Microsoft is working on with Autodesk as we speak, so I would not advise upgrading to 4.0 yet. The guy teaching that class had some "patched" DLL files which he said were not available yet, and that 4.0 would not work with 2010.
All in all, I had great classes and learned a lot of things I keep hearing you guys talk about. Now if I can just get enough time in coding so I dont forget the new stuff.
-
my method was meant more for quick debug testing ...
For autoloading DLL on debug, pasting this in the acad.lsp file seems to work whatever the dll name (the dll must ahve the same name as the solution folder) :
((lambda (path)
(if (wcmatch path "*\\DEBUG\\*")
(foreach f (vl-directory-files path "*.DLL" 1)
(if
(wcmatch path
(strcat "*\\" (strcase (vl-filename-base f)) "\\*")
)
(command "_.netLoad" f)
)
)
)
)
(strcase (getvar 'dwgprefix))
)
-
Nice solution gile.
I loaded the starement from a menubar command.
and added
(if (wcmatch path
(strcat "*\\" (strcase (vl-filename-base f)) "\\*")
)
(progn (prompt (strcat "\n DEBUG NETLOADING :\n" path f))
(command "_.netLoad" f)
)
)
so I got this :
DEBUG NETLOADING :
C:\KDUBPRO\VS2008\AC2010\TESTING\GETSETENV\BIN\DEBUG\GetSetEnv.dll
Thanks Sir, excellent !