3

Possible Duplicate:
Using C++ Class DLL in C# Application

I try to failed to add reference to add c++ dll in c#

if you have any other method to add or use c++ dll in c#. how can we use?

Where do i mistake to add dll in my c# project?

Thanks in advance

Community
  • 1
  • 1
Ashwin
  • 131
  • 2
  • 4
  • 15

2 Answers2

4

For using native C++ libraries in C#, you mostly will have to create a C++/CLI wrapper for that. P/Invoke is ok as long as the API of your DLL contains just simple C-like functions, but when the API contains real C++ classes, C++/CLI ist much better for that task.

Doc Brown
  • 19,739
  • 7
  • 52
  • 88
2

You don't add a reference to a C++ library, that's for .NET assemblies only. What you need is platform interop using P/Invoke. MSDN has a bunch of information here:-

http://msdn.microsoft.com/en-us/library/aa288468(VS.71).aspx

It basically means you have to write method stubs that call your exported functions in the external library.

There is also the C++/CLI way which can be better depending on your C++ project setup, but personally I prefer the traditional Windows API function export way.

Lloyd
  • 29,197
  • 4
  • 84
  • 98
  • One more great resource is the http://en.wikipedia.org/wiki/Platform_Invocation_Services and http://pinvoke.net/ – Vamsi Oct 17 '11 at 12:38