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.

3
  • 1
    You should be able to do this using the native CLR host APIs. Commented Nov 15, 2012 at 17:35
  • 1
    You do understand there is likely still going to be this 1 second gap right? Commented Nov 15, 2012 at 17:42
  • If you are running the managed program repeatedly, you may find it more efficient to re-engineer it as a persistent service. Commented Nov 15, 2012 at 17:52

4 Answers 4

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.

Sign up to request clarification or add additional context in comments.

Comments

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++

Comments

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.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.