日期:2014-05-17  浏览次数:20793 次

C#动态调用dll
有个 DLL文件  路径是:D:\123123\123.dll  ,要调用这个DLL文件里面的  1234方法,
1234 方法   :
参数1:  string  a   
参数2: int  b 
 返回值: bool   c 
求代码!这里感谢了!
------解决方案--------------------
using System.Runtime.InteropServices;

public sealed class Dll123{
        [DllImport("D:\123123\123.dll", EntryPoint = "1234")]
        public static extern bool 1234(string a, int b);
}

------解决方案--------------------
Type type= System.Reflection.Assembly.LoadFile(@"D:\123123\123.dll").GetType("Lib.MyClass");
object obj = type.GetMethod("1234").Invoke(Activator.CreateInstance(type), new object[] { "abc", 123 });
bool result = Convert.ToBoolean(obj);


未作任何异常处理,自行斟酌~