Writing the Interfaces
First we create a new project of type Class Library, and define the two interfaces. For the purposes of this tutorial they will be very simple. Each plugin will offer a property with the name of the plugin, and a function which accepts two integers and returns a double. The host interface will expose a method so that the plugin can cause the host to show a message box.
Public Interface IPlugin
Sub Initialize(ByVal Host As IHost)
ReadOnly Property Name() As String
Function Calculate(ByVal int1 As Integer, ByVal int2 As Integer) As Double
Public Interface IHost
Sub ShowFeedback(ByVal strFeedback As String)
Lastly we set the build output directory to a common directory, where we'll also put the host application and the plugins.
Writing the first plugin
Since we'll need at least one to test the host application with, now we can write a simple plugin. Again, we create a new project of type Class Library, set the build output directory, and make sure we reference the interface class library we just created. Next, we modify the class provided thus:
Public Class Class1
Private objHost As PluginSample.Interfaces.IHost
Public Sub Initialize(ByVal Host As PluginSample.Interfaces.IHost) _
objHost = Host
Public ReadOnly Property Name() As String Implements _
Return "Example Plugin 1 - Adds two numbers"
Public Function Calculate(ByVal int1 As Integer, ByVal int2 As Integer) As Double _
Return int1 + int2
We've just created a simple plugin, which adds the two numbers provided together. Although we are accepting and storing a reference to the host interface, we don't actually use it. We'll do that in the next plugin we write.