-5

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

Community
  • 1
  • 1
perumal316
  • 1,159
  • 6
  • 17
  • 36

2 Answers2

6

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 DllImportAttribute and the extern keyword.

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

Robert Rouhani
  • 14,512
  • 6
  • 44
  • 59
2
  1. First of all Right-Click in your solution explorer and select Add Refrence Tab.
  2. Brose the dll you want add.
  3. Add Dll to your code file using following fomat:

    using in C# Or

    Import in VB

If above solution doesn,t work then refer to this link:

add C++ dll in .net

Community
  • 1
  • 1