Author Topic: AutoLoading .NET dll's  (Read 14542 times)

0 Members and 1 Guest are viewing this topic.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
AutoLoading .NET dll's
« 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
« Last Edit: December 03, 2009, 11:09:39 AM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

MickD

  • King Gator
  • Posts: 3636
  • (x-in)->[process]->(y-out) ... simples!
Re: AutoLoading .NET dll's
« Reply #1 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?
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: AutoLoading .NET dll's
« Reply #2 on: December 03, 2009, 04:31:57 PM »

Yes Mick.
or in an MNL file with the same name as a menu you use.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

MickD

  • King Gator
  • Posts: 3636
  • (x-in)->[process]->(y-out) ... simples!
Re: AutoLoading .NET dll's
« Reply #3 on: December 03, 2009, 04:33:02 PM »
Thanks.
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: AutoLoading .NET dll's
« Reply #4 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)
)
Speaking English as a French Frog

fixo

  • Guest
Re: AutoLoading .NET dll's
« Reply #5 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'~

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: AutoLoading .NET dll's
« Reply #6 on: December 04, 2009, 08:52:42 AM »
You're welcome fixo, I'm glad it helps :-)
Speaking English as a French Frog

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: AutoLoading .NET dll's
« Reply #7 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
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: AutoLoading .NET dll's
« Reply #8 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
Speaking English as a French Frog

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: AutoLoading .NET dll's
« Reply #9 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.
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: AutoLoading .NET dll's
« Reply #10 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.
Speaking English as a French Frog

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: AutoLoading .NET dll's
« Reply #11 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 ?

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: AutoLoading .NET dll's
« Reply #12 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  :|
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: AutoLoading .NET dll's
« Reply #13 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.
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: AutoLoading .NET dll's
« Reply #14 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))
)
Speaking English as a French Frog