Add-ins for your program
If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
5 posts
Page 1 of 1
I was wondering how you cod imement add-ins to your program. What code should I put in the program and what code should I use in he add-in?
Please help
-Comathi-
Please help

-Comathi-
Last edited by comathi on Mon Oct 24, 2011 8:41 pm, edited 1 time in total.
Google out System.Reflection, and adding dll controls during runtime.
You will need a DLL that both your program and the program has a reference to. Call the project PluginBase. In the code you will need a plugin class/interface that every plugin inherits/implements like:
Code: Select all
Or you could use an interface:
Public MustInherit Class PluginBase
Public MustOverride ReadOnly Property Name As String
Public MustOverride ReadOnly Property Creator As String
Public MustOverride ReadOnly Property Description As String
'Any optional properties you plugin might need
End Class
Code: Select all
So a plugin might have this code:
Public Interface IPlugin
ReadOnly Property Name As String
ReadOnly Property Creator As String
ReadOnly Property Description As String
'Anything else
End Interface
Code: Select all
Or the interface way:
Public Class MyPlugin
Inherits PluginBase.PluginBase
Public Overrides ReadOnly Property Name As String
Get
Return "PluginName"
End Get
End Property
Public Overrides ReadOnly Property Creator As String
Get
Return "PluginCreator"
End Get
End Property
Public Overrides ReadOnly Property Description As String
Get
Return "A plugin that currently does nothing."
End Get
End Property
End Class
Code: Select all
Your main project could then load the plugins:
Public Class MyPlugin
Implements PluginBase.IPlugin
Public ReadOnly Property Name As String Implements PluginBase.IPlugin.Name
Get
Return "PluginName"
End Get
End Property
Public ReadOnly Property Creator As String Implements PluginBase.IPlugin.Creator
Get
Return "Creator"
End Get
End Property
Public ReadOnly Property Description As String Implements PluginBase.IPlugin.Description
Get
Return "This is a plugin that currently does nothing."
End Get
End Property
End Class
Code: Select all
Or using the interface:
Public Function LoadPlugins(Directory As String) As PluginBase.PluginBase()
Dim PluginType As Type = GetType(PluginBase.PluginBase)
Dim Plugins As New List(Of PluginBase.PluginBase)
For Each file As String In IO.Directory.GetFiles(Directory, "*.dll")
Dim Assembly As Reflection.Assembly = Reflection.Assembly.LoadFrom(file)
For Each [class] As Type In Assembly.GetTypes()
If [class].IsSubclassOf(PluginType) And Not [class].IsAbstract Then
Plugins.Add(Activator.CreateInstance([class]))
End If
Next
Next
Return Plugins.ToArray()
End Function
Code: Select all
I did not test this code, im sure it work, but it might be a few typos therePublic Function LoadPlugins(Directory As String) As PluginBase.IPlugin()
Dim PluginType As Type = GetType(PluginBase.IPlugin)
Dim Plugins As New List(Of PluginBase.IPlugin)
For Each file As String In IO.Directory.GetFiles(Directory, "*.dll")
Dim Assembly As Reflection.Assembly = Reflection.Assembly.LoadFrom(file)
For Each [class] As Type In Assembly.GetTypes()
If [class].IsSubclassOf(PluginType) And Not [class].IsAbstract Then
Plugins.Add(Activator.CreateInstance([class]))
End If
Next
Next
Return Plugins.ToArray()
End Function
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;
Over 30 projects with source code!
Please give reputation to helpful members!
![Image]()
![Image]()
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;
Over 30 projects with source code!
Please give reputation to helpful members!

5 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023