Question

I'm trying to create a method using mono where a string is passed by reference, here is the test code I have:

C++:

static bool p_TestMethod(int num, MonoString ** response) {

    auto b = mono_string_new(mono_domain_get(), "Test repsonse");
    response = &b;

    return true;
}
//...
mono_add_internal_call("SharpCode.TestClass::Testmethod", p_TestMethod);

C#:

    [MethodImpl(MethodImplOptions.InternalCall)]
    public static extern bool Testmethod(int num, out string response);

    public bool RunTheTest()
    {
        string x;
        Testmethod(0, out x);
        Console.WriteLine("Test: {0}", x);

        return true;
    }

But no response is printed (only Test: )

How do I properly pass a string by reference using Mono?

Was it helpful?

Solution

Fixed by doing it like this:

*response = mono_string_new(mono_domain_get(), "Test repsonse"); 

as suggested by delnan

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top