Author Topic: Make a Netload or .Net .DLL loader  (Read 5087 times)

0 Members and 1 Guest are viewing this topic.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8702
  • AKA Daniel
Make a Netload or .Net .DLL loader
« on: April 24, 2007, 06:00:01 AM »
I want to make a NetLoad command for Intellicad ,anyone have a clue
Where would I even begin to write such an animal ?

Thanks

Glenn R

  • Guest
Re: Make a Netload or .Net .DLL loader
« Reply #1 on: April 24, 2007, 06:06:43 AM »
Appdomain's...

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8702
  • AKA Daniel
Re: Make a Netload or .Net .DLL loader
« Reply #2 on: April 24, 2007, 09:50:30 AM »
Appdomain's...

I’m on it, thanks for the tip.
Dan

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8702
  • AKA Daniel
Re: Make a Netload or .Net .DLL loader
« Reply #3 on: April 24, 2007, 02:38:35 PM »
I suppose upon loading of the assembly I would need to extract all the custom attributes like [CommandMethod("DOMeNow")] and do mojo to register commands.
I think Assembly::LoadFrom(…) might work


It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8702
  • AKA Daniel
Re: Make a Netload or .Net .DLL loader
« Reply #4 on: May 01, 2007, 11:21:32 PM »
Ok I am getting in over my head here trying to make a CommandMethod attribute. I have created a custom Attribute class called TesterAttribute that has one property string GlobalName. I am able to search an assembly for the attribute, get the method, and global name. I can also invoke the method.
My Question is how can I register a managed method pointer with sds_regfunc() (read: acedRegFunc() )  so the method can be called from the command line? I am even making sense ? :-o

Here is what I have so far.

Code: [Select]
            public ref class NetLoader
            {
            internal:
                static Hashtable ^ht = gcnew Hashtable(); 
            public:
                NetLoader(void)
                {
                }
                static NetLoader(void)
                {
                    Initialize();
                }
                static void Initialize()
                {
                    System::AppDomain::CurrentDomain->AssemblyLoad +=
                        gcnew AssemblyLoadEventHandler(NetLoader::OnAssemblyLoad);
                }
                static void OnAssemblyLoad(Object ^sender, AssemblyLoadEventArgs ^e)
                {
                    ProcessAssembly(e->LoadedAssembly);
                }
                [SecurityPermission(SecurityAction::LinkDemand, Infrastructure=true)]
                static void Load(String ^fileName)
                {
                    System::Reflection::Assembly::LoadFrom(fileName);
                }
                static void ProcessAssembly(Assembly^ assembly)
                {
                    Type ^tp = DWM::Cad::RuntimeServices::TesterAttribute::typeid;
                    for each (Type^ t in assembly->GetTypes())
                        for each (MethodInfo^ m in t->GetMethods())
                            //for each (Object^ o in m->GetCustomAttributes(tp,true))// nope
                            for each (Object^ o in m->GetCustomAttributes(true))
                            {
                                if (o->ToString() == tp->ToString()) //what a hack
                                {
                                    TesterAttribute ^att = static_cast<TesterAttribute^>(o);//ok
                                    if( !ht->ContainsKey((String^)att->GlobalName) && !ht->ContainsValue((MethodInfo^)m) )
                                    {
                                        ht->Add((String^)att->GlobalName , (MethodInfo^)m);
                                        m->Invoke(nullptr, nullptr);//yeehaw it works

                                        //see acedDefun() and acedRegFunc()
                                        sds_defun((char*)(void*)Marshal::StringToHGlobalAnsi(att->GlobalName) , ht->Count);
                                        sds_regfunc(m->Invoke(nullptr,nullptr) , ht->Count);
                                    }
                                    else
                                    {
                                      Utilities::WriteMessage("\nCommand " + att->GlobalName + " Already registered");//ok
                                    }
                                   
                                }

                            }

                }

            };
« Last Edit: May 01, 2007, 11:24:02 PM by Danielm103 »

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8702
  • AKA Daniel
Re: Make a Netload or .Net .DLL loader
« Reply #5 on: May 02, 2007, 02:09:13 PM »
Who da Man! <Victory Dance>  I got it!! :-D
Now Intellicad has both a dialog based netload and a  (netload “path”)  :kewl:
And will register commands
Hope it don’t crash.

Chuck Gabriel

  • Guest
Re: Make a Netload or .Net .DLL loader
« Reply #6 on: May 02, 2007, 03:40:58 PM »
Who da Man! <Victory Dance>  I got it!! :-D
Now Intellicad has both a dialog based netload and a  (netload “path”)  :kewl:
And will register commands
Hope it don’t crash.

Congratulations.  Sounds like you're having a lot of fun with this.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8702
  • AKA Daniel
Re: Make a Netload or .Net .DLL loader
« Reply #7 on: May 02, 2007, 11:36:13 PM »
Thanks Chuck,
Yep, I am having fun playing this old Les Paul copy.
Dan