473,387 Members | 1,530 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,387 software developers and data experts.

stuck on reflection latebinding assembly problem

I have 2 samples of code bellow that work fine at the moment

the first routine loads an dll assembley and instantiates the type in
the dll which is always a form, and creates a child form from it.

I need to use latebinfing becasue the dll to be loaded is selected by
the user but is allways a dll with a form class and always
instantiated as a child form.

My problem is how can using this technique pass a reference to the
child form of the parent form in the constructor of the child form in
the dll file. The child form needs to refer back to the parent form
for customs methods to run

I want to pass "this" from the parent form into the child form, but
there does not seem to be anyway to do this using
assembley.createinstance.

Can anyone help please

peted

//loading routine to load child form from dll using latebiding and
reflection

private void loadDeviceInterfaceToSerialPort(int port,String
devicefile)
{
Assembly deviceInterfaceAssembly = null;

// Dynamically load the selected assembly.
deviceInterfaceAssembly = Assembly.LoadFile(devDir +
devicefile);
if (deviceInterfaceAssembly == null)
MessageBox.Show("not loaded");

// Get all types in assembly.

Type[] deviceInterfaceType =
deviceInterfaceAssembly.GetTypes();

ipLink.SetSerialPortDeviceInterface(port,
(Form)deviceInterfaceAssembly.CreateInstance(devic eInterfaceType[0].FullName));

ipLink.GetSerialPortDeviceInterface(port).MdiParen t =
this;
ipLink.GetSerialPortDeviceInterface(port).StartPos ition =
FormStartPosition.Manual;
ipLink.GetSerialPortDeviceInterface(port).FormBord erStyle =
FormBorderStyle.None;

ipLink.GetSerialPortDeviceInterface(port).Size = new
Size(400, this.ClientRectangle.Height);
ipLink.GetSerialPortDeviceInterface(port).Location = new
Point(540, 0);

ipLink.GetSerialPortDeviceInterface(port).Show();
}
// general form code class in the dll(s) to be loaded.

namespace K108Relay
{
public partial class K108Relay : Form
{
// static IPLinkerator.IPLinkMain host;

public K108Relay()
{
InitializeComponent();
// host.DeviceWrite("1I");
}

private void button1_Click(object sender, EventArgs e)
{
IPLinkMain.staticVar.DeviceWrite("1I");

}
}
}
Feb 21 '07 #1
2 1725
There is an overload for that methods that take an object array for the
contructor parameters. It will then use these to find the correct contructor.
My suggestion though is to have an interface that all these forms in these
dlls should implement. Then you can do the reflection based on that interface
and it will make using the object easier and faster when you call interface
members rather then reflecting them.
--
Ciaran O''Donnell
http://wannabedeveloper.spaces.live.com
"Peted" wrote:
I have 2 samples of code bellow that work fine at the moment

the first routine loads an dll assembley and instantiates the type in
the dll which is always a form, and creates a child form from it.

I need to use latebinfing becasue the dll to be loaded is selected by
the user but is allways a dll with a form class and always
instantiated as a child form.

My problem is how can using this technique pass a reference to the
child form of the parent form in the constructor of the child form in
the dll file. The child form needs to refer back to the parent form
for customs methods to run

I want to pass "this" from the parent form into the child form, but
there does not seem to be anyway to do this using
assembley.createinstance.

Can anyone help please

peted

//loading routine to load child form from dll using latebiding and
reflection

private void loadDeviceInterfaceToSerialPort(int port,String
devicefile)
{
Assembly deviceInterfaceAssembly = null;

// Dynamically load the selected assembly.
deviceInterfaceAssembly = Assembly.LoadFile(devDir +
devicefile);
if (deviceInterfaceAssembly == null)
MessageBox.Show("not loaded");

// Get all types in assembly.

Type[] deviceInterfaceType =
deviceInterfaceAssembly.GetTypes();

ipLink.SetSerialPortDeviceInterface(port,
(Form)deviceInterfaceAssembly.CreateInstance(devic eInterfaceType[0].FullName));

ipLink.GetSerialPortDeviceInterface(port).MdiParen t =
this;
ipLink.GetSerialPortDeviceInterface(port).StartPos ition =
FormStartPosition.Manual;
ipLink.GetSerialPortDeviceInterface(port).FormBord erStyle =
FormBorderStyle.None;

ipLink.GetSerialPortDeviceInterface(port).Size = new
Size(400, this.ClientRectangle.Height);
ipLink.GetSerialPortDeviceInterface(port).Location = new
Point(540, 0);

ipLink.GetSerialPortDeviceInterface(port).Show();
}
// general form code class in the dll(s) to be loaded.

namespace K108Relay
{
public partial class K108Relay : Form
{
// static IPLinkerator.IPLinkMain host;

public K108Relay()
{
InitializeComponent();
// host.DeviceWrite("1I");
}

private void button1_Click(object sender, EventArgs e)
{
IPLinkMain.staticVar.DeviceWrite("1I");

}
}
}
Feb 21 '07 #2
I assumed that becasue i was instantiating a form from the dll an
interface would not be useable.

Is there any chance you could provide a code sample as to what the
interface would look like, and how i could mod my code to make use of
it ?

thanks
On Wed, 21 Feb 2007 01:36:10 -0800, Ciaran O''Donnell
<Ci************@discussions.microsoft.comwrote:
>There is an overload for that methods that take an object array for the
contructor parameters. It will then use these to find the correct contructor.
My suggestion though is to have an interface that all these forms in these
dlls should implement. Then you can do the reflection based on that interface
and it will make using the object easier and faster when you call interface
members rather then reflecting them.
Feb 21 '07 #3

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

Similar topics

4
by: Tim Werth | last post by:
I am trying to use reflection to add an event handler for the RowUpdated event of the OracleDataAdapter object (ODP.NET), but the same thing can be said for SqlDataAdapter if you only use...
10
by: Sunny | last post by:
Hi, I have an old problem which I couldn't solve so far. Now I have found a post in that group that gave me an idea, but I can not fully understand it. The problem is: I'm trying to use a...
1
by: Mike Malter | last post by:
I am just starting to work with reflection and I want to create a log that saves relevant information if a method call fails so I can call that method again later using reflection. I am...
0
by: TT (Tom Tempelaere) | last post by:
Hi there The following is a description to reproduce the problem. I do not know if this is a bug in the .NET environment/framework (I suspect it is), or if there is something that I am doing...
2
by: Lev | last post by:
Hi, I have some code that does reflection on an assembly I load. When I try to get the attributes on one of the methods implemented in the assembly, the MC++ version does not return anything....
1
by: Patrick | last post by:
Has been trying to get an ASP.NET DLL's modification date/time for the "release date/time" to be displayed on the page's footer Using: System.Reflection.Assembly...
4
by: Hakan ÖRNEK | last post by:
Hi, I have two dll's like First.dll and Second.dll compiled by vb.net, a object in first.dll and, b object in Second.dll. I need hold cross referances; a.breferance=b and b.areferance=a I...
7
by: Paul Hadfield | last post by:
Hi, I'm running into one problem with trying to call "Type.GetCustomAttributes(...)" on my reflected code. Basically - I can't trap my own custom attribute - I can only catch / identify system...
7
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
I have a C# logging assembly with a static constructor and methods that is called from another C# Assembly that is used as a COM interface for a VB6 Application. Ideally I need to build a file...
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: 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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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.