C# 如何调用动态外部dll
在C#中,我想调用外部DLL中签名为C# 如何调用动态外部dll,c#,dll,C#,Dll,在C#中,我想调用外部DLL中签名为bool IsValid(string)的方法, 但是dll的名称是作为字符串来自输入的 我怎样才能: 调用外部方法 是否执行IsValid方法 我能想到的唯一方法是使用Win32库和LoadLibrary API函数。 这里有一个链接可以帮助您入门: 我能想到的唯一方法是使用Win32库和LoadLibrary API函数。 这里有一个链接可以帮助您入门: 外部DLL是托管的还是非托管的 如果它是托管DLL,将允许您加载它并从其中的类调用函数 对于非托管DL
bool IsValid(string)
的方法,
但是dll的名称是作为字符串来自输入的
我怎样才能:
IsValid
方法我能想到的唯一方法是使用Win32库和LoadLibrary API函数。 这里有一个链接可以帮助您入门:
我能想到的唯一方法是使用Win32库和LoadLibrary API函数。 这里有一个链接可以帮助您入门:
外部DLL是托管的还是非托管的 如果它是托管DLL,将允许您加载它并从其中的类调用函数
对于非托管DLL,@lcfseth的链接是正确的选择。外部DLL是托管的还是非托管的 如果它是托管DLL,将允许您加载它并从其中的类调用函数
对于非托管DLL,@lcfseth的链接是正确的选择。对于第一个问题,我找到了以下答案:
string path = ApplicationMapPath+ objDLLName + ".dll";
System.Reflection.Assembly a = System.Reflection.Assembly.LoadFile(path);
Type t = a.GetType("<namespace>.<Class>");
object instance = a.CreateInstance("<namespace>.<Class>");
MethodInfo m = t.GetMethod("<FuncName>");// Call the method
object res = m.Invoke(instance, new object[] { txtBox.Text }); // Get the result here
string path=applicationAppath+objDLLName+“.dll”;
System.Reflection.Assembly a=System.Reflection.Assembly.LoadFile(路径);
类型t=a.GetType(“.”);
对象实例=a.CreateInstance(“.”);
MethodInfo m=t.GetMethod(“”;//调用该方法
object res=m.Invoke(实例,新对象[]{txtBox.Text});//在这里得到结果
对于第一个问题,我找到了以下答案:
string path = ApplicationMapPath+ objDLLName + ".dll";
System.Reflection.Assembly a = System.Reflection.Assembly.LoadFile(path);
Type t = a.GetType("<namespace>.<Class>");
object instance = a.CreateInstance("<namespace>.<Class>");
MethodInfo m = t.GetMethod("<FuncName>");// Call the method
object res = m.Invoke(instance, new object[] { txtBox.Text }); // Get the result here
string path=applicationAppath+objDLLName+“.dll”;
System.Reflection.Assembly a=System.Reflection.Assembly.LoadFile(路径);
类型t=a.GetType(“.”);
对象实例=a.CreateInstance(“.”);
MethodInfo m=t.GetMethod(“”;//调用该方法
object res=m.Invoke(实例,新对象[]{txtBox.Text});//在这里得到结果