tags:

views:

817

answers:

2

Hi guys,

I have a C# class library that contains methods that need to be used with an external application. Unfortunately this external application only supports external APIs in C/C++.

Suppose I have a takeIntReturnDoubleArray method in this C# library that takes an integer and returns an array of doubles. All I need to do is have a C++ method that takes an integer, calls the C# library and returns an array of doubles to the calling application.

So in essence the C++ library is just acting as an intermediary between the C# wrapper and the external application.

Is there an easy way to do this? Do I have to do anything special on the C# side to allow it to be imported into C++ easily? I have seen some talk of using the #import statement but I really have no idea what I am doing when it comes to C++.

What is the approach I should be taking here?

+1  A: 

COM Interop is one way to approach this problem. You'll have to have a COM layer for the C# library function(s) you want to expose to the C++ application. This (http://msdn.microsoft.com/en-us/library/aa302324.aspx#usingframeworktools_topic10) might be of interest.

dirkgently
+4  A: 

You have two main options here:

  1. C++\CLI - this allows you to have both managed and unmanaged code in the same source file. The managed portion can then call the C# code.
  2. COM Interop - expose your .NET type as a COM interface and matching coclass which you can easily use from unmanaged C++.
On Freund
I would prefer to go with the simplest solution. I believe I can keep my C++ as managed code.
Alex
I ended up going with COM. It wasnt pleasant but it got the job done.
Alex