【问题标题】:Invoking C# methods from C++ with usage of CoreCLR on Linux在 Linux 上使用 CoreCLR 从 C++ 调用 C# 方法
【发布时间】:2015-03-04 11:17:55
【问题描述】:

我找到了that code,它允许在 Linux 中托管的 CLR 上执行 C# 程序集。但我只想从 C# dll 调用一些方法。我试过thisthis,但我不知道如何在Linux 上正确包含或重新定义:

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

你有什么想法或链接到一些在 Linux 上使用 CoreCLR 从 C++ 调用 C# 的代码吗?

我只对 Linux 上的 CoreCLR 感兴趣(不是 Mono!)。

【问题讨论】:

  • Hmya,这是 CoreCLR 的定义问题,也是微软开源它的基本原因。 Somebody 将不得不以 Unix 的方式充实 coreclr/src/dlls/mscoree/unixinterface.cpp,将其扩展到非常简单的 ExecuteAssembly() 入口点之外。那个人可能是你。
  • 看看Kestrel项目如何与libuv互操作,github.com/aspnet/KestrelHttpServer/blob/…。也许可以将函数指针编组到 c# 委托中。

标签: c# c++ .net coreclr


【解决方案1】:

好的,我发现为了获得 C# 函数的委托,您必须使用 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);

这是我调用 C# 函数的示例代码,该函数在 C++ 对象上调用 C++ 方法:https://github.com/Marqin/simpleCoreCLRHost

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-26
    • 2016-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多