I have a lot of libraries written in C++. I want to call these libraries from C#, however, I have met many problems. I want to know if there is a book or guideline to tell me how to do that.
-
http://geeklit.blogspot.com/2006/08/calling-c-lib-from-c.html – Ray Lu Feb 22 '09 at 12:00
-
See http://stackoverflow.com/questions/569603/using-c-class-dll-in-c-application – Richard Feb 22 '09 at 12:37
4 Answers
If you google "c++ c# interop", you'll find tons of information on this topic.
A couple of links:
http://msdn.microsoft.com/en-us/magazine/cc301501.aspx
http://msdn.microsoft.com/en-us/library/ms235281(VS.80).aspx

- 25,414
- 13
- 85
- 121

- 27,121
- 13
- 66
- 85
I recently had to wrap some c++ code in .NET. Although the c++ code was packaged as a dll, the interface was too unfriendly for P/Invoke, so I decided to write it in managed c++, or C++/CLI as it is apparently known now.
I found this tutorial very useful on the syntax. It's not so easy on the eye, but the content seemed pretty good.

- 724
- 5
- 10
I'm a big fan of the book C++/CLI in Action which has a couple of useful sample chapters online, at that address.
This intro on CodeProject is a good starting point.
The author of C++/CLI in Action has a number of articles on CodeProject, scroll down to the C++/CLI section on his index.
The Wikipedia article on P/Invoke has a number of reasons why you might not want to use that approach, with which I agree:
- loss of typing support by the compiler
- possible data type or alignment issues as you have to map types by hand
- need to pin garbage-collected objects
The best starting point on MSDN is the summary article.

- 17,578
- 6
- 88
- 115