Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何调用动态外部dll_C#_Dll - Fatal编程技术网

C# 如何调用动态外部dll

C# 如何调用动态外部dll,c#,dll,C#,Dll,在C#中,我想调用外部DLL中签名为bool IsValid(string)的方法, 但是dll的名称是作为字符串来自输入的 我怎样才能: 调用外部方法 是否执行IsValid方法 我能想到的唯一方法是使用Win32库和LoadLibrary API函数。 这里有一个链接可以帮助您入门: 我能想到的唯一方法是使用Win32库和LoadLibrary API函数。 这里有一个链接可以帮助您入门: 外部DLL是托管的还是非托管的 如果它是托管DLL,将允许您加载它并从其中的类调用函数 对于非托管DL

在C#中,我想调用外部DLL中签名为
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});//在这里得到结果