I want to call my .NET code from unmanaged C++. My process entrypoint is .NET based, so I don’t have to worry about hosting the CLR. I know it can be done using COM wrappers for .NET objects, but I would like to access individual static methods of managed classes, so COM isn’t my shortest/easiest route.
Share
Assuming you are talking about real unmanaged code – not just native C++ running in a mixed-mode assembly compiled with /clr – the easiest way is to create a wrapper to your .NET code in C++/CLI. You can then export the C++/CLI methods by just marking them with __declspec(dllexport).
Alternatively, if you have control over the invocation of the unmanaged code, you can marshal function-pointers to your .NET methods and pass them to the unmanaged code.