Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Exchanging info dynamically via interface

mumpizmumpiz Posts: 75Member
Hi there,

I need to have a dynamic information exchange
between two assemblies. One is an exe and the
other a dll derived of a class that implements
an interface.
The executable has a command-list where commands
are added or removed depending on user input.

The dll also has a command-list, but only one of
the commands in either list should be the current
command.

If user klicks a control in exe, the command
of the dll must be canceled, and if user clicks a
control of the dll which is displayed in the exe,
the current exe command must be canceled.

What would be the easiest way to go about?
The only way to transfer information is the interface.

I can adapt code whereever I need to. e.g. whenever a
command is added to either list ( control.click ) I can
send some info to the other side?!

Id be happy about any suggestions.

Thanks

Comments

  • tsagldtsagld Posts: 621Member
    : Hi there,
    :
    : I need to have a dynamic information exchange
    : between two assemblies. One is an exe and the
    : other a dll derived of a class that implements
    : an interface.
    : The executable has a command-list where commands
    : are added or removed depending on user input.
    :
    : The dll also has a command-list, but only one of
    : the commands in either list should be the current
    : command.
    :
    : If user klicks a control in exe, the command
    : of the dll must be canceled, and if user clicks a
    : control of the dll which is displayed in the exe,
    : the current exe command must be canceled.
    :
    : What would be the easiest way to go about?
    : The only way to transfer information is the interface.
    :
    : I can adapt code whereever I need to. e.g. whenever a
    : command is added to either list ( control.click ) I can
    : send some info to the other side?!
    :
    : Id be happy about any suggestions.
    :
    : Thanks
    :
    Take a look at the System.Activator class. With that, you can dynamically instantiate classes of whatever assembly, from whatever assembly.

    Greets,
    Eric Goldstein
    www.gvh-maatwerk.nl

  • mumpizmumpiz Posts: 75Member
    : Take a look at the System.Activator class. With that, you can dynamically instantiate classes of whatever assembly, from whatever assembly.
    :
    : Greets,
    : Eric Goldstein
    : www.gvh-maatwerk.nl
    :
    :
    Thanks Eric,

    the biggest problem for me is: I only have a couple of years experience,
    and some concepts of C# I only know from reading, but have never used.
    Then there is this huge project I have to change and rid of bugs.

    Now what I described in my question I have solved meanwhile. However, have a look at this code snippet, I wonder if this is the propper way to implement the objects of my plugins?

    string path = Application.StartupPath + "\Standard\PlugIn";
    string[] pluginFiles = Directory.GetFiles(path, "*.dll");
    // List of Interface - Objects
    this.mIpi = new IPlugin[pluginFiles.Length];

    // register ViskonInterface foreach Dll

    for(int i=0; i<pluginFiles.Length; i++)
    {
    string args = pluginFiles[i].Substring( pluginFiles[i].LastIndexOf("\")+1,
    pluginFiles[i].IndexOf(".dll")-
    pluginFiles[i].LastIndexOf("\")-1);


    Type ObjType = null;
    try
    {
    Assembly ass = null;
    ass = Assembly.LoadFile( pluginFiles[i] );

    Type[] mytypes = ass.GetTypes();

    if (ass != null)
    {
    ObjType = ass.GetType(args+".Plugin");
    }
    }
    catch (Exception ex)
    {
    MessageBox.Show(ex.ToString(),"Exception Read Dll");
    }

    try
    {
    if (ObjType != null)
    //only if Dll class is called Plugin!!
    {
    mIpi[i] = (IPlugin)Activator.CreateInstance(ObjType);
    // catch if plugIn not derived of type VisKonInterface
    mIpi[i].PlugInHost = this;
    mIpi[i].Initialize();
    }
    }
    ....................................
    ..................................

    Does that make sense?!

    cya carsten
  • tsagldtsagld Posts: 621Member
    Looks fine to me. In fact, you did use the Activator class:
    [code]
    mIpi[i] = (IPlugin)Activator.CreateInstance(ObjType);
    [/code]

    : : Take a look at the System.Activator class. With that, you can dynamically instantiate classes of whatever assembly, from whatever assembly.
    : :
    : : Greets,
    : : Eric Goldstein
    : : www.gvh-maatwerk.nl
    : :
    : :
    : Thanks Eric,
    :
    : the biggest problem for me is: I only have a couple of years experience,
    : and some concepts of C# I only know from reading, but have never used.
    : Then there is this huge project I have to change and rid of bugs.
    :
    : Now what I described in my question I have solved meanwhile. However, have a look at this code snippet, I wonder if this is the propper way to implement the objects of my plugins?
    :
    : string path = Application.StartupPath + "\Standard\PlugIn";
    : string[] pluginFiles = Directory.GetFiles(path, "*.dll");
    : // List of Interface - Objects
    : this.mIpi = new IPlugin[pluginFiles.Length];
    :
    : // register ViskonInterface foreach Dll
    :
    : for(int i=0; i<pluginFiles.Length; i++)
    : {
    : string args = pluginFiles[i].Substring( pluginFiles[i].LastIndexOf("\")+1,
    : pluginFiles[i].IndexOf(".dll")-
    : pluginFiles[i].LastIndexOf("\")-1);
    :
    :
    : Type ObjType = null;
    : try
    : {
    : Assembly ass = null;
    : ass = Assembly.LoadFile( pluginFiles[i] );
    :
    : Type[] mytypes = ass.GetTypes();
    :
    : if (ass != null)
    : {
    : ObjType = ass.GetType(args+".Plugin");
    : }
    : }
    : catch (Exception ex)
    : {
    : MessageBox.Show(ex.ToString(),"Exception Read Dll");
    : }
    :
    : try
    : {
    : if (ObjType != null)
    : //only if Dll class is called Plugin!!
    : {
    : mIpi[i] = (IPlugin)Activator.CreateInstance(ObjType);
    : // catch if plugIn not derived of type VisKonInterface
    : mIpi[i].PlugInHost = this;
    : mIpi[i].Initialize();
    : }
    : }
    : ....................................
    : ..................................
    :
    : Does that make sense?!
    :
    : cya carsten
    :


    Greets,
    Eric Goldstein
    www.gvh-maatwerk.nl

Sign In or Register to comment.