[Mono-list] [embedding] "moving from mono_runtime_invoke() to mono_method_get_unmanaged_thunk()" or "how to call class method that takes and returns a string via thunks"

Core_Code julian at corecode.at
Wed Nov 11 20:03:19 UTC 2015


hello,

we are currently embedding Mono to use a C# DLL, which works fine.

we are using mono_runtime_invoke() to invoke a class method and are
obtaining the resulting object just fine.

however, for performance reasons we'd like to switch to using the 'unmanaged
thunks', which we did not get to work. our call differes from the example in
the 'embedding mono' docs by the parameters and the fact that we are calling
a class method. however we try, just different crashes.


the function we have to call has this prototype:
public static string ParseToJSON(string input)

which seems to translate to a mono method description of
XLParser.ExcelFormulaParser:ParseToJSON (string)

we have no problem using mono_runtime_invoke() to call it exactly like this:

    
MonoAssembly *assembly = mono_domain_assembly_open(domain,
"/path/to/XLParser.dll");
MonoImage *image = mono_assembly_get_image(assembly);
MonoClass *classHandle = mono_class_from_name(image, "XLParser",
"ExcelFormulaParser");
const char *descAsString = "XLParser.ExcelFormulaParser:ParseToJSON
(string)";
MonoMethodDesc *description = mono_method_desc_new(descAsString, 0);
method = mono_method_desc_search_in_class(description, classHandle);
void *args[1] = {mono_string_new (domain, "A+B")};
MonoObject *resultObject = mono_runtime_invoke(method, NULL, args, NULL);
MonoString *resultString = mono_object_to_string(resultObject, NULL);
char *resultCString = mono_string_to_utf8(resultString);


now we are trying the thunk method:

typedef MonoObject* (*ParseToJSON) (MonoString *obj1,MonoString *obj2);
ParseToJSON func = mono_method_get_unmanaged_thunk(method);
MonoString *s = mono_string_new (domain, "A+B");
MonoObject *result = func(s,NULL);
MonoString *resultstring = mono_object_to_string(result, NULL);
char *str = mono_string_to_utf8(resultstring);

but it crashes - any idea how to call a class method via thunks?




--
View this message in context: http://mono.1490590.n4.nabble.com/embedding-moving-from-mono-runtime-invoke-to-mono-method-get-unmanaged-thunk-or-how-to-call-class-me-tp4666935.html
Sent from the Mono - General mailing list archive at Nabble.com.


More information about the Mono-list mailing list