Nov 3, 2014 05:45 AM
(This post was last modified: Nov 3, 2014 05:49 AM by imi-tat0r.)
Hey there.
First of all you should read the tutorial by TheUnknownProgrammer, because this is based on his code or it extends his code a bit.
You can find his tutorial here: https://hackforums.net/showthread.php?tid=2169571
In this tutorial I will show you how you can extend his Pluginsystem a bit more.
We will be adding a Tabpage for each Plugin we run, we will be able to load as many plugins as we want and we will be able to communicate from AND to the Plugin.
Remember this is very basic so you can learn from it but it is no way near perfect.
Step 1 - Designing the Main application
At first we will create our Host application which will run all our Plugins. Mine looks like this:
![[Image: 458a4cefad.png]](https://puu.sh/cByOe/458a4cefad.png)
The textbox under the "Run Plug-in" Button will be filled with the Pluginname so we know which one we want to run/close.
The rest should be selfexplaining.
Step 2 - The Connector Library
Our goal is, to create a new Tabpage whenever we load and run a plugin and to delete the Tabpage when we close the Plugin.
Also we want to communicate from the Mainapplication to the Plugin and vice versa
![[Image: df1f444342.png]](https://puu.sh/cByXq/df1f444342.png)
Step 3 - The Connector in the Main Application
After creating the connector library, save and build it and go back to your main application. Add your Plugin connector library reference to the project and create a new class, called Connector. Then add the following code to implement the IConnector interface.
After pressing enter, our subroutines should show up being empty. Now we can fill them with code.
![[Image: 85c05304d9.png]](https://puu.sh/cBzbS/85c05304d9.png)
Step 4 - Creating the Plugin
As we are adding the Form we create now to the Tabpage we add in the Main Application, the Form should be borderless and the exact same size than the TabPages are in our Main Application.
For me this is: 544; 324
My form looks like this:
![[Image: 1177e479ca.png]](https://puu.sh/cBzkp/1177e479ca.png)
Now add a new Class like this:
And the Subs "StartPlugIn" and "DataToPlugin" should appear. In the class of the Form we have to give the buttons something to do.
![[Image: fdafe77946.png]](https://puu.sh/cBztA/fdafe77946.png)
It is important that, wherever I used "PluginTest", you use your Pluginname. And it always has to be the same name or it might fail.
Our Class "PluginStart" should look like this
![[Image: d0c9fc07be.png]](https://puu.sh/cBzxr/d0c9fc07be.png)
DataToPlugin will just reassamble our give Object array to Strings.
Step 5 - Finishing the Main application
At the imports we have to use
Now on our Load Plugin button we will add this code:
On our Run Plugin Button we add this code:
Textbox2.Text is the little Box in our Main application where we have to put in the Pluginname.
On our Close Plugin Button we will do like this:
and on the Send Data to Plugin Button this is our code:
now your code should look like this
![[Image: 3dbc6fdb74.png]](https://puu.sh/cBAEM/3dbc6fdb74.png)
Step 6 - Testing
Opening, Running and sending data from a Plugin
Spoiler (Click to View)
Sending data to a Plugin and Closing it
Spoiler (Click to View)
First of all you should read the tutorial by TheUnknownProgrammer, because this is based on his code or it extends his code a bit.
You can find his tutorial here: https://hackforums.net/showthread.php?tid=2169571
In this tutorial I will show you how you can extend his Pluginsystem a bit more.
We will be adding a Tabpage for each Plugin we run, we will be able to load as many plugins as we want and we will be able to communicate from AND to the Plugin.
Remember this is very basic so you can learn from it but it is no way near perfect.
Step 1 - Designing the Main application
At first we will create our Host application which will run all our Plugins. Mine looks like this:
![[Image: 458a4cefad.png]](https://puu.sh/cByOe/458a4cefad.png)
The textbox under the "Run Plug-in" Button will be filled with the Pluginname so we know which one we want to run/close.
The rest should be selfexplaining.
Step 2 - The Connector Library
Our goal is, to create a new Tabpage whenever we load and run a plugin and to delete the Tabpage when we close the Plugin.
Also we want to communicate from the Mainapplication to the Plugin and vice versa
![[Image: df1f444342.png]](https://puu.sh/cByXq/df1f444342.png)
Step 3 - The Connector in the Main Application
After creating the connector library, save and build it and go back to your main application. Add your Plugin connector library reference to the project and create a new class, called Connector. Then add the following code to implement the IConnector interface.
Code
Imports PluginConnector
Public Class Connector
Implements IConnector
Dim T As New Dictionary(Of String, TabPage)
Dim frm As New Form1
Public Sub New(ByVal frm As Form1)
Me.frm = frm
End SubAfter pressing enter, our subroutines should show up being empty. Now we can fill them with code.
![[Image: 85c05304d9.png]](https://puu.sh/cBzbS/85c05304d9.png)
Step 4 - Creating the Plugin
As we are adding the Form we create now to the Tabpage we add in the Main Application, the Form should be borderless and the exact same size than the TabPages are in our Main Application.
For me this is: 544; 324
My form looks like this:
![[Image: 1177e479ca.png]](https://puu.sh/cBzkp/1177e479ca.png)
Now add a new Class like this:
Code
Public Class PluginStart
Implements IPlugin
Public frm As New Form1And the Subs "StartPlugIn" and "DataToPlugin" should appear. In the class of the Form we have to give the buttons something to do.
![[Image: fdafe77946.png]](https://puu.sh/cBztA/fdafe77946.png)
It is important that, wherever I used "PluginTest", you use your Pluginname. And it always has to be the same name or it might fail.
Our Class "PluginStart" should look like this
![[Image: d0c9fc07be.png]](https://puu.sh/cBzxr/d0c9fc07be.png)
DataToPlugin will just reassamble our give Object array to Strings.
Step 5 - Finishing the Main application
At the imports we have to use
Code
Imports System.ReflectionNow on our Load Plugin button we will add this code:
Code
Dim ofd As New OpenFileDialog
If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then
'load the assembly
Dim pluginassembly As Assembly = Assembly.LoadFile(ofd.FileName)
'get the StartOfPlugin class by using GetType("<typename>")
Dim pluginclass As IPlugin = CType(Activator.CreateInstance(pluginassembly.GetType(pluginassembly.GetName.Name & ".PluginStart")), IPlugin)
Plugs.Add(pluginassembly.GetName.Name, CType(Activator.CreateInstance(pluginassembly.GetType(pluginassembly.GetName.Name & ".PluginStart")), IPlugin))
End IfOn our Run Plugin Button we add this code:
Code
Plugs(TextBox2.Text).StartPlugIn(Connector)On our Close Plugin Button we will do like this:
Code
Connector.Disconnect(TextBox2.Text)and on the Send Data to Plugin Button this is our code:
Code
Dim td As Object() = TextBox1.Text.Split(",")
Plugs(td(0)).DataToPlugin(td)now your code should look like this
![[Image: 3dbc6fdb74.png]](https://puu.sh/cBAEM/3dbc6fdb74.png)
Step 6 - Testing
Opening, Running and sending data from a Plugin
Spoiler (Click to View)
Sending data to a Plugin and Closing it
Spoiler (Click to View)


![[Image: uzpE9zW.jpg]](https://i.imgur.com/uzpE9zW.jpg)

