Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Get the assembly
Dim MyAssembly As Reflection.Assembly
MyAssembly = Reflection.Assembly.LoadFile("C:\Projekt\VS.Net\VBTest\ClassLibrary1\bin\ClassLibrary1.dll")
' Get the module called "ClassLibrary1.dll"
Dim MyModule As Reflection.Module
MyModule = MyAssembly.GetModule("ClassLibrary1.dll")
' Get the type that holds the method to invoke
Dim MyType As System.Type
MyType = MyModule.GetType("ClassLibrary1.Class1")
' Get the method to invoke (called "Abs")
Dim MyMethod As Reflection.MethodInfo
MyMethod = MyType.GetMethod("Abs")
' Create an instance of the type
Dim MyInstance As Object
MyInstance = Activator.CreateInstance(MyType)
' Invoke the method, pass an object array with
' parameters and show the result
MyMethod.Invoke(MyInstance, New Object() {-12})
' Lets try to hook up to an event called "MyEvent"
' Get the event
Dim MyEvent As Reflection.EventInfo
MyEvent = MyType.GetEvent("MyEvent")
' Create a delegate to our eventhandler procedure
Dim MyDelegate As System.Delegate
MyDelegate = System.Delegate.CreateDelegate(MyEvent.EventHandlerType, Me, "EventHandlerSub")
' Now add the eventhandler to the object
MyEvent.AddEventHandler(MyInstance, MyDelegate)
End Sub
' The eventhandler procedure
Private Sub EventHandlerSub(ByVal sender As Object, ByVal e As System.EventArgs)
MsgBox("Event fired!")
End Sub