.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to load another dll from within your main dll and use classes/methods of it.

3 REPLIES 3
Reply
Message 1 of 4
Anonymous
606 Views, 3 Replies

How to load another dll from within your main dll and use classes/methods of it.

Hello, I'm just brainstorming this, not looking for copy/paste code, just ideas on how I can load another dll from my main dll, then access functions there, subscribe to events, pass objects back and forth...

 

Anyone done this?

 

Thanks,

Viktor.

3 REPLIES 3
Message 2 of 4
fieldguy
in reply to: Anonymous

I don't know about loading another dll, but I have added other vb code to solution explorer as an "Existing Item".  If you have the code for the dll you want to add, then add it as existing item.  Then it will be "built" into the main dll - a separate load is not required.  You can reference methods and variables using "othervbcodename.methodname", or othervbcodename.variablename = value.  I declare the othervbcodename variables and methods as Friend Shared, but I don't know if that is correct - it works. 

Message 3 of 4
Anonymous
in reply to: Anonymous

you just reference it the same way you reference the autocad libraries, only difference is that you have to distribute both of your dlls together

Message 4 of 4
Anonymous
in reply to: Anonymous

Maybe something like this ... from/as an IExtensionApplication

  

       public void Initialize()
        {
            Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            Assembly callee = Assembly.GetExecutingAssembly();
            string calleename = callee.FullName;
            string lclpath = Path.GetDirectoryName(callee.Location);

            //Type AssmOfInterest = typeof(DataBridgeMap3dDriver.DataBridgeMap3d);
            //string QualifiedAssmName = AssmOfInterest.AssemblyQualifiedName.ToString();
            //Type target_assembly = Type.GetType(QualifiedAssmName, false);
            Assembly[] asms;
            bool assmIsLoaded = false;
            asms = AppDomain.CurrentDomain.GetAssemblies();
            ed.WriteMessage("\nThere are {0} assemblies loaded.", asms.Length);
            foreach (Assembly asm in asms)
            {
                if (asm.FullName.ToLower().Contains(PPKS["DATABRIDGE_MODULE_NAME"].ToLower()))
                {
                    assmIsLoaded = true;
                    ed.WriteMessage("\n" + asm.FullName + " is loaded");
                    break;
                }
            }
            try
            {
                if (assmIsLoaded == false)
                {
                    ResultBuffer args = new ResultBuffer();
                    args.Add(new TypedValue(RTSTR, "._NETLOAD"));
                    args.Add(new TypedValue(RTSTR, lclpath + "\\" + PPKS["DATABRIDGE_MODULE_NAME"] + ".dll"));
                    int b = InvokeCmd(args);
                    DataBridgeForm = DataBridgeMap3dDriver.DataBridgeMap3d.DataBridgeForm;
                }
                else
                {
                    DataBridgeForm = DataBridgeMap3dDriver.DataBridgeMap3d.DataBridgeForm;
                }
                DataBridgeForm.OnReceivedSuspenseQueueEntry += new DataBridgeII.ReceivedSuspenseQueueEntryHandler(DataBridgeForm_OnReceivedSuspenseQueueEntry);
                DataBridgeForm.FormClosing += new FormClosingEventHandler(DataBridgeForm_FormClosing);
                ed.WriteMessage("\r\nSDOCHGARCHENG: to define/redefine dwg scale and airport");
                ed.WriteMessage("\r\nSDOCOLORANDLAYER: to current active color and layer");
            }
            catch (System.Exception _ex)
            {
                ed.WriteMessage("Error:" + _ex.Message);
            }
        }

 

There are comments and some wasted bits but the above is how I do it ... also

public static DataBridge.DataBridgeII DataBridgeForm; exists within the "this dll" which gets checked for null/!null

r,

dennis

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Autodesk Design & Make Report