473,698 Members | 2,972 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

System.Reflecti on.Assembly.Loa dFrom + passing variables

Hi!

I have two applications:
* mainapp.exe
* plugin01.exe

I have 2 "friend" variables in mainapp.exe:
Friend gblConn as SqlConnection
Friend gblPath as string

When mainapp.exe starts, gblConn is declared as a new SqlConnection
and connects to the database, gblPath is filled with the current
application path.

If the user clicks "Button1" in Form1 of mainapp.exe, "PluginForm " of
plugin01.exe is loaded by this code:
Dim extAssembly As System.Reflecti on.Assembly =
System.Reflecti on.Assembly.Loa dFrom("c:\plugi n01.exe")
Dim extform As Form =
extAssembly.Cre ateInstance("pl ugin01.PluginFo rm", True)
Form1.AddOwnedF orm(extform)
extform.Show()

Everything works fine so far.

The problem is that I want to share the 2 friend-variables in
mainapp.exe with plugin01.exe (so I can use the same connection -
gblConn - for both applications, etc.).

So, how can I pass / share the variables from mainapp.exe to
plugin01.exe?

Sep 17 '07 #1
3 5363
Hi,

What you need is to create a method in the PluginForm that will accept
glbConn and glbPath as parameters and store them in PluginForm's private
fields:

Public Sub SetParams(conn as SqlConnection, path as String)
prvConn = conn
prvPath = path
End Sub

Then what's left is to call that method and pass glbConn and glbPath as its
parameters.

There are 2 ways to do that:

1. Use Reflection

Since you do not know the exact type of PluginForm in mainapp, you have
to assume the method SetParams is there and invoke it by name:

Dim t As Type = extform.GetType ()

Dim p As Object() = { gblConn , gblPath }
t.GetMethod("Se tParams").Invok e(extform, p)

2. Use an interface

You could also declare an interface in another module, e.g. Common,
which you would reference in mainapp and in plugin01:

Public Interface IPlugin
Sub SetParams(ByRef conn As SqlConnection, ByVal path As String)
End Interface

Then you should make PluginForm implement that interface.

In mainapp, you can then cast the result of CreateInstance to that
interface:
Dim extform As IPlugin = extAssembly.Cre ateInstance("pl ugin01.PluginFo rm",
True)

and call the SetParams method thru that interface:
extform.SetPara ms(gblConn, gblPath)

Hope this helps,

_____________
Adam Bieganski
http://godevelop.blogspot.com
"bi************ **@gmail.com" wrote:
Hi!

I have two applications:
* mainapp.exe
* plugin01.exe

I have 2 "friend" variables in mainapp.exe:
Friend gblConn as SqlConnection
Friend gblPath as string

When mainapp.exe starts, gblConn is declared as a new SqlConnection
and connects to the database, gblPath is filled with the current
application path.

If the user clicks "Button1" in Form1 of mainapp.exe, "PluginForm " of
plugin01.exe is loaded by this code:
Dim extAssembly As System.Reflecti on.Assembly =
System.Reflecti on.Assembly.Loa dFrom("c:\plugi n01.exe")
Dim extform As Form =
extAssembly.Cre ateInstance("pl ugin01.PluginFo rm", True)
Form1.AddOwnedF orm(extform)
extform.Show()

Everything works fine so far.

The problem is that I want to share the 2 friend-variables in
mainapp.exe with plugin01.exe (so I can use the same connection -
gblConn - for both applications, etc.).

So, how can I pass / share the variables from mainapp.exe to
plugin01.exe?

Sep 17 '07 #2
Hi!

Both methods work great! Thank you very much! :-)

With kind regards

Christian Binder

Sep 18 '07 #3
Cheers :)

_____________
Adam Bieganski
http://godevelop.blogspot.com
"bi************ **@gmail.com" wrote:
Hi!

Both methods work great! Thank you very much! :-)

With kind regards

Christian Binder

Sep 18 '07 #4

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

Similar topics

2
1481
by: forvino | last post by:
Hi Geeks, Ihave a doubt in dotNet reflection. I m developing a tool which will returns set of public(access specifier) methods of the selected assembly. this works completely fine, when the selected components are
3
2013
by: Jozsef Bekes | last post by:
Hi All, I am trying to use reflection for getting all the classes from the dlls of a software written by my company. I am using this line: Assembly.LoadFile(s).GetTypes() Gettypes fails, I guess because when one dll refers to another one of mine, Reflection does not find that dll. This is what the exception contains anyway. So I realized that I'd need to copy the dlls, or register them to
3
17065
by: System.Reflection Activator | last post by:
************************************** //Load the Assembly Assembly a = Assembly.LoadFrom(sAssembly); //Get Types so we can Identify the Interface. Type mytypes = a.GetTypes(); BindingFlags flags = (BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly); //Iterate through the Assembly to find Class with a Public Interface.
2
1408
by: forvino | last post by:
Hi Geeks, Ihave a doubt in dotNet reflection. I m developing a tool which will returns set of public(access specifier) methods of the selected assembly. this works completely fine, when the selected components are
1
2923
by: Brian | last post by:
I've looked through the previous posts on this one and have verified permissions and location of my Dlls, but I am still getting an exception when I try to Load an assembly. The directory where my Dlls are located give the ASPNET user full control, and all Dlls used by the Assembly in question are in the local folder with the rest of the web application Dlls. Could someone take a look at my error and shed some light on this?
4
2660
by: DOTNET | last post by:
Hi, Anybody help me regarding this error: I am assigning the values to the session variables when the button is clicked and passing these session variables to the next page and when I am printing these session variables they are printing. After that I am assigning these things in hidden object and in the form submit action I am receiving these hidden values like the following:
2
299
by: Gujju | last post by:
Hi all, I m new to this class.. With System.Reflection... u can create run time objects for a specified class in a assembly... Now if once the Assembly is loaded in the memory then does that means that it loads the Assembly again when we call the same function..
2
2539
by: Peted | last post by:
can anyone help me with the following bellow is a routine i use that works, that will load an assembly from a dll class from the HDD, and instantiate a form to be used to control a device. What is listed bellow works but 1 . before i got it to work this line
2
11010
by: =?Utf-8?B?c2FtMDFt?= | last post by:
I have a remoting application that was developed on a Windows XP SP2 machine with VS2005 SP1. I finally got everything deployed using Wix 3.0, and it works great. Problem is, when I install the msi on a W23 server SP2, I get the following error: System.Runtime.Remoting.RemotingException: Remoting configuration failed with the exception 'System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation....
0
8683
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8611
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9170
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9031
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8904
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8876
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4372
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4624
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.