添加 Mono 内部调用,其中通过引用传递字符串 [英] add Mono internal call where a string is passed by reference
本文介绍了添加 Mono 内部调用,其中通过引用传递字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用单声道创建一个方法,其中通过引用传递字符串,这是我的测试代码:
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: )
如何使用 Mono 正确地通过引用传递字符串?
How do I properly pass a string by reference using Mono?
推荐答案
通过这样做来修复:
*response = mono_string_new(mono_domain_get(), "Test repsonse");
按照 delnan 的建议
as suggested by delnan
这篇关于添加 Mono 内部调用,其中通过引用传递字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文