【发布时间】:2020-02-17 08:28:43
【问题描述】:
在 C# 中,我使用外部 dll,使用 loadLibrary,如下所示:
public class Utilities
[DllImport("kernel32", CharSet= CharSet.Auto, SetLastError=true)]
private static extern IntPtr LoadLibrary(string librayName);
[DllImport("kernel32", CharSet= CharSet.Auto, SetLastError=true)]
private static extern IntPtr GetProcAddress(intPtr hwnd, string procedureName);
public static LoadAssembliesAndMethods() {
string mainPath = AppDomain.CurrentDomain.BaseDirectory;
string path = Path.Combine(mainPath, "MyAssembly.dll");
IntPtr ptr = LoadLibrary(path);
// What to do next in order to get all the list of functions/methods/class in the library and use them?
}
这个dll没有Assembly的签名(它是第3方),所以我做不到
Assebly.LoadFile(path);
我需要获取 dll 的所有函数/方法/类,并使用其中的一些,使用 C#。
我该怎么做。
【问题讨论】:
-
你要加载什么样的dll库?
-
LoadLibrarythenGetProcAddress(hLibrary, functionName)返回所需函数的地址 (IntPtr) -
我不知道希望函数是在静态类中还是只是一个函数。我没有第 3 方库的来源。我需要检查类列表和方法列表,然后使用它们。
标签: c# dynamic-library