Marqin
Marqin

Reputation: 1094

Invoking C# methods from C++ with usage of CoreCLR on Linux

I've found that code which allows to execute C# assembly on hosted CLR in Linux. But I want to invoke only some methods from C# dll. I've tried this and this, but I've no idea how to properly on Linux include or redefine:

ICLRMetaHost, ICLRRuntimeInfo, ICLRRuntimeHost, CLSID_CLRMetaHost,
IID_ICLRMetaHost, IID_ICLRRuntimeInfo, CLSID_CLRRuntimeHost,
IID_ICLRRuntimeHost

Do you have any idea or link to some code that invokes C# from C++ with CoreCLR on Linux?

I'm only interested in CoreCLR on Linux ( not Mono! ).

Upvotes: 4

Views: 1428

Answers (1)

Marqin
Marqin

Reputation: 1094

Ok, I found that in order to get delegate to C# function you have to use this three functions provided by coreCLR:

// this one first, to initialize coreCLR
int (coreclrInitializeFunction)(
            const char* exePath,
            const char* appDomainFriendlyName,
            int propertyCount,
            const char** propertyKeys,
            const char** propertyValues,
            void** hostHandle,
            unsigned int* domainId);

// this one to get delegate to your C# function
int (coreclrCreateDelegateFunction)(
              void* hostHandle,
              unsigned int domainId,
              const char* entryPointAssemblyName,
              const char* entryPointTypeName,
              const char* entryPointMethodName,
              void** delegate);

// this one on the end, to close coreCLR
int (coreclrShutdownFunction)(
            void* hostHandle,
            unsigned int domainId);

Here's my example code calling C# function that calls C++ method on C++ object: https://github.com/Marqin/simpleCoreCLRHost

Upvotes: 3

Related Questions