How do i add references during runtime?
Adding references during runtime
Collapse
This topic is closed.
X
X
-
filip stasTags: None -
Jon Skeet
Re: Adding references during runtime
filip stas <filip.stas@pan dora.be> wrote:[color=blue]
> How do i add references during runtime?[/color]
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 - <skeet@pobox.co m>
Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.
If replying to the group, please do not mail me too
-
filip stas
Re: Adding references during runtime
reference to other assemblies
"Jon Skeet" <skeet@pobox.co m> wrote in message news:MPG.19b6c0 3938386d9c98a3b 0@news.microsof t.com...
filip stas <filip.stas@pan dora.be> wrote:[color=blue]
> How do i add references during runtime?[/color]
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 - <skeet@pobox.co m>
Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.
If replying to the group, please do not mail me too
Comment
-
Jon Skeet
Re: Adding references during runtime
filip stas <filip.stas@pan dora.be> wrote:[color=blue]
> reference to other assemblies[/color]
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 - <skeet@pobox.co m>
Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.
If replying to the group, please do not mail me too
Comment
-
Jon Skeet
Re: Adding references during runtime
[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 <filip.stas@pan dora.be> wrote:[color=blue]
> 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[/color]
In that case use Assembly.Load, Assembly.LoadFr om or one of the
similarly named methods. They vary in subtle ways, so be careful which
you pick.
You then use Assembly.GetTyp e(String) to get the appropriate type, then
instantiate it by reflection etc.
--
Jon Skeet - <skeet@pobox.co m>
Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.
If replying to the group, please do not mail me too
Comment
-
filip stas
Re: Adding references during runtime
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.MenuIt ems.Add("subtes t", New EventHandler(Ad dressOf _sub1_Click))
m.MenuItems.Add (_hoofdIn)
Return m
End Function
Protected Sub _sub1_Click(ByV al sender As Object, ByVal e As System.EventArg s)
Dim sf As New sub1
sf.Show()
End Sub
testmodule.dll also contains sub1 form.
The main program:
Imports System.reflecti on
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.
InitializeCompo nent()
'Add any initialization after the InitializeCompo nent() 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.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er
'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.Diagnos tics.DebuggerSt epThrough()> Private Sub InitializeCompo nent()
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.SuspendLayou t()
'
'MainMenu1
'
Me.MainMenu1.Me nuItems.AddRang e(New System.Windows. Forms.MenuItem( ) {Me.MenuItem1})
'
'MenuItem1
'
Me.MenuItem1.In dex = 0
Me.MenuItem1.Me nuItems.AddRang e(New System.Windows. Forms.MenuItem( ) {Me.MenuItem2})
Me.MenuItem1.Te xt = "bestand"
'
'MenuItem2
'
Me.MenuItem2.In dex = 0
Me.MenuItem2.Te xt = "sluiten"
'
'Button1
'
Me.Button1.Loca tion = New System.Drawing. Point(104, 104)
Me.Button1.Name = "Button1"
Me.Button1.TabI ndex = 0
Me.Button1.Text = "merge"
'
'Form1
'
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.ClientSize = New System.Drawing. Size(292, 273)
Me.Controls.Add (Me.Button1)
Me.IsMdiContain er = 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.EventArg s) 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.dl l")
Dim t As Type = refmodule.GetTy pe("testmodule. menu")
Dim obj As Object = Activator.Creat eInstance(t)
Dim ar As Menu = obj.getmenu()
Me.MainMenu1.Me rgeMenu(ar)
End Sub
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click
CreateMenu()
End Sub
End Class
"Jon Skeet" <skeet@pobox.co m> wrote in message news:MPG.19b733 f6ab9c34f298a3d d@news.microsof t.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 <filip.stas@pan dora.be> wrote:[color=blue]
> 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[/color]
In that case use Assembly.Load, Assembly.LoadFr om or one of the
similarly named methods. They vary in subtle ways, so be careful which
you pick.
You then use Assembly.GetTyp e(String) to get the appropriate type, then
instantiate it by reflection etc.
--
Jon Skeet - <skeet@pobox.co m>
Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.
If replying to the group, please do not mail me too
Comment
-
filip stas
Re: Adding references during runtime
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.MenuIt ems.Add("subtes t", New EventHandler(Ad dressOf _sub1_Click))
m.MenuItems.Add (_hoofdIn)
Return m
End Function
Protected Sub _sub1_Click(ByV al sender As Object, ByVal e As System.EventArg s)
Dim sf As New sub1
sf.Show()
End Sub
testmodule.dll also contains sub1 form.
The main program:
Imports System.reflecti on
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.
InitializeCompo nent()
'Add any initialization after the InitializeCompo nent() 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.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er
'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.Diagnos tics.DebuggerSt epThrough()> Private Sub InitializeCompo nent()
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.SuspendLayou t()
'
'MainMenu1
'
Me.MainMenu1.Me nuItems.AddRang e(New System.Windows. Forms.MenuItem( ) {Me.MenuItem1})
'
'MenuItem1
'
Me.MenuItem1.In dex = 0
Me.MenuItem1.Me nuItems.AddRang e(New System.Windows. Forms.MenuItem( ) {Me.MenuItem2})
Me.MenuItem1.Te xt = "bestand"
'
'MenuItem2
'
Me.MenuItem2.In dex = 0
Me.MenuItem2.Te xt = "sluiten"
'
'Button1
'
Me.Button1.Loca tion = New System.Drawing. Point(104, 104)
Me.Button1.Name = "Button1"
Me.Button1.TabI ndex = 0
Me.Button1.Text = "merge"
'
'Form1
'
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.ClientSize = New System.Drawing. Size(292, 273)
Me.Controls.Add (Me.Button1)
Me.IsMdiContain er = 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.EventArg s) 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.dl l")
Dim t As Type = refmodule.GetTy pe("testmodule. menu")
Dim obj As Object = Activator.Creat eInstance(t)
Dim ar As Menu = obj.getmenu()
Me.MainMenu1.Me rgeMenu(ar)
End Sub
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click
CreateMenu()
End Sub
End Class
"Jon Skeet" <skeet@pobox.co m> wrote in message news:MPG.19b733 f6ab9c34f298a3d d@news.microsof t.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 <filip.stas@pan dora.be> wrote:[color=blue]
> 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[/color]
In that case use Assembly.Load, Assembly.LoadFr om or one of the
similarly named methods. They vary in subtle ways, so be careful which
you pick.
You then use Assembly.GetTyp e(String) to get the appropriate type, then
instantiate it by reflection etc.
--
Jon Skeet - <skeet@pobox.co m>
Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.
If replying to the group, please do not mail me too
Comment
-
Jon Skeet
Re: Adding references during runtime
filip stas <filip.stas@pan dora.be> wrote:[color=blue]
> Okay got at lot further for now, but have a following question[/color]
<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 - <skeet@pobox.co m>
Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.
If replying to the group, please do not mail me too
Comment
-
serge calderara
Re: Adding references during runtime
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
[color=blue]
>-----Original Message-----
>creating dll files containing forms so they can be[/color]
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[color=blue]
> "Jon Skeet" <skeet@pobox.co m> wrote in message[/color]
news:MPG.19b6e1 343b16075698a3b 7@news.microsof t.com...[color=blue]
> filip stas <filip.stas@pan dora.be> wrote:[color=green]
> > reference to other assemblies[/color]
>
> That's not "exactly what you want to do" - that's 4[/color]
words. Say exactly[color=blue]
> what situation you've got, what the *aim* of this is,[/color]
etc.[color=blue]
>
> --
> Jon Skeet - <skeet@pobox.co m>
> http://www.pobox.com/~skeet/
> If replying to the group, please do not mail me too[/color]
Comment
Comment