473,385 Members | 1,772 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Plugin problem

JJ
Hi all,

I'm writing a program that uses plugins to add some functionality. It works
as follows:
A plugin is a user control with a method getCoordArray(decimal inX, decimal
inY, decimal inZ) and a property System.Drawing.Size bestsize. To use the
plugin, I need to do the following:
1) import the dll as a reference.
1b) validate the dll: look for the method getCoordArray(decimal inX, decimal
inY, decimal inZ) and a property System.Drawing.Size bestsize
2) adding the user control to a panel in my form (only if step 1b returns
true)
Of course I know how to do this at design time, but how can I do this at
runtime?

Thanks in advance,

Vincent
Nov 16 '05 #1
3 1391

"JJ" <ge***************@lycos.nl> schrieb
I'm writing a program that uses plugins to add some functionality. It
works
as follows:
A plugin is a user control with a method getCoordArray(decimal inX,
decimal
inY, decimal inZ) and a property System.Drawing.Size bestsize. To use the
plugin, I need to do the following:
1) import the dll as a reference.
1b) validate the dll: look for the method getCoordArray(decimal inX,
decimal
inY, decimal inZ) and a property System.Drawing.Size bestsize
2) adding the user control to a panel in my form (only if step 1b returns
true)
Of course I know how to do this at design time, but how can I do this at
runtime?


Hi Vincent,

use System.Reflection.

//load Assembly
Assembly assm = Assembly.LoadFrom(yourDll.dll);
//get your Control
Type t = assm.GetType("yourControl");
//check if method exists
MethodInfo mi = t.GetMethod("getCoordArray");
if (mi != null)
{
ParameterInfo[] pi = mi.GetParameters();
//evaluate ParameterInfos
//[...]
//check returnType
if (mi.ReturnType == typeof (System.Drawing.Size))
{
//Create an instance of your control
Control c = (Control) assm.CreateInstance("yourControl");
//Add the control to your form
yourForm.Controls.Add(c);
//further actions with Control c
}
}

Have a look at
http://msdn.microsoft.com/library/en...onOverview.asp

for further information.

Cheers

Arne Janning
Nov 16 '05 #2
Vincent... This may help:
http://www.geocities.com/jeff_louie/OOP/oop13.htm
Chapter 13 "Dynamic Loading with Reflection"
Modified 8.15.04
Regards,
Jeff
I'm writing a program that uses plugins to add some functionality.<


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3
JJ
Hi,

thanks for your response. I've used your codesnippet succesfull. There's
only one problem: When I use the method getCoordArray() (that's a valid
method of my plugin, but will only be available at runtime) the compiler
gives an error message: System.Windows.Forms.Control does not contain a
definition for getCoordArray. I understand the error message, but do not
know how to solve it.

Any suggestions?

Best regards
Vincent
"Arne Janning" <sp*****************@msn.com> schreef in bericht
news:eH**************@TK2MSFTNGP10.phx.gbl...

"JJ" <ge***************@lycos.nl> schrieb
I'm writing a program that uses plugins to add some functionality. It
works
as follows:
A plugin is a user control with a method getCoordArray(decimal inX,
decimal
inY, decimal inZ) and a property System.Drawing.Size bestsize. To use the plugin, I need to do the following:
1) import the dll as a reference.
1b) validate the dll: look for the method getCoordArray(decimal inX,
decimal
inY, decimal inZ) and a property System.Drawing.Size bestsize
2) adding the user control to a panel in my form (only if step 1b returns true)
Of course I know how to do this at design time, but how can I do this at
runtime?
Hi Vincent,

use System.Reflection.

//load Assembly
Assembly assm = Assembly.LoadFrom(yourDll.dll);
//get your Control
Type t = assm.GetType("yourControl");
//check if method exists
MethodInfo mi = t.GetMethod("getCoordArray");
if (mi != null)
{
ParameterInfo[] pi = mi.GetParameters();
//evaluate ParameterInfos
//[...]
//check returnType
if (mi.ReturnType == typeof (System.Drawing.Size))
{
//Create an instance of your control
Control c = (Control) assm.CreateInstance("yourControl");
//Add the control to your form
yourForm.Controls.Add(c);
//further actions with Control c
}
}

Have a look at

http://msdn.microsoft.com/library/en...ectionOverview
..asp
for further information.

Cheers

Arne Janning

Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Roger Boesch | last post by:
Im currently working on a plugin architectur for a software product written in c# and have found the following problem: Project a) Application, Application with all classes used in this app ...
2
by: Edvard Majakari | last post by:
Hi, My idea is to create a system working as follows: each module knows path to plugin directory, and that directory contains modules which may add hooks to some points in the code. Inspired...
3
by: auad | last post by:
hi, I'm having a problem with plugins....as follows: I have 3 projects: 2 class libraries and 1 Windows App (Project 1: ClassLibrary) I have a plugin interface:...
2
by: Aravind | last post by:
I have 3rd party dll plugin COM interface, when loaded executes the following functions. public class Test: IPlugin { public void Innitialize(IPluginApp obj, int pluginHandle) { //gets the...
4
by: Paciente8159 AKA Klayman | last post by:
Hi, I have a couple of doubts reggarding a plugin based application in C++? I want to build a c++ plugin based app. I have searched alot of things in the net but I still don't know how to...
0
by: Zeya | last post by:
Situation: Using C#, ASP.Net Requirement: 1. ASP.net application with virtual hosting service. 2. Requires a service that will run every predefined frequency in minutes (2, 30, 100, 10000)...
1
by: Olie | last post by:
I was quite surprised to find virtually nothing about this but I may have been searching for the wrong thing. I want to know the best way to provide a programming interface to a plugin. I...
0
by: gerdhub | last post by:
I develop an application that uses a plugin interface, that the hosting application as well as the plugins implement. Each plugin is loaded via: newPlugin.Instance =...
7
by: WTH | last post by:
I am now aware (I am primarily a C++ developer) that in C# if you reference the same interface from the same file in two different projects the types are actually incompatible. I found this out...
3
etiainen
by: etiainen | last post by:
Hi everyone! I'm in a bit of a problem here: I have to make a maven project for native (jni & C) code. I am using this plugin:...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.