I have a C++ DLL which I'm importing into a C# project using a DllImport
ed LoadLibrary
.
class Program
{
[DllImport("kernel32.dll", SetLastError = true)]
public static extern IntPtr LoadLibrary(string dllToLoad);
static void Main(string[] args)
{
IntPtr library = LoadLibrary(@"MyDll.dll");
if (library == IntPtr.Zero)
{
var err = Marshal.GetLastWin32Error();
throw new Exception($"Library load error, code {err}");
}
}
}
I now want to enumerate over the functions exported from this DLL. I've seen this question, but it applies to C++, and I'm not sure how I could do the same in C#.
Parsing the output of dumpbin /exports
would probably work, but I'd like to know if there's a more concrete way of doing it first.
How can I obtain a list of all of the functions in the C++ DLL from C#?