1

is there any function to have the same possibilities like "mono_add_internal_call" in the CLR-Hosting w/o using mono?

Mono

C++ Code:

static MonoString* Sample ()
{
  return mono_string_new (mono_domain_get(), "Hello!");
}
mono_add_internal_call ("Hello::Sample", Sample);

C# Code:

using System;
using System.Runtime.CompilerServices;

class Hello {
    [MethodImplAttribute(MethodImplOptions.InternalCall)]
    extern static string Sample ();
}

Thanks

DogeAmazed
  • 858
  • 11
  • 28
  • 1
    Take a look at C++/CLI (or P/Invoke if you can fit your requirements to its model). – Lucas Trzesniewski Aug 11 '15 at 17:50
  • @LucasTrzesniewski if I load the C# Dll with the CLR-Hosting and use P/Invoke, is the c++ binary the same thats load the C# Dll? – DogeAmazed Aug 11 '15 at 20:15
  • 1
    Hmm... AFAIK P/Invoke calls [`LoadLibrary`](https://msdn.microsoft.com/en-us/library/windows/desktop/ms684175.aspx) under the hood, so it *should* end up resolving to the already-loaded `HMODULE`, and thus to the same address space. But I've never tried that and I'm not sure about it, so the best way to tell is to try it out. – Lucas Trzesniewski Aug 11 '15 at 20:23
  • 1
    @LucasTrzesniewski P/Invoke works, the instance is the same. Thanks! – DogeAmazed Aug 12 '15 at 11:30

1 Answers1

1

Instead of "mono_add_internal_call", I use now P/Invoke. It has the same results. So if you call an C# DLL with CLR-Hosting, the P/Invoke calls the CLR-Hosting Dll and not create a new instance.

Thanks to Lucas.

DogeAmazed
  • 858
  • 11
  • 28