我使用Assembly动态加载dll,方法如下(从网上查的方法):
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  string   DllPath   =   Application.StartupPath   +   @"\someDLL.dll";   
  System.Reflection.Assembly   assmble   =   System.Reflection.Assembly.LoadFile(DllPath);   
    
  Type   tmpType   =   assmble.GetType("someDLL.ClassA");   
  System.Reflection.MethodInfo   tmpM   =   tmpType.GetMethod("Add");   
  object   tmpobj   =   assmble.CreateInstance("someDLL.ClassA");   
  int   i   =   (int)tmpM.Invoke(tmpobj,   new   object[]{2,3});   
    
  ----------ClassA的定义--------------------   
  using   System;  namespace   someDLL   
  {   
  ///   <summary>   
  ///   ClassA   的摘要说明。   
  ///   </summary>   
  public   class   ClassA   
  {   
  public   ClassA()   
  {   
  //   
  //   TODO:   在此处添加构造函数逻辑   
  //   
  }
  public   int   Add(int   a,   int   b)   
  {   
  return   a+b;   
  }
  }
  }
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\现在的问题是:如果类库中的函数有ref型返回值参数,应该怎么做?
多谢各位大侠了!!

解决方案 »

  1.   

    参考:        static void Main(string[] args)
            {
                Type t = typeof(A);
                MethodInfo mi = t.GetMethod("AMethod", new Type[] { Type.GetType("System.Int32&") });
                if (mi != null)
                {
                    object o = Activator.CreateInstance(t);
                    int i = 0;
                    mi.Invoke(o, new object[] { i });
                }
            }        class A
            {
                public A()
                {
                }            public void AMethod(ref int i)
                {
                    i = 10;
                    Console.WriteLine(i);
                }
            }
      

  2.   


    把你带ref参数的方法贴出来看看
      

  3.   

    object[] vars = new object[] { 1 };
    mi.Invoke(o, vars);
    int i = (int)vars[0];
      

  4.   


    我是这样用的:
    (1).在一个类库函数中定义函数:  using  System;   namespace  someDLL  
      {  
      ///  <summary>  
      ///  ClassA  的摘要说明。  
      ///  </summary>  
      public  class  ClassA  
      {  
      public  ClassA()  
      {  
      //  
      //  TODO:  在此处添加构造函数逻辑  
      //  
      } 
      public  int  Add(ref int  xx)  
      {  
    xx=12;
      return  9;  
      } 
      } 
      } (2).然后将dll放在一个界面程序的根目录中,界面程序不引用这个dll文件,而是动态添加: string  DllPath  =  Application.StartupPath  +  @"\someDLL.dll";  
      System.Reflection.Assembly  assmble  =  System.Reflection.Assembly.LoadFile(DllPath);  
        
      Type  tmpType  =  assmble.GetType("someDLL.ClassA");  
      object  tmpobj  =  assmble.CreateInstance("someDLL.ClassA");  
      System.Reflection.MethodInfo  tmpM  =  tmpType.GetMethod("Add",new Type[] {Type.GetType("System.Int32&") );    //在这里修改了
     
    int bb=0;  int  i  =  (int)tmpM.Invoke(tmpobj,  new  object[]{bb}); 但是执行完后,变量bb还是0.
      

  5.   

    再问个问题:如果函数参数的ref型的数组应该怎么传啊,多谢各位大侠再帮帮忙了。或者指点一下小弟应该在MSDN中查什么能查到,多谢了。
    P.S.一会儿就给二位大哥放分,多谢帮忙!!
      

  6.   


    Type.GetType("System.Int32[]&")