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

Adding references during runtime

How do i add references during runtime?
Jul 19 '05 #1
8 6561
filip stas <fi********@pandora.be> wrote:
How do i add references during runtime?


Do you mean references to other assemblies? You don't. You have to load
them with reflection. What *exactly* do you want to do?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Jul 19 '05 #2
reference to other assemblies
"Jon Skeet" <sk***@pobox.com> wrote in message news:MP************************@news.microsoft.com ...
filip stas <fi********@pandora.be> wrote:
How do i add references during runtime?


Do you mean references to other assemblies? You don't. You have to load
them with reflection. What *exactly* do you want to do?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Jul 19 '05 #3
filip stas <fi********@pandora.be> wrote:
reference to other assemblies


That's not "exactly what you want to do" - that's 4 words. Say exactly
what situation you've got, what the *aim* of this is, etc.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Jul 19 '05 #4
[If you could make your newsreader wrap lines at about 70 characters it
would make your posts easier to reply to, by the way.]

filip stas <fi********@pandora.be> wrote:
creating dll files containing forms so they can be applied as sort of
an add-in in to a main program. I want to call those dll files and then
dynamically add menus for the forms contained in the dll into the main
program


In that case use Assembly.Load, Assembly.LoadFrom or one of the
similarly named methods. They vary in subtle ways, so be careful which
you pick.

You then use Assembly.GetType(String) to get the appropriate type, then
instantiate it by reflection etc.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Jul 19 '05 #5
Okay got at lot further for now, but have a following question

I have a main program wihich merges a menu created in a seperate dll. This mainprogram is an MDIcontainer. How can I make it so that the forms in thd dll use the form of the main program as mdiparent.
these are the codes i have:

testmodule.dll (seperate dll):
class menu
Private _hoofdIn As New MenuItem

Public Function getmenu()

Dim m As New MainMenu

_hoofdIn.Text = "TestModule"

_hoofdIn.MenuItems.Add("subtest", New EventHandler(AddressOf _sub1_Click))

m.MenuItems.Add(_hoofdIn)

Return m

End Function

Protected Sub _sub1_Click(ByVal sender As Object, ByVal e As System.EventArgs)

Dim sf As New sub1

sf.Show()

End Sub

testmodule.dll also contains sub1 form.

The main program:

Imports System.reflection

Public Class Form1

Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()

MyBase.New()

'This call is required by the Windows Form Designer.

InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Dispose()

End If

End If

MyBase.Dispose(disposing)

End Sub

'Required by the Windows Form Designer

Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer

'It can be modified using the Windows Form Designer.

'Do not modify it using the code editor.

Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu

Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem

Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem

Friend WithEvents Button1 As System.Windows.Forms.Button

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

Me.MainMenu1 = New System.Windows.Forms.MainMenu

Me.MenuItem1 = New System.Windows.Forms.MenuItem

Me.MenuItem2 = New System.Windows.Forms.MenuItem

Me.Button1 = New System.Windows.Forms.Button

Me.SuspendLayout()

'

'MainMenu1

'

Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1})

'

'MenuItem1

'

Me.MenuItem1.Index = 0

Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem2})

Me.MenuItem1.Text = "bestand"

'

'MenuItem2

'

Me.MenuItem2.Index = 0

Me.MenuItem2.Text = "sluiten"

'

'Button1

'

Me.Button1.Location = New System.Drawing.Point(104, 104)

Me.Button1.Name = "Button1"

Me.Button1.TabIndex = 0

Me.Button1.Text = "merge"

'

'Form1

'

Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)

Me.ClientSize = New System.Drawing.Size(292, 273)

Me.Controls.Add(Me.Button1)

Me.IsMdiContainer = True

Me.Menu = Me.MainMenu1

Me.Name = "Form1"

Me.Text = "Form1"

Me.ResumeLayout(False)

End Sub

#End Region

Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click

End

End Sub

Private path As String = "c:\testmod"

Private objmenu As MainMenu

Public Sub CreateMenu()

Dim refmodule As [Assembly] = [Assembly].LoadFile(path & "\testmodule.dll")

Dim t As Type = refmodule.GetType("testmodule.menu")

Dim obj As Object = Activator.CreateInstance(t)

Dim ar As Menu = obj.getmenu()

Me.MainMenu1.MergeMenu(ar)

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

CreateMenu()

End Sub

End Class

"Jon Skeet" <sk***@pobox.com> wrote in message news:MP************************@news.microsoft.com ...
[If you could make your newsreader wrap lines at about 70 characters it
would make your posts easier to reply to, by the way.]

filip stas <fi********@pandora.be> wrote:
creating dll files containing forms so they can be applied as sort of
an add-in in to a main program. I want to call those dll files and then
dynamically add menus for the forms contained in the dll into the main
program


In that case use Assembly.Load, Assembly.LoadFrom or one of the
similarly named methods. They vary in subtle ways, so be careful which
you pick.

You then use Assembly.GetType(String) to get the appropriate type, then
instantiate it by reflection etc.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Jul 19 '05 #6
Okay got at lot further for now, but have a following question

I have a main program wihich merges a menu created in a seperate dll. This mainprogram is an MDIcontainer. How can I make it so that the forms in thd dll use the form of the main program as mdiparent.
these are the codes i have:

testmodule.dll (seperate dll):
class menu
Private _hoofdIn As New MenuItem

Public Function getmenu()

Dim m As New MainMenu

_hoofdIn.Text = "TestModule"

_hoofdIn.MenuItems.Add("subtest", New EventHandler(AddressOf _sub1_Click))

m.MenuItems.Add(_hoofdIn)

Return m

End Function

Protected Sub _sub1_Click(ByVal sender As Object, ByVal e As System.EventArgs)

Dim sf As New sub1

sf.Show()

End Sub

testmodule.dll also contains sub1 form.

The main program:

Imports System.reflection

Public Class Form1

Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()

MyBase.New()

'This call is required by the Windows Form Designer.

InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Dispose()

End If

End If

MyBase.Dispose(disposing)

End Sub

'Required by the Windows Form Designer

Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer

'It can be modified using the Windows Form Designer.

'Do not modify it using the code editor.

Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu

Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem

Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem

Friend WithEvents Button1 As System.Windows.Forms.Button

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

Me.MainMenu1 = New System.Windows.Forms.MainMenu

Me.MenuItem1 = New System.Windows.Forms.MenuItem

Me.MenuItem2 = New System.Windows.Forms.MenuItem

Me.Button1 = New System.Windows.Forms.Button

Me.SuspendLayout()

'

'MainMenu1

'

Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1})

'

'MenuItem1

'

Me.MenuItem1.Index = 0

Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem2})

Me.MenuItem1.Text = "bestand"

'

'MenuItem2

'

Me.MenuItem2.Index = 0

Me.MenuItem2.Text = "sluiten"

'

'Button1

'

Me.Button1.Location = New System.Drawing.Point(104, 104)

Me.Button1.Name = "Button1"

Me.Button1.TabIndex = 0

Me.Button1.Text = "merge"

'

'Form1

'

Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)

Me.ClientSize = New System.Drawing.Size(292, 273)

Me.Controls.Add(Me.Button1)

Me.IsMdiContainer = True

Me.Menu = Me.MainMenu1

Me.Name = "Form1"

Me.Text = "Form1"

Me.ResumeLayout(False)

End Sub

#End Region

Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click

End

End Sub

Private path As String = "c:\testmod"

Private objmenu As MainMenu

Public Sub CreateMenu()

Dim refmodule As [Assembly] = [Assembly].LoadFile(path & "\testmodule.dll")

Dim t As Type = refmodule.GetType("testmodule.menu")

Dim obj As Object = Activator.CreateInstance(t)

Dim ar As Menu = obj.getmenu()

Me.MainMenu1.MergeMenu(ar)

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

CreateMenu()

End Sub

End Class

"Jon Skeet" <sk***@pobox.com> wrote in message news:MP************************@news.microsoft.com ...
[If you could make your newsreader wrap lines at about 70 characters it
would make your posts easier to reply to, by the way.]

filip stas <fi********@pandora.be> wrote:
creating dll files containing forms so they can be applied as sort of
an add-in in to a main program. I want to call those dll files and then
dynamically add menus for the forms contained in the dll into the main
program


In that case use Assembly.Load, Assembly.LoadFrom or one of the
similarly named methods. They vary in subtle ways, so be careful which
you pick.

You then use Assembly.GetType(String) to get the appropriate type, then
instantiate it by reflection etc.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Jul 19 '05 #7
filip stas <fi********@pandora.be> wrote:
Okay got at lot further for now, but have a following question


<snip>

I'm afraid the combination of:

o Your post's text still not wrapping pleasantly
o The program code having a blank line between each real line
o It being in VB.NET when I'm really a C# coder
o Me not quite understanding what you're after
o Me not knowing a lot about MDI containers
o It being nearly time to go home
o Me not having got much sleep last night

makes me reluctant to tackle this at the moment.

A quick look at it suggests you should:

a) Get familiar with reflection if you're not already
b) Alter the code so it loads the DLL, finds the type, instantiates it,
casts the instance to MenuItem, and then uses it as it would do any
other menu item.

That may well not be what you're after though...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Jul 19 '05 #8
Hi,

I am planning to do a quite similar thing for my
application.
I have different function that belongs to different
assembly. Based on available function on the system I need
my application to be self configurable.
Kind of plug in as you mentionned with menu belonging to
the plugin and forms if any.

Did you finnaly make it happen ? if yes how
do u have sample?

For my case I have only a main form, not MDI

thanks for your info
(I am VB programmer)
regards
Serge
-----Original Message-----
creating dll files containing forms so they can be applied as sort of an add-in in to a main program. I want
to call those dll files and then dynamically add menus for
the forms contained in the dll into the main program "Jon Skeet" <sk***@pobox.com> wrote in message news:MP************************@news.microsoft.com ... filip stas <fi********@pandora.be> wrote:
> reference to other assemblies
That's not "exactly what you want to do" - that's 4

words. Say exactly what situation you've got, what the *aim* of this is, etc.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too

Jul 19 '05 #9

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

Similar topics

2
by: manohar.shankar | last post by:
Hi, I have been searching on this topic for quite sometime and didnt get any answer. Is there a way I can extend/add methods/properties to a C# class during runtime. eg., I have class:...
3
by: MIGUEL | last post by:
Hi all, I'm quite lost with how adding web references to a project creates proxy classes. I've developed a web service with two classes inside and that contains three references to three...
8
by: filip stas | last post by:
How do i add references during runtime?
3
by: _DS | last post by:
The two obvious methods for ref'ing assemblies are: Add a reference and 'Browse' for the actual DLL OR Add existing project to the solution, then add a ref to 'Project'. 1: I'd like to...
5
by: Michael Russell | last post by:
Hi all, Using C#, I've created a simple wrapper class for using Excel. I have Office Pro 2003 installed on my devel machine. The wrapper class works great, reading and writing to/from Excel. ...
32
by: Zytan | last post by:
Are they possible? I am passing in a large array of Bytes, thus I don't want to use ByVal. Zytan
4
by: krishm | last post by:
hi i have a COM dll and i want to access the methods in the dll through my program. but i need to add that dll as reference during runtime and not the way references are generally added...
5
by: DBC User | last post by:
I have a situation, where I need to add 4 or 5 data files (they change every time I build) in my project during build time and somehow I need a way to access these files during runtime. So I have...
7
by: chage | last post by:
Hi, I have been searching around to try adding reference assembly to another assembly during runtime, programatically. Is this possible in .Net? The reason for this is because i am having...
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: 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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
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...

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.