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
End Interface
Public Interface IHost
Sub ShowFeedback(ByVal strFeedback As String)
End Interface
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
Implements PluginSample.Interfaces.IPlugin
Private objHost As PluginSample.Interfaces.IHost
Public Sub Initialize(ByVal Host As PluginSample.Interfaces.IHost) _
Implements PluginSample.Interfaces.IPlugin.Initialize
objHost = Host
End Sub
Public ReadOnly Property Name() As String Implements _
PluginSample.Interfaces.IPlugin.Name
Get
Return "Example Plugin 1 - Adds two numbers"
End Get
End Property
Public Function Calculate(ByVal int1 As Integer, ByVal int2 As Integer) As Double _
Implements PluginSample.Interfaces.IPlugin.Calculate
Return int1 + int2
End Function
End Class
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.
Comments