Re: [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"

Rodrigo Kumpera <[email protected]>
Newsgroups gmane.comp.gnome.mono.general
Message-ID <CACmR+BCe2qFRSP1pMxV=Oj1kEkDSDGcu6NRtHReGke3sVG7D0A@mail.gmail.com>
How does it crash? Did you try debugging it?

The invocation looks ok.

On Wed, Nov 11, 2015 at 3:03 PM, Core_Code <[email protected]> wrote:

> 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.
> _______________________________________________
> Mono-list maillist  -  [email protected]
> http://lists.ximian.com/mailman/listinfo/mono-list
>

_______________________________________________
Mono-list maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-list
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.