RSS订阅优然探索
你的位置:首页 » 技术文章 » 正文

asp.net动态调用DLL文件

选择字号: 超大 标准 发布时间:2010-1-19 9:21:55 | 作者:admin | 0个评论 | 人浏览

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Reflection;
using System.Runtime.Remoting;
namespace MyDLLDyUserd
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            object[] args = new object[0];
            MessageBox.Show(" 这是您第 " + Invoke("MyTestClass.dll", "MyTestClass", "Class1", "getDate", args));
       
        }

 

        private object Invoke(string lpFileName, string Namespace, string ClassName, string lpProcName, object[] ObjArray_Parameter)
        {
            try
            { // 载入程序集
                Assembly MyAssembly = Assembly.LoadFrom(lpFileName);
                Type[] type = MyAssembly.GetTypes();
                foreach (Type t in type)
                {// 查找要调用的命名空间及类
                    if (t.Namespace == Namespace && t.Name == ClassName)
                    {// 查找要调用的方法并进行调用
                        MethodInfo m = t.GetMethod(lpProcName);
                        if (m != null)
                        {
                            object o = Activator.CreateInstance(t);
                            return m.Invoke(o, ObjArray_Parameter);
                        }
                        else MessageBox.Show(" 装载出错 !");
                    }
                }
            }//try
            catch (System.NullReferenceException e)
            {
                MessageBox.Show(e.Message);
            }//catch
            return (object)0;
        }// Invoke

      
    }
}
 

标签:

猜你喜欢

发表评论

必填

选填

选填

必填,不填不让过哦,嘻嘻。

记住我,下次回复时不用重新输入个人信息

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。