zoukankan      html  css  js  c++  java
  • c# 动态加载dll文件

     /// <summary>
            /// 动态加载DLL
            /// </summary>
            /// <param name="lpFileName">DLL路径</param>
            /// <param name="Namespace">命名空间</param>
            /// <param name="ClassName">类名</param>
            /// <param name="lpProcName">公共函数名</param>
            /// <param name="ObjArray_Parameter"></param>
            /// <returns></returns>
            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(" 装载出错 !");
                        }
                    }
                }
                catch (System.NullReferenceException e)
                {
                    MessageBox.Show(e.Message);
                }
                return (object)0;
            }
  • 相关阅读:
    vi
    head
    uniq
    sort
    所谓静态绑定
    债务
    不确
    tar
    VMWare虚拟系统上网设置 及 三种模式详解
    awk
  • 原文地址:https://www.cnblogs.com/z45281625/p/10623716.html
Copyright © 2011-2022 走看看