Click here to Skip to main content
15,173,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Base on plugin Sample I was able to load two plugins (DLL) and execute code on the DLL using the Plugin Interface from the main form..
Now I need to be able to raise an event in the Main Form using the DLL

How do I do that :-)
Can somebody point me in the right direction ?
Also is there an "easy" way of implementing Bi-directional calling within the same Interface (Plugin Contract)?
- FORM > DLL (Working)
- DLL > FORM (How ??)

Plugin "Contract":
Public Interface IPlugin
    ReadOnly Property Name() As String ' plugin Name
    Sub DoSomething()
    Function Calc(ByVal A As Double) As Double
End Interface

DLL Plugin
Public Class Plugin_Copley
    Implements IPlugin

    Public Function Calc(ByVal A As Double) As Double Implements IPlugin.Calc
        Return A * 1.200056
    End Function

    Public Sub DoSomething() Implements IPlugin.DoSomething
        System.Windows.Forms.MessageBox.Show("Do Something in Copley Plugin")
    End Sub

    Public ReadOnly Property Name As String Implements IPlugin.Name
            Name = "Copley Plugin"
        End Get
    End Property
End Class

Main Form
Public Class Main
    Private _Plugins As Dictionary(Of String, IPlugin)
    Dim Y_Button As Integer = 5
    Private Sub Main_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

    End Sub

    Sub New()

        ' This call is required by the designer.

        ' Add any initialization after the InitializeComponent() call.
    End Sub

    Private Sub Load_PluginList()
        _Plugins = New Dictionary(Of String, IPlugin)
        Dim plugins As ICollection(Of IPlugin) = PluginLoader.LoadPluginList("PLUGINS")

        If plugins Is Nothing Then
            MsgBox("No plugins loaded. Application Closed.")
        End If

        For Each item In plugins
            _Plugins.Add(item.Name, item)

            Dim b = New Button With {
                .Text = item.Name}
            AddHandler b.Click, AddressOf b_Click
            Dim t As Point
            t.X = 5
            t.Y = Y_Button
            Y_Button = Y_Button + 30
            b.Location = t
    End Sub
    Private Sub b_Click(sender As Object, e As System.EventArgs)
        Dim b As Button = sender
        If b IsNot Nothing Then
            Dim key As String = b.Text.ToString()
            If _Plugins.ContainsKey(key) Then
                Dim plugin As IPlugin = _Plugins(key)
            End If
        End If
    End Sub

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900