[Mono-dev] mono embed: passing arrays from and to unmanaged code

Robert Jordan robertj at gmx.net
Fri Jan 13 11:06:34 EST 2006


Davide,

> - in C
> typedef struct atom_simple
> {
> int a_type;
> float float_value;
> MonoString *string_value;
> };
> 
> - in C#
> [StructLayout (LayoutKind.Sequential)]
> public struct Atom
> {
> public int type;
> public float float_value;
> public string string_value;
> }
> 
> I'd like to put those struct in an array but i need a MonoClass to 
> create the MonoArray, something like:
> 
> MonoClass *c = mono_class_from_name (image, "PureData", "Atom");
> mono_array_new (domain, c, argc);
> 
> but is this the right thing to do? i mean does mono_class_from_name () 
> work on struct also?

Yes. After you've allocated the array, you can fill it up using
the mono_array_* macros declared in metadata/object.h.

Robert


> if not, is there another way i can create a monoarray ?
> 
> sadly the examples in samples/embed don't cover this.
> 
> thank you,
> Davide.
> 
> 
> ----- Original Message ----- From: "Paolo Molaro" <lupus at ximian.com>
> To: <mono-devel-list at lists.ximian.com>
> Sent: Thursday, January 12, 2006 4:48 PM
> Subject: Re: [Mono-dev] mono embed: passing arrays from and to unmanaged 
> code
> 
> 
>> On 01/11/06 Davide Morelli wrote:
>>> I'm trying to pass arrays of floats and strings from and to mono 
>>> embed from
>>> a C software with no luck.
>>>
>>> I'd need to call (from C) managed functions like:
>>> void TakeManyStrings(string [] list);
>>> void TakeManyFloats(float [] list);
>>>
>>> i'd also need to do the same from managed to umnanaged: call a C 
>>> function
>>> from C# passing an array of strings and floats.
>>>
>>> I couldn't find any useful manual page or source code on how to do so..
>>> could anybody point out any reference to me?
>>
>> See mono/docs/internal-calls.
>> An array argument passed to an icall will look like a MonoArray*
>> argument on the C side.
>> A MonoArray* is a reference so it is passed to managed functions like
>> any other reference. See mono/samples/embed/*.c for many invocation
>> examples.
>>
>> lupus
>>
>> -- 
>> -----------------------------------------------------------------
>> lupus at debian.org                                     debian/rules
>> lupus at ximian.com                             Monkeys do it better
>> _______________________________________________
>> Mono-devel-list mailing list
>> Mono-devel-list at lists.ximian.com
>> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>>




More information about the Mono-devel-list mailing list