DLL Import Programatically?

  • Thread starter Thread starter wackyphill
  • Start date Start date
W

wackyphill

I know how to use [DLLImport] when I know the path the DLL I'll be
importing. But I have the following scenario:

I have a series of DLL plugins that all have the exact same function
signatures just different implementations of them.

I'd like to programatically search a directory for them and import them
some how. Even though I know there signatures at compile time I won't
know the DLL file names till run time.

Any ideas how to do this?

Thanks very much.
 
You can do this in .NET 2.0. What you would do is create a delegate
with the appropriate signature. Once you have that, you would call
LoadLibrary and GetProcAddress (through the P/Invoke layer) to get the
address of the function.

Finally, you would call the static GetDelegateForFunctionPointer method
on the Marshal class to get a delegate that represents the function in the
unmanaged dll you loaded.

Hope this helps.
 
Back
Top