Hello Noone
The concept is pretty simple
1. create a generic interface and compile this to a dll
2. create your plugin and implement the interface in the class you want to
start from the outside
3. create a application and set a reference to the interface dll
now you do
Dim objAssembly As Reflection.Assembly
objAssembly = Reflection.Assembly.LoadFrom(FullPathToAssemblyDllOrExe)
Dim YourObject as Yourinterface =
DirectCast(objAssembly.CreateInstance(Namespace.YourClassToInvoke),
Yourinterface)
Note :
Namespace.YourClassToInvoke ( namespace defaults to the assembly name
but
can be set under project , properties , application , root namespace )
And that`s it !!
YourObject is now initiated and can be controled from your code with the
interface that you provided
if You need anny more help feel free to ask ( i can create a small demo
for
you and upload it to my server for you to download )
Regards
Michel Posseth
:
Thank you very much for the post but I have no idea what you are
doing. I have never worked with any of the "Reflection" classes. I
am a bit newer to VB.net so I think I am missing something. Can you
explain what is going on in more detail and less Dutch? hehe... : )
Thanks,
Josh
On Wed, 31 Jan 2007 21:15:08 +0100, "Michel Posseth [MCP]"
Well i did this with an interface
here is my reallife code from a wotking project ( sorry comments are
for my
co workers and they are Dutch )
'--------------------------------------------------------------------------------------
'---
'--- clsGetObjectFromFile
'---
'--- Purpose : start returns an initiated IiQueuObject
'---
'--- Made by : Michel Posseth [MCP]
'--- Date : 14-11-2006
'--- Revissions : 21-11-2006 : AssPath ingebouwd voor flexibiliteid
'---
'--------------------------------------------------------------------------------------
Option Strict On
Option Explicit On
Imports System.IO
Public Class clsGetObjectFromFile
''' <summary>
''' Laad een object by zijn assembly naam en class naam
''' het te laden object moet een IiQueuObject interface bezitten
''' </summary>
''' <param name="vstrAssemblyName">Name of the VSTR assembly.</param>
''' <param name="vstrClassName">Name of the VSTR class.</param>
''' <returns></returns>
Public Shared Function LoadMeByName(ByVal vstrAssemblyName As String, _
ByVal vstrClassName As String) As ista.IiQueuObject
'<21-11-2006 MP>
If vstrAssemblyName.StartsWith("[AssPath]") Then
Dim appath As String =
System.Reflection.Assembly.GetExecutingAssembly.Location
vstrAssemblyName = vstrAssemblyName.Replace("[AssPath]", "")
vstrAssemblyName = Path.Combine(appath, vstrAssemblyName)
End If
'</21-11-2006 MP>
Dim objAssembly As Reflection.Assembly
If Not My.Computer.FileSystem.FileExists(vstrAssemblyName) Then
ServMain.WriteLogentry("Assembly niet aanwezig : " & vstrAssemblyName,
EventLogEntryType.Error)
'de assembly is niet aanwezig op deze lokatie
Return Nothing
End If
objAssembly = Reflection.Assembly.LoadFrom(vstrAssemblyName)
'voer een cast uit naar ista.IiQueuObject interface
Try
LoadMeByName = DirectCast(objAssembly.CreateInstance(vstrClassName),
ista.IiQueuObject)
Catch ex As Exception
ServMain.WriteLogentry("Assembly bezit niet de juiste interface : " &
vstrAssemblyName, EventLogEntryType.Error)
Return Nothing
End Try
If LoadMeByName Is Nothing Then
Dim msg As String
msg = "Assembly : " & vstrAssemblyName & Environment.NewLine & _
"Type : " & vstrClassName & " is niet gestart om onduidelijke reden"
ServMain.WriteLogentry(msg, EventLogEntryType.Error)
'geen error gewoon niets terug geven
'wanneer we dus iets anders hebben als een Nothing pointer
'dan hebben we een geinitialiseerd object
Return Nothing
End If
End Function
End Class
here is my generic interface
'--------------------------------------------------------------------------------------
'---
'--- Purpose : Provide an generic interface for the Queu
'---
'--- Made by : Michel Posseth [MCP]
'--- Date : 20-11-2006
'--- Revissions :
'---
'--- Remarks : Do not break the interface signature !!
'--- you may extend but never remove property`s or methods
'---
'--------------------------------------------------------------------------------------
Option Strict On
Option Explicit On
Public Interface IiQueuObject
Sub StartProcessing()
Property Parameters() As String
Property ProcessId() As String
Event eFinished(ByVal ProcessId As String, ByVal msg As String)
Event eError(ByVal ProcessId As String, ByVal msg As String)
Event eProcessCancelled(ByVal ProcessId As String, ByVal msg As String)
Property CancellProcess() As Boolean
End Interface
now i can just use anny object like this
'het object welke we gaan starten
'OTask wordt gedefinieerd as ista.IiQueuObject
'we kunnen dus ieder mogelijk object opstarten indien het deze
interface
heeft geimplementeerd
Dim oTask As ista.IiQueuObject =
clsGetObjectFromFile.LoadMeByName(Dr.Item("AssemblyNaam").ToString,
Dr.Item("AssemblyType").ToString)
If Not IsNothing(oTask) Then
otask.StartProcessing()
end if
HTH
Michel Posseth [MCP]
"Noone" <
[email protected]> schreef in bericht
Sorry, not invoke, I meant Interop. I think... Heeelp! : )
Hello all,
Ok, I want to create a program that will load plugins (dll's) from a
plugin folder. I can create the forms and put them into a dll but I
cannot actually add them dynamically at run time. I have tried to
use
the LoadLibrary and GetProc functions, which sort of worked. I got
the pointer to the function but I cannot actually RUN the function
like I can in C++. I have heard some things about Invoking(?) I
believe but I cannot find enough about it. Any comments or
suggestions would be EXTREMELY helpful.
Thanks,
Josh