我在内部函数这样写了一段代码:
Dim DllName As String ="测试dll.dll"
Dim Name As String ="测试dll"
Dim Typename As String = "AfterOpenProject"
Dim methodname As String = "AfterOpenProject"
Dim ParamArray0() As Object = Nothing
Dim assembly0 As system.reflection.assembly = system.reflection.assembly.loadfrom(ProjectPath & DllName)
Dim method As System.Reflection.MethodInfo = assembly0.Gettype(Name & "." & Typename).GetMethod(methodname)
Dim obj2 As object
Try
obj2 = method.Invoke(Nothing, New Object() { ParamArray0 })
Catch exception1 As Exception
Dim exception As Exception = exception1
MessageBox.Show(("调用DLL执行出错,错误信息:" & exception.InnerException.ToString), "警告", MessageBoxButtons.OK, MessageBoxIcon.Hand)
goto Label_Error
End Try
Return obj2
Label_Error:
Return Nothing
执行函数为:
Functions.Execute("ABC","测试dll.dll","AfterOpenProject","AfterOpenProject",New Object() { "生产管理系统" })
执行没有任何问题
但是我这样改后:
Dim Typename As String = Args(0)
Dim methodname As String = Args(1)
Dim ParamArray0() As Object = Nothing
Dim assembly0 As system.reflection.assembly = system.reflection.assembly.loadfrom(ProjectPath & "测试dll.dll")
Dim method As System.Reflection.MethodInfo = assembly0.Gettype("测试dll" & "." & Typename).GetMethod(methodname)
Dim obj2 As object
Try
obj2 = method.Invoke(Nothing, New Object() { ParamArray0 })
Catch exception1 As Exception
Dim exception As Exception = exception1
MessageBox.Show(("调用DLL执行出错,错误信息:" & exception.InnerException.ToString), "警告", MessageBoxButtons.OK, MessageBoxIcon.Hand)
goto Label_Error
End Try
Return obj2
Label_Error:
Return Nothing
函数应该一样,但是执行后提示找不到实例了