C++/CIL exe, seemless integration with a C# dll?

FYI, I am a C# dev by trade, but i would like to have an existing C++ exe (which i recompiled for C++/CIL) be able to talk back and forth, prefereably as if they were compiled together.

Here are some details as to my question:

I have a C++/CIL exe (Managed C++ compiled with VS2005 Beta 2)

I want to call a DLL Written in C#, and then I want the C# dll to call some functions specified in the calling C++ EXE.  Is this possible    I would want this to be synchronous.

It is easy to call a C# dll from the C++ exe, what I am having trouble figuring out is how to be able to have that C# dll call functions specified in the EXE.

I hope you guys can help,   (if you know resources that I could look at, that would help too)

Thanks,

-Jason



Answer this question

C++/CIL exe, seemless integration with a C# dll?

  • floriflori

  • arsonist

    Thank you for that quick Reply Ritz, this looks good (i will be trying it out later today)

    I was originally going to try to use reflection to call functions from the calling assembly, but there are obvious perf issues with that.

    I will post a reply confirming if the link you sent works :)

  • Glenn Blinckmann

    Ritz, unfortunatly the work found on the site you linked is interesting, but does NOT solve the problem I'm running into.

    It is easy enough to call from managed to unmanaged (or vice-versa)

    What I would like to do is to "bind together" a C++ and a C# application, so that the C++ code can call functions in the C# code, and the c# code can call the c++ code, while sharing state.

    The only way i've found to do this seems to be using reflection,   Though there is perf problems with this.

    Here's how it's "working"  (would like a better solution than this though)
       the C++ code references the C# code
                the C++ code can then call the strongly-linked C# functions as usual.
       the C# code cant reference the C++ code (it would get a circular reference error, and also it would create a new instance of the C++ code, while i want to use the original caller instance)
                uses callingAssembly.GetModule.GetMethod to execute a function from the C++ code.

    is there any other way of doing this   I want the C++ and C# code to be able to freely call eachothers functions.


  • bpmerkel

    The 'nicest' way I've figured out to do this is to pinvoke.   This is better than eating perf to do reflection at runtime, but If anyone knows a better way, please let me know.
  • C++/CIL exe, seemless integration with a C# dll?