25

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.

David Ranieri
  • 37,819
  • 6
  • 48
  • 88
Yigang Wu
  • 3,516
  • 5
  • 37
  • 54

4 Answers4

5

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

Kyle Trauberman
  • 24,976
  • 13
  • 86
  • 117
17 of 26
  • 26,652
  • 13
  • 64
  • 85
4

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
  • 724
  • 5
  • 10
3

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
  • 16,995
  • 6
  • 83
  • 111