在 C++ 中我们能够通过 LoadLibrary,  GetProcAddress 来动态调用 dll 的导出函数.
在 C# 中也能够用这样的方式吗?
在 DotNet 2.0 里面这样是可以的, 这完全得益于 2.0新增的一个函数
此方法在 .NET Framework 2.0 版中是新增的。

将非托管函数指针转换为委托。
实例代码如下:

在 C# 中动态调用 native dll 的导出函数public delegate int MsgBox(int hwnd,string msg,string cpp,int ok);
在 C# 中动态调用 native dll 的导出函数
在 C# 中动态调用 native dll 的导出函数        [DllImport(
"Kernel32")]
在 C# 中动态调用 native dll 的导出函数        
public static extern int GetProcAddress(int handle, String funcname);
在 C# 中动态调用 native dll 的导出函数        [DllImport(
"Kernel32")]
在 C# 中动态调用 native dll 的导出函数        
public static extern int LoadLibrary(String funcname);
在 C# 中动态调用 native dll 的导出函数        [DllImport(
"Kernel32")]
在 C# 中动态调用 native dll 的导出函数        
public static extern int FreeLibrary(int handle);
在 C# 中动态调用 native dll 的导出函数
在 C# 中动态调用 native dll 的导出函数        
private static Delegate GetAddress(int dllModule, string functionname, Type t)
        }

在 C# 中动态调用 native dll 的导出函数

相关文章:

  • 2022-03-09
  • 2022-12-23
  • 2021-12-23
  • 2021-12-09
  • 2021-11-21
  • 2021-11-21
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-21
  • 2022-12-23
相关资源
相似解决方案