问题
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?
回答1:
Fixed by doing it like this:
*response = mono_string_new(mono_domain_get(), "Test repsonse");
as suggested by delnan
来源:https://stackoverflow.com/questions/22428411/add-mono-internal-call-where-a-string-is-passed-by-reference