0

I have some .NET C# code that I want to execute through a compiled (unmanaged) C++ program.

Currently what I have done is to put the former into a separate .exe file, which I execute from the C++ program. (The C++ program executes the .exe file, passing in the proper arguments, and captures its output into a variable.)

This works. However, executing a separate .exe file introduces some overhead, and the overhead is noticeable - one notices a half a second gap or so while the .exe program runs and finishes.

Question: Are there any better ways to do such integration? Something that would be faster than executing an .exe.

I'm on Windows XP running Visual Studio 2010.

NoobOverflow
  • 1,208
  • 3
  • 14
  • 19

4 Answers4

1

You might find this link useful: http://msdn.microsoft.com/en-us/library/x0w2664k.aspx

You can create mixed mode assemblies that contain both native code and .NET code. However this is usually done using C++/CLR.

Lloyd
  • 29,197
  • 4
  • 84
  • 98
0

If your goal is only to execute specific code in the C# project you can simply build it as a dll and add it as a reference in the C++ project. From there you can execute parts of the C# code base as you please.

This question using c# dll in project c++ explains how to use the C# assembly in a project compiled with VC++

Community
  • 1
  • 1
evanmcdonnal
  • 46,131
  • 16
  • 104
  • 115
0

One another way of integrating .NET with C++ would be through COM interface. Turn the .NET into COM component. Instantiate and invoke them from C++ is simple and fast enough. Hope it helps.

Cinchoo
  • 6,088
  • 2
  • 19
  • 34
0

In one of our business solutions we had to connect an unmanaged c++ application to a managed c# application. We achieved that by creating one mixed mode "Wrapper" dll, one managed c# "Client" dll on the unmanaged application side and one WCF service with a NamedPipe-Binding, hostet by the managed c# application.

The unmanaged c++ application calls the wrapper, which redirects the request to the c# Client dll. That dll establishes the connection to the WCF service of the c# Application and calls the requested Method on that service.

Christian
  • 143
  • 8