3

Possible Duplicate:
Writing a DLL in C/C++ for .Net interoperability

I am writing a school project in C++, where I would like to have a GUI written in C# with WPF.

This leads me to my question:

What are the different ways of combining unmanaged C++ and C# and what are the advantages of each?

Preferably I would like to have standard C++ code in a separate project, which I will then wrap (if needed), so I can build the C++ with a shell interface on Linux.

I am using VS2010 Ultimate.

Note: Writing the code in C# is not relevant. There are some details in the algorithm which make STL more suited than the equivalent classes on .NET. I would also like unmanaged code, so I can test the performance without GC pauses.

Community
  • 1
  • 1
Jørgen Fogh
  • 7,516
  • 2
  • 36
  • 46
  • Possible duplicate of [Writing a DLL in C/C++ for .Net interoperability](http://stackoverflow.com/questions/3726829) – Heinzi Sep 21 '10 at 12:16
  • The answer I gave in the linked question doesn't really emphasize portability or use from a native C++ application. You can make that easier with a macro, the usual way of doing it is: In your header file, all the function declarations look like `JORGENAPI(returntype) PublicFunc(params);` In your project, the definition is `#define JORGENAPI(returntype) extern "C" returntype __stdcall __declspec(dllexport)` In consumer projects `#define JORGENAPI(returntype) extern "C" returntype __stdcall __declspec(dllimport)` and then you can define the macro differently for linux. – Ben Voigt Sep 21 '10 at 12:30
  • I don't think the linked question even begins to cover the same ground as this question - it should definitely be re-opened. – Justin Sep 21 '10 at 12:34
  • @Ben, Kragen: Point taken, voting to reopen. – Heinzi Sep 21 '10 at 16:04
  • @Kragen: Can you give an example of what is covered by this question and not the other one? It's possible that some of the answers to the other one could use some more elaboration or comments, but I do think that the other question is broad enough to cover this. – Ben Voigt Sep 21 '10 at 17:34
  • I've merged my comment here into my other answer to make it better cover the topic of building C++ libraries that can be called from C# (as well as other languages). – Ben Voigt Sep 21 '10 at 17:42
  • Some of the answers for the other questions are definitely relevant, but I am not trying to create a DLL, nor am I trying not to. I just want to make my C++ work with C# as seamlessly as possible, but with a clean interface between GUI and backend. – Jørgen Fogh Sep 22 '10 at 20:49

0 Answers0