'Loading a .NET-5 assembly from a C++ code

I'm trying to load an assembly and run code from a C++ host with load_assembly_and_get_function_pointer. I found an example in github from microsoft, that works, but no further documentation. What are the meanings of the return codes i.E. -2146233054?

relevant code

C++:

    int rc = load_assembly_and_get_function_pointer(
        dotnetlib_path.c_str(),                         // <---- Wide character!!!
        dotnet_type.c_str(),
        STR("Load"),
        nullptr, // STR("load_delegate_type") /*delegate_type_name*/,
        nullptr,
        reinterpret_cast<void**>(&loadMethodPtr));
    if (rc!=0 || loadMethodPtr==nullptr) {
      INFO(("load_assembly_and_get_function_pointer(" STR_FORMAT ", load_delegate_type) ... failed (%d) !!!", dotnetlib_path.data(), rc));
    }

C#:

namespace CooDotNetV2
{
  public class CooDotNetV2
  {
    static Assembly cooAssembly;

    //public delegate IntPtr load_delegate_type(IntPtr assemblyname);
    public static IntPtr Load(IntPtr iassemblyname, int argLength)
    {
      String assemblyname = Marshal.PtrToStringAuto(iassemblyname);
      cooAssembly = Assembly.LoadFrom(assemblyname);
      return (IntPtr)1;
    }
  }
}

Any ideas?

Thanks in advance

Martin



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source