user9969215
user9969215

Reputation:

Load a C++ DLL at runtime

I am using DllImport to load a C++ dll. A user uses my code by passing a string to the MyClass constructor

I want to load the specified DLL path that was provided in the MyClass constructor and then I want methods to be able to access the loaded DLL.

How do I code it so that all the user has to type is new MyClass().DoSomething()?

Upvotes: 0

Views: 1871

Answers (1)

V0ldek
V0ldek

Reputation: 10553

You need the LoadLibrary and GetProcAddress methods from Win32 and then the Marshal.GetDelegateForFunctionPointer method. For a detailed description see this msdn blog:

https://blogs.msdn.microsoft.com/jonathanswift/2006/10/03/dynamically-calling-an-unmanaged-dll-from-net-c/

Upvotes: 1

Related Questions