Re: unmanaged structure layout error

Benjamin Schwehn <[email protected]> Wed, 11 Nov 2009 21:13:30 +0000
Newsgroups gmane.comp.windows.devel.dotnet.advanced
Message-ID <[email protected]>
On 11.11.2009 20:48, Mike Andrews wrote:
> That would explain the problems then.
> I'll just stick with sequential as that seems to do the trick nicely.
> I read the Pack field member description for the StructLayout attribute and
> I failed to notice that it only worked for Sequential.  Thanks for pointing
> that out.

Btw: If you use "Sequential", the layout will look quite different, as 
the strings only take 4/8 bytes for the string reference with the 
references obviously beeing aligned to the native pointer size.

The layout then looks like:


   MT    Field   Offset                 Type VT     Attr    Value Name
63e84590  400000b        4        System.Double  1 instance 0,000000 _height
63e84590  400000c        c        System.Double  1 instance 0,000000 _width
63e84590  400000d       14        System.Double  1 instance 0,000000 _depth
63e84590  400000e       1c        System.Double  1 instance 0,000000 _a
63eb3470  400000f       24        System.Byte[]  0 instance 00000000 _u1
63eae808  4000010       34        System.UInt16  1 instance        0 _number
63eae808  4000011       36        System.UInt16  1 instance        0 _d
63eb3470  4000012       28        System.Byte[]  0 instance 00000000 _u2
63eb0a00  4000013       2c        System.String  0 instance 00000000 _name
63eb0a00  4000014       30        System.String  0 instance 00000000 
_address1

I find it curious that e.g. _d's offset is higher than the offset of 
_name, so it's not really sequential in the same order as specified. 
Does anyone know why that is?

===================================
View archives and manage your subscription(s) at http://peach.ease.lsoft.com/archives