I currently have a DLL (done using C++). Now I want to load this DLL in my C# application to access some methods.
I tried using the example shown here but it couldn’t work:
Can I load a .NET assembly at runtime and instantiate a type knowing only the name?
Any idea what’s wrong? Is there any way to load a DLL and access the methods?
Thanks In Advance,
Perumal
The difference between the question you linked to and your problem is that the other question was talking about a .NET assembly in .dll form, but your problem is about a native .dll file.
If you’ve got a lot of classes on the C++ side, it’s best to use C++/CLI to wrap the native methods and classes. If your API only exposes methods, then you can get away with writing the bindings using
DllImportAttributeand theexternkeyword.This MSDN article should be a nice starting point for writing the bindings for your C++ dll: http://msdn.microsoft.com/en-us/library/2x8kf7zx(v=vs.80).aspx