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


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

主题:咨询一个函数写法

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


加好友 发短信
等级:版主 帖子:1693 积分:12117 威望:0 精华:7 注册:2013/7/11 10:52:00
  发帖心情 Post By:2014/2/27 19:58:00 [显示全部帖子]

你的参数量和传入数为什么是不一样的啊?

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


加好友 发短信
等级:版主 帖子:1693 积分:12117 威望:0 精华:7 注册:2013/7/11 10:52:00
  发帖心情 Post By:2014/2/27 20:05:00 [显示全部帖子]

Dim obj As object =  Functions.Execute("ABC","AfterOpenProject","AfterOpenProject")  

 

还得判断空

 

猜的

[此贴子已经被作者于2014-2-27 20:06:17编辑过]

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


加好友 发短信
等级:版主 帖子:1693 积分:12117 威望:0 精华:7 注册:2013/7/11 10:52:00
  发帖心情 Post By:2014/2/28 11:33:00 [显示全部帖子]

试一下这样,参数自己改

 

Dim filePath As String = Args(0)    '文件路径
Dim className As String = Args(1)    '模块名
Dim methodName As String = Args(2)    '函数名
Dim paramter() As Object  = Args(3)   '参数集

If FileSys.FileExists(filePath ) = False Then   
    MessageBox.Show("文件不存在", "提示", MessageBoxButtons.OK, MessageBoxIcon.Question)
    Return Nothing
End If

Dim fileName As String = system.io.Path.GetFileNameWithoutExtension(filePath)  '取文件名
Try
        Dim asm As System.Reflection.Assembly = System.Reflection.Assembly.LoadFile(filePath)
        Dim classtemp As Type = asm.Gettype(fileName & "." & className,True)
        Dim obj As Object = asm.CreateInstance(classtemp.FullName)
        Dim me_Info As System.Reflection.MethodInfo = classtemp.GetMethod(methodName)        
        Return me_Info.Invoke(obj, paramter)
Catch exception1 As Exception
    Dim exception As Exception = exception1
   
    MessageBox.Show(("调用DLL执行出错,错误信息:" & exception.InnerException.ToString), "警告", MessageBoxButtons.OK, MessageBoxIcon.Hand)
    Return Nothing
End Try

 

 

 

调用

 

Dim str As String = "E:\shishi\测试.dll"
        Dim paramter(1) As Object
        paramter(0) = 1
        paramter(1) = 5
 Dim ob As object = Functions.Execute("动态DLL",str,"Class1","aa",paramter)
If ob IsNot Nothing Then
Output.show(ob)
End If


 回到顶部