0

我将 Mono 嵌入到用 Objective-c 编写的 MacOSX 应用程序中。

我正在访问一个 C# lib (DDL),它只包含一堆返回不同类型的静态方法。到目前为止,我可以成功返回 int、double 和 string,但是在检索返回的数组时遇到了麻烦......

例如,这是我检索 int 的方法:

MonoDomain *domain = mono_jit_init("TestDomain");

NSBundle* mainBundle = [NSBundle mainBundle];
NSString* dll = [mainBundle pathForResource:@"TestLib86" ofType:@"dll"];

MonoAssembly* assembly = mono_domain_assembly_open(domain, [dll UTF8String]);

MonoImage* image = mono_assembly_get_image(assembly);

// Get INTEGER

// get a method handle to whatever you like
const char* descAsString = "MiniLib86.Show:GetInt()";
MonoMethodDesc* description = mono_method_desc_new(descAsString,TRUE);
MonoMethod* method = mono_method_desc_search_in_image(description, image);

// call it
void* args[0];
MonoObject *result = mono_runtime_invoke(method, NULL, args, NULL);    
int int_result = *(int*)mono_object_unbox (result);

// See the result in log
NSLog(@"int result %i", int_result);

C# 中返回 List 的方法如下所示:

public static List<int> GetListInt()
{
    return new System.Collections.Generic.List<int>{1,2,3,4,5};
}

任何帮助将非常感激 !

4

1 回答 1

0

看看mono_runtime_invoke_array

于 2012-04-09T18:46:59.667 回答