tags:

views:

182

answers:

3

I am currently programming in C++ and C#. Using native C++ for the numerical computing part.

Originally I intended to use C++/CLI to make a wrapper to the native C++ classes, but I found it would result in a 2 to 4 times slowdown.

So I decided to compile my native C++ to a DLL and call in .NET/C# via P/Invoke. I will do data preprocessing in C# and number crunching in the native DLL.

The problem is that when I deliver my work for others to use, I'd like it to be a single DLL.

Is this possible? BTW, I have all source code to the native C++.

A: 

You can mix languages in the same assembly in .NET but not naturally. I would avoid this unless absolutely necessary.

See:

http://www.hanselman.com/blog/MixingLanguagesInASingleAssemblyInVisualStudioSeamlesslyWithILMergeAndMSBuild.aspx

I keep assemblies from different languages separate.

Paul
ILMerge only works with managed code. It doesn't help when combining native code with managed code.
Peter Tate
Yup good point...I was thinking c++/cli and c#. Missed that.
Paul
A: 

There is no way that I know of that you can use to combine managed code written in C# and native code written in C++ (or any language). The closest you can come is to use native C++ with managed C++ in a single assembly, which you say caused a substancial slowdown in your code.

Peter Tate
+3  A: 

You can do this quite easily, and entirely supportedly, by producing netmodules. Compile your combined C++ and C++/CLI code into a .obj (C++ netmodules have file extension .obj, C# netmodules have file extension .netmodule) and then link this into your C# project.

Details: http://blogs.msdn.com/junfeng/archive/2005/05/19/420186.aspx. Worked example: http://blogs.msdn.com/junfeng/archive/2005/05/19/420186.aspx.

DrPizza