[Mono-devel-list] [Embedding Mono] Accessing Fields

Friedrich Priewasser priewasser at gmx.at
Fri Aug 6 13:29:36 EDT 2004


On Wed, 04 Aug 2004 10:21:54 +0200, Joe Ante <joe at uti.is> wrote:

>> Hi,
>>
>> I'm trying to access a field of a C# struct (from C), but i don't get  
>> the
>> expected result.
>> My programm should set i to 11 and then write out this value by calling
>> "Write()".
>> If T is a class this works, but if T is a struct I dont't get "11".
>> By calling mono_field_set with an address reduced by 8 (size of a
>> MonoObject?) it works
>> (field offset of "i" is 8, using class and using struct)
>>
>> Reducing the address by 8 is not very clean,
>> so, can anyone help me and tell me what i've done wrong?
> I guess that its a bug in mono or mono_field_set_value is just not  
> supposed
> to be called on structs.
> But if you are using structs anyway it is possibly simpler to just have  
> the
> same struct on the C side and use mono_value_box.
>
> [StructLayout (LayoutKind.Sequential)] on the C# side.
>
> struct Cstruct {  int i; };
> Cstruct a;
> A.i = 10;
> MonoObject* o = mono_value_box (domain, klass, &a);

I can't use this method since I can't ensure that [StructLayout  
(LayoutKind.Sequential)] is set (I only have access to the assembly)




More information about the Mono-devel-list mailing list