Hi all i'm trying to make a plugin supported windows MDI application but my brain has stopped! i can't build algorithm!
First of all my program will read dll's from plugin directory which is located at the same directory of my MDI parent application,

i don't know what will i use for interfaces and classes, for the moment i created an interface which has to set name and i use that name for placing a button on a panel and i created a dll with that sdk, now its working but i want to add forms to that dll and when i click on my button that forms will appear as MDI child in my parent application..

codes that i worked on:
SDKLib.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;

namespace drSDK
{
    public interface IPlugIn
    {
        string name();
                
    }

    public class Plug
    {
        public string pName;
        public string pPath;
        public string pFName;
    }

    public class Kit
    {
        public static List<Plug> getAllPlugIns(string path)
        {
            List<Plug> myPlugs = new List<Plug>();//list
            if (!Directory.Exists(path))
                return myPlugs;//null
            string[] dlls = Directory.GetFiles(path, "*.dll");//arry dlls
             foreach (string dll in dlls)//all dlls in list
            {
                Assembly asm = Assembly.LoadFile(dll);//open as asm
                Type[] tipler = asm.GetTypes();
                foreach (Type tip in tipler)
                {
                    if (tip.GetInterface("IPlugIn") != null)//Thats my SDK!
                    {
                        Plug myP = new Plug();
                        myP.pFName = tip.FullName;
                        myP.pPath = dll;
                        object obj = asm.CreateInstance(tip.FullName);//dll instance 
                        myP.pName = obj.GetType().InvokeMember("name", BindingFlags.InvokeMethod, null, obj, null).ToString(); //name from interface
                        myPlugs.Add(myP);
                    }
                }
            }
            return myPlugs;
        }

        public static object createObject(Plug p)
        {
            Assembly asm = Assembly.LoadFile(p.pPath);
            object obj = asm.CreateInstance(p.pFName);
            return obj;
        }
    }
}

Form1.cs

using drSDK;
.
.
.
        List<Plug> myList = null;//Plugin list
        private void Form1_Load(object sender, EventArgs e)
        {
            myList = Kit.getAllPlugIns(Application.StartupPath + "//plugins");//plugin directory
            foreach (Plug p in myList)//4 every plug
            {
                Button b = new Button();
                b.Text = p.pName;
                b.Click += new EventHandler(b_Click);
                NavigatorGroupItemContainerPanel1.Controls.Add(b);
            }
        void b_Click(object sender, EventArgs e)
        {
            foreach (Plug p in myList)
            {
                if (p.pName == (sender as Button).Text)//wats clicked
                {
                    run(p);
                }
            }
        }

        void run(Plug p)
        {
            IPlugIn obj = (IPlugIn)Kit.createObject(p);
            .
            . [B]//I HAVE TO DO SMTH HERE (IN MY OPINION)[/B]
            .
            .


        }
        void Pencereler(Form pencere)
        {
            bool acik = false;
            foreach (Form eleman in this.MdiChildren)
            {
                if (eleman.Text == pencere.Text)
                {
                    acik = true;
                    eleman.Activate();
                }
                if (acik == false)
                {
                    pencere.MdiParent = this;
                    pencere.Show();
                }
            }
        }

Recommended Answers

All 2 Replies

//I HAVE TO DO SMTH HERE (IN MY OPINION)
What about doing this:

Form form = obj as Form;
if (form != null)
{
    form.MdiParent = this;
    form.Show();
}

Thank you for your post dear nick.crane;
but i wrote that " i can't build algorithm " i mean am stucked!
do i have to get type like...
Type formType = Type.GetType(BLABLA_DLL_BLA);
or do i have to Create Instance off the form which dll includes? or what kind a way i've to fallow for doing this? wat interfaces i've to add for ma sdk for dll? ok i give my obj as a form and if form is not null set this container, mdi parent of new form and show it.. i may add if the form is already opened Activate it or BringToFront but which form? "...from" which interface? do i have to add Form to my dll named by Form? or any name? (form1...form2...blaForm..) are there any example project for examine?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.