c# - 在 Mac 上从 C++ 代码调用时 `coreclr_create_delegate` 不起作用

标签 c# c++ macos .net-core

我需要从 Mac 上的 C++ 代码调用 C# 库中声明的方法。我正在使用 .Net Core 框架 2.0.x(2.0.3、2.0.4)。

为了让它工作,我调用了 coreclr_initialize,它成功运行并返回 0。然后,我通过传递所需参数来调用 coreclr_create_delegate,如下所示:

auto no_del = []( auto x ) { (void)(x); };
auto csharp_runIt = std::unique_ptr<csharp_runIt_t, decltype(no_del)>(nullptr, no_del);

int status = coreclr_create_delegate (
                                          hostHandle,
                                          domainId,
                                          assemblyName.c_str(),
                                          entryPointType.c_str(),
                                          entryPointName.c_str(),
                                          reinterpret_cast<void**>(&csharp_runIt)
                                          );

这里,hostHandledomainId 是从coreclr_initialize 接收到的。其余值是:assemblyName(dll 名称)、entryPointType(类名称)和 entryPointName(函数名称)。 运行它会返回带有十六进制代码的负值:0x80070002

我还将库名、类名和方法名作为参数传递。 由于没有多少人尝试过,因此在线提供的帮助不多。

最佳答案

如果该类不在全局命名空间中,则需要为该类指定完全限定名。例如,您需要在此处将 entryPointType 设置为 samplelibrary.SampleClass

关于c# - 在 Mac 上从 C++ 代码调用时 `coreclr_create_delegate` 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48070556/

相关文章:

c++ - 使用 C++ 如何在 mac osx Finder 中显示覆盖图标

python - 使用 conda 克隆环境时出现异常

c# - 在迷宫中的消息框上插入声音和图像

java - 从图像中去除背景噪音,使 OCR 的文本更清晰

c++ - 我可以将 std::ostream& 传递给需要 std::ofstream 的函数吗

c++ - boolean 冒号初始化

macos - couchdb 在 MacOSX 上在哪里存储管理员用户数据?

c# - 如何执行命令并获取其输出

c# - 使用 MySqlCommandBuilder 时更新 datagridview 中的时间值时日期值发生变化

c# - 如何在调试时刷新 Excel