C#

Moderators: None (Apply to moderate this forum)
Number of threads: 2722
Number of posts: 5749

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Exchanging info dynamically via interface Posted by mumpiz on 11 Feb 2006 at 1:39 PM
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
Report
Re: Exchanging info dynamically via interface Posted by tsagld on 13 Feb 2006 at 5:13 AM
: 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

Report
Re: Exchanging info dynamically via interface Posted by mumpiz on 13 Feb 2006 at 7:42 AM
: 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
Report
Re: Exchanging info dynamically via interface Posted by tsagld on 13 Feb 2006 at 7:52 AM
Looks fine to me. In fact, you did use the Activator class:
 mIpi[i] = (IPlugin)Activator.CreateInstance(ObjType); 


: : 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




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.