TheSwamp

Code Red => .NET => Topic started by: Kerry on December 03, 2009, 10:57:08 AM

Title: AutoLoading .NET dll's
Post 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.

Code: [Select]
(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
Title: Re: AutoLoading .NET dll's
Post by: MickD on December 03, 2009, 04:12:07 PM
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?
Title: Re: AutoLoading .NET dll's
Post by: Kerry on December 03, 2009, 04:31:57 PM

Yes Mick.
or in an MNL file with the same name as a menu you use.
Title: Re: AutoLoading .NET dll's
Post by: MickD on December 03, 2009, 04:33:02 PM
Thanks.
Title: Re: AutoLoading .NET dll's
Post by: gile on December 03, 2009, 05:43:09 PM
Hi,

By my side, I use some LISP routine to register or unregister DLLs

Code: [Select]
;;; 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)
)
Title: Re: AutoLoading .NET dll's
Post by: fixo on December 04, 2009, 08:10:26 AM
Hi,

By my side, I use some LISP routine to register or unregister DLLs

Code: [Select]
;;; 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'~
Title: Re: AutoLoading .NET dll's
Post by: gile on December 04, 2009, 08:52:42 AM
You're welcome fixo, I'm glad it helps :-)
Title: Re: AutoLoading .NET dll's
Post by: David Hall on December 04, 2009, 03:27:32 PM
Kerry, I learned how to demand load .Net dlls through the registry at AU.  When I get back I will send you the info
Title: Re: AutoLoading .NET dll's
Post by: gile on December 04, 2009, 03:43:01 PM
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)
Title: Re: AutoLoading .NET dll's
Post by: David Hall on December 04, 2009, 04:09:20 PM
I am not sure about a LISP routine you are referring to, however, Keans post is the method I was referring to.
Title: Re: AutoLoading .NET dll's
Post by: gile on December 04, 2009, 04:33:33 PM
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.
Title: Re: AutoLoading .NET dll's
Post by: Kerry on December 05, 2009, 06:58:12 PM
..... 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 ?

Title: Re: AutoLoading .NET dll's
Post by: Kerry on December 05, 2009, 07:04:18 PM
Hi,

By my side, I use some LISP routine to register or unregister DLLs

Code: [Select]
;;; 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  :|
Title: Re: AutoLoading .NET dll's
Post by: David Hall on December 05, 2009, 11:52:35 PM
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.
Title: Re: AutoLoading .NET dll's
Post by: gile on February 22, 2010, 08:49:39 AM
Quote
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) :
Code: [Select]
((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))
)
Title: Re: AutoLoading .NET dll's
Post by: Kerry on February 22, 2010, 10:17:10 PM
Nice solution gile.
I loaded the starement from a menubar command.

and added
Code: [Select]
            (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 :
Quote
DEBUG NETLOADING :
C:\KDUBPRO\VS2008\AC2010\TESTING\GETSETENV\BIN\DEBUG\GetSetEnv.dll

Thanks Sir, excellent !