Private Delegate Function GetName() As String
Private Delegate Function GetDesc() As String
Public Delegate Sub Start()
<DllImport("kernel32")> _
Private Shared Function LoadLibrary(ByVal name As String) As IntPtr
End Function
<DllImport("kernel32")> _
Private Shared Function FreeLibrary(ByVal hmodule As IntPtr) As Boolean
End Function
<DllImport("kernel32")> _
Private Shared Function GetProcAddress(ByVal hmodule As IntPtr, ByVal name As String) As IntPtr
End Function
Private Function OpenPlugin(ByVal path As String) As PluginInfo
Dim ptr As IntPtr = LoadLibrary(path)
Dim paddr As IntPtr
Dim pinfo As PluginInfo = Nothing
If ptr.ToInt32() = 0 Then
MsgBox("Errore caricamento plugin")
Else
Try
pinfo = New PluginInfo
paddr = GetProcAddress(ptr, "GetName")
pinfo.name = Marshal.GetDelegateForFunctionPointer(paddr, GetType(GetName)).DynamicInvoke
pinfo.desc = Marshal.GetDelegateForFunctionPointer(GetProcAddress(ptr, "GetDesc"), GetType(GetDesc)).DynamicInvoke
pinfo.start = Marshal.GetDelegateForFunctionPointer(GetProcAddress(ptr, "Start"), GetType(Start))
pinfo.active = False
'FreeLibrary(ptr)
Catch ex As Exception
Application.Exit()
End Try
End If
OpenPlugin = pinfo
End Function