stuck on reflection latebinding assembly problem

P

Peted

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(deviceInterfaceType[0].FullName));

ipLink.GetSerialPortDeviceInterface(port).MdiParent =
this;
ipLink.GetSerialPortDeviceInterface(port).StartPosition =
FormStartPosition.Manual;
ipLink.GetSerialPortDeviceInterface(port).FormBorderStyle =
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");

}
}
}
 
G

Guest

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.
 
P

Peted

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top