views:

883

answers:

4

I'm a newbie for C#, i have a lot of libraries are wrote with C++, when I want to call these libraries in C#, i met many problems. I want to know if there is a book or guideline to tell me how to do that.

+2  A: 

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.

Nick Gunn
+1  A: 

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

17 of 26
A: 

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.

Andy Dent