好的,我发现为了获得 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