In C #, I try PInvoke the "simple" function that I have in C ++. The problem is that I do not know the name or location of the library at compile time. In C ++, this is easy:
typedef HRESULT (*SomeFuncSig)(int, IUnknown *, IUnknown **); const char *lib = "someLib.dll"; // Calculated at runtime HMODULE mod = LoadLibrary(lib); SomeFuncSig func = (SomeFuncSig)GetProcAddress("MyMethod"); IUnknown *in = GetSomeParam(); IUnknown *out = NULL; HRESULT hr = func(12345, in, &out); // Leave module loaded to continue using foo.
In life, I can't figure out how to do this in C #. I would not have a problem if I knew the name dll, it would look something like this:
[DllImport("someLib.dll")] uint MyMethod(int i, [In, MarshalAs(UnmanagedType.Interface)] IUnknown input, [Out, MarshalAs(UnmanagedType.Interface)] out IUnknown output);
How can I do this without knowing the dll with which I boot at compile time?
source share