is that possible? and if yes, is it possible to know their parameters?
Printable View
is that possible? and if yes, is it possible to know their parameters?
yes..and yes
this should get you stated
you can compile that to an exe and pass in a dll filename and path as a command line parameter to see it workCode:
Imports System
Imports System.Reflection
Public Module DLLReport
Public Sub Main(ByVal args() As String)
LoadDLL(args(0))
End Sub
Public Sub LoadDLL(ByVal filename As String)
Dim asm As [Assembly] ' Assembly is reserved vb word so use the brackets to override
Dim myClasses() As Type
Dim myMethods() As MethodInfo
Dim myEvents() As EventInfo
Dim myProperties() As PropertyInfo
Dim myParameters() As ParameterInfo
Dim myTypes As Type
Dim myMethodInfo As MethodInfo
Dim myEventInfo As EventInfo
Dim myPropertyInfo As PropertyInfo
Dim myParameterInfo As ParameterInfo
asm = [Assembly].LoadFrom(filename)
If Not(asm Is Nothing) Then
myClasses = asm.GetTypes()
End If
For Each myTypes In myClasses
' Output Classname
Console.Writeline(myTypes.ToString())
' Lets get all methods(sub and function) from this class
myMethods = myTypes.GetMethods()
For Each myMethodInfo In myMethods
Console.Writeline("---Method---" & myMethodInfo.Name & " Returns " & myMethodInfo.ReturnType.ToString())
' Now lets get the Parameters for this method
myParameters = myMethodInfo.GetParameters()
For Each myParameterInfo In myParameters
Console.WriteLine(" ---Parameter---" & myParameterInfo.Name & " As " & myParameterInfo.ParameterType.ToString())
Next myParameterInfo
Next myMethodInfo
' Lets get all events
myEvents = myTypes.GetEvents()
For Each myEventInfo In myEvents
Console.Writeline("---Event---" & myEventInfo.Name)
Next myEventInfo
' Lets get all properties
myProperties = myTypes.GetProperties()
For Each myPropertyInfo In myProperties
Console.Writeline("---Properties---" & myPropertyInfo.Name & " As " & myPropertyInfo.PropertyType.ToString())
Next myPropertyInfo
Next myTypes
End Sub
End Module
hmmm i antecipated and got a example of a friend...and then i tryed to make that by myself but i am getting an error...i have the following code:
Plugin Code
VB Code:
Imports System Imports System.ComponentModel Public Class MathSystem Public Function Somar(ByVal numero1 As Integer, ByVal numero2 As Integer) As Integer Return numero1 + numero2 End Function Public Function Subtrair(ByVal numero1 As Integer, ByVal numero2 As Integer) As Integer Return numero1 - numero2 End Function Public Function Multiplicar(ByVal numero1 As Integer, ByVal numero2 As Integer) As Integer Return numero1 * numero2 End Function Public Function Dividir(ByVal numero1 As Integer, ByVal numero2 As Integer) As Integer Return numero1 \ numero2 End Function End Class
Program code:
VB Code:
Dim MeuAssembly As [Assembly] Dim obj As Object Dim Estructura As Type Dim MeuMetodo As MethodInfo Dim args(1) As Object Dim ValorRetorno As Object Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click MeuAssembly = [Assembly].Load("plugintest123") Estructura = MeuAssembly.GetType("plugintest123.MathSystem") MeuMetodo = Estructura.GetMethod("Somar") obj = Activator.CreateInstance(Estructura) args(0) = TextBox1.Text 'this is 10 args(1) = TextBox2.Text 'this is 10 [b]ValorRetorno = MeuMetodo.Invoke(obj, BindingFlags.Public Or BindingFlags.InvokeMethod, Nothing, args, Nothing)[/b] MsgBox(ValorRetorno) End Sub
i am getting error in the bold line
ah the error says:
An unhandled exception of type 'System.ArgumentException' occurred in mscorlib.dll
Additional information: Cannot widen from target type to primitive type.
what error do you get
?
try declaring ValorRetorno As integer
then
ValorRetorno = CType(MeuMetodo.Invoke(obj, BindingFlags.Public Or BindingFlags.InvokeMethod, Nothing, args, Nothing), Integer)
hmm ill try
same error..any ideas..? lol
here is the code if u want to see it