Author Topic: Working with .net/arx dll files  (Read 3160 times)

0 Members and 1 Guest are viewing this topic.

Peter Jamtgaard

  • Guest
Working with .net/arx dll files
« on: June 06, 2010, 02:26:26 PM »
Here is a couple questions.

Programatically in .net

1.) Is there a way to tell which .net or arx dll's have already been loaded into the editor? (is there accessible list somewhere)

2.) Is there a way to tell the difference between an arx dll and a .net dll? (can the header information be read to tell the difference)

If so with either can you share any examples of the procedure?

Peter

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Working with .net/arx dll files
« Reply #1 on: June 06, 2010, 05:42:16 PM »
Have a play with something like this

Code: [Select]
[assembly: CommandClass(typeof(KdubTesting.TestCommands))]

namespace KdubTesting
{   
    public class TestCommands
    {
        //
        // Add System.Reflection;   to using statements
        //
        [CommandMethod("LTN")]
        static public void ListTheNetDllLoadedInAutoCAD()
        {
            Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;

            // Get the current application domain for the  current System.Threading.Thread
            AppDomain appDom = AppDomain.CurrentDomain;

            // gets the assemblies that have been loaded into  the execution context of this application domain
            foreach(Assembly assembly in appDom.GetAssemblies())
            {
                ed.WriteMessage("\n{0}", assembly.Location);
            }
        }
    }
}
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.

Chuck Gabriel

  • Guest
Re: Working with .net/arx dll files
« Reply #2 on: June 06, 2010, 06:37:09 PM »
There is something wrong with your code Kerry.  Maybe I just overlooked it, but I didn't see "//code him belonga Kdub@..." anywhere in there.  :D

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Working with .net/arx dll files
« Reply #3 on: June 06, 2010, 10:45:42 PM »

Note the comments !!

.. and the addition to keep Chuck happy :-D
Code: [Select]
[assembly: CommandClass(typeof(KdubTesting.TestCommands))]

namespace KdubTesting
{
    public partial class Kdub_API
    {
        [System.Security.SuppressUnmanagedCodeSecurity]
        // http://msdn.microsoft.com/en-us/library/ms683199(VS.85).aspx
        // This function returns a module handle for the specified module if the file
        // is mapped into the address space of the calling process

        [DllImport("kernel32.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
        public static extern int GetModuleHandleW(string lpModuleName);
    }
    public partial class TestCommands
    {
        [CommandMethod("TIML")]
        static public void TestIsTheDllModuleLoaded()
        {
            Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;

            //  Codehimbelonga Kdub@theSwamp 2010.06.07
            //  I don't fully understand this Method yet ... so beware .. this is a work in progress
            //  .ARX extension seems to be needed .. .DLL extension seems optional
            //  WEIRD .. AcLayer.DLL is loaded yet not recognised by this routine.
            //

            PromptResult prRes = ed.GetString("\nName of the net DLL or ARX File  [with extension]: ");
            if(prRes.Status != PromptStatus.OK) return;
            string dllModuleName = prRes.StringResult;

            if(Kdub_API.GetModuleHandleW(dllModuleName) > 0)
                ed.WriteMessage("\nModule {0} is loaded", dllModuleName);
            else
                ed.WriteMessage("\nModule {0} is NOT loaded", dllModuleName);
        }
    }
}
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: Working with .net/arx dll files
« Reply #4 on: June 07, 2010, 05:07:17 AM »

From my Discussion Group Archive

----- Original Message -----
From: "Tony Tanzillo" <tony.tanzillo@THE_URL_BELOW.com>
Newsgroups: autodesk.autocad.customization.dotnet
Sent: Wednesday, April 25, 2007 1:31 AM
Subject: Re: How to tell what .dll's Acad has loaded


There is an AutoCAD API method to list loaded
arx libraries:

  DynamicLinker.GetLoadedModules()

There are also events on the same object that
notify when modules are loaded/unloaded.



Thanks again Tony :)







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.

Glenn R

  • Guest
Re: Working with .net/arx dll files
« Reply #5 on: June 07, 2010, 05:24:03 AM »
I seem to remember Kean posting something along these lines, quite recently in fact...google helps.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Working with .net/arx dll files
« Reply #6 on: June 07, 2010, 06:29:16 AM »

Thanks Glenn,
I saw that subsequent to my post.

I think it's about time I took up programming seriously, I'm at the crossroads of 'use it or lose it' at the moment .. as soon as I saw that linked post I remembered seeing it before  :|
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.

Peter Jamtgaard

  • Guest
Re: Working with .net/arx dll files
« Reply #7 on: June 07, 2010, 10:12:29 AM »
Wow, thanks guys, Keans article was exactly what I was looking for (for question 1).

I have been meaning to print out all of his articles and put them together as a book, and just read it cover to cover...

How about programatically telling the difference between an arx dll and .net dll? (question 2)

If you read the file can you tell the difference from the header?

Thanks again.

Peter

LE3

  • Guest
Re: Working with .net/arx dll files
« Reply #8 on: June 07, 2010, 11:22:53 AM »
How about programatically telling the difference between an arx dll and .net dll? (question 2)

Have not tried but have a look here:
Namespace: System.Reflection
Module.GetPEKind method and check the PortableExecutableKinds Enumeration.