Mixed Mode EXE

How can I create an app with both managed and unmanaged code, with wrappers to switch between the modes

I know this is possible: I have done it in C++. I would like to know how to do it in a hex editor (in principle, of course!)

Thanks.



Answer this question

Mixed Mode EXE

  • andy0203

    Yes C++ and C#/VB/whatever/managed can live together. You have to follow some rules and hunt in MSDN for the quirks, but it is very do-able. Note that what Microsoft called Managed Extensions for C++ (i.e. unmanaged code calling managed, where all you do is flip a compiler switch on your existing C++ code to make it play nice) is going away in Visual Studio 2005 and being replaced by a slightly different syntax, so pay attention to that issue when you research it.

    Several keywords to search MSDN (i.e. msdn.microsoft.com) with: interop, interoperability, P/Invoke (a way of calling unmanaged DLL functions from managed code, including calling Win32 API functions).

    Several articles I found useful:
        MSDN articles titled "A Client In Managed Extensions For C++", "A Component In Visual C#" (both describe how unmanaged C++ can call into managed C#, VB and C++ DLLs). There's a similar pair of articles "A Client In Visual C#" and "A Component In Managed Extensions For C++". Search msdn.microsoft.com for the titles.

    MSDN Magazine (available on msdn.microsoft.com) January 2005, "C++ Q&A" column, look for the question entitled "Can I call the .Net Framework from my MFC app ". VERY valuable info on what compiler settings you need in the unmanaged files that call into managed code. Beware of setting the /clr compiler flag on all your unmanaged files - the "Managed Extensions" claim that all you have to do is throw the /clr switch and it works is not always true. I tend to isolate all my calls into managed code in a few routines in a few files, and only use the /clr switch on those few files.

    Also note that in Studio 2005 the /clr flag will be INcompatible with static linking to the CRT libraries (in case you care). You'll have to dynamically link to (and ship) the DLLs.

    Good luck!!

  • DuckPuppy

    http://msdn.microsoft.com/newsgroups/ might help in such issues.

    Thanks,
    Ayman Shoukry
    VC++ Team


  • Mixed Mode EXE