Foxtable(狐表)用户栏目专家坐堂 → 咨询一个函数写法


  共有7159人关注过本帖树形打印复制链接

主题:咨询一个函数写法

帅哥哟,离线,有人找我吗?
jianjingmaoyi
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:三尾狐 帖子:760 积分:4714 威望:0 精华:0 注册:2011/12/17 18:37:00
咨询一个函数写法  发帖心情 Post By:2014/2/27 19:40:00 [显示全部帖子]

我在内部函数这样写了一段代码:

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

 函数应该一样,但是执行后提示找不到实例了

 回到顶部
帅哥哟,离线,有人找我吗?
jianjingmaoyi
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:三尾狐 帖子:760 积分:4714 威望:0 精华:0 注册:2011/12/17 18:37:00
  发帖心情 Post By:2014/2/27 20:24:00 [显示全部帖子]

我修改了函数是可以执行,但是现在是写在dll的不能执行

 回到顶部
帅哥哟,离线,有人找我吗?
jianjingmaoyi
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:三尾狐 帖子:760 积分:4714 威望:0 精华:0 注册:2011/12/17 18:37:00
  发帖心情 Post By:2014/2/27 20:33:00 [显示全部帖子]

我把函数改成这样是可以执行了:

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" & "." & Args(0)).GetMethod(Args(1))
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","AfterOpenProject","AfterOpenProject",New Object() { "生产管理系统" })  

 但是改成另外一个就又不行了.方法一样


 回到顶部
帅哥哟,离线,有人找我吗?
jianjingmaoyi
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:三尾狐 帖子:760 积分:4714 威望:0 精华:0 注册:2011/12/17 18:37:00
  发帖心情 Post By:2014/2/27 21:53:00 [显示全部帖子]

不应该呀 问题是已经成功,只是另外一个不成功了.

 回到顶部