[Mono-devel-list] Managed to unmanaged structure question

Peter Dennis Bartok peter at novonyx.com
Fri Jun 11 00:27:48 EDT 2004


Hi all,

Got a (hopefully) simple question:

If I have a structure:

  internal struct TestStructure
         {
                 internal int      number;
[MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, 
SizeConst=1024)]
                 internal byte[] stuff;
         }

and some code:

  TestStructure t = new TestStructure();

  Console.WriteLine("Size of t: {0}", 
Marshal.SizeOf(typeof(TestStructure)));

I it returns a size of 8, instead of the expected size of 1028.

If I now pass this structure as ref to unmanaged code, and that code 
writes more than 8 bytes, it seems that data gets overwritten. (I've got 
some sample code that shows that the call stack is ok before the 
P/Invoke and messed up afterwards, if I write more data)

Can anyone shed light on this, whether I'm up in the night or whether 
this is a real bug?

Cheers,
   Peter





More information about the Mono-devel-list mailing list