NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

structlayout

Specifies the layout of fields in a class or struct for interoperability with unmanaged code.

[structlayout(
   kind,
   Pack=pack,
   CharSet=charset,
   CheckFastMarshal=checkfastmarshal
)]

Applies To

Class and struct declarations.

Parameters

kind
A LayoutKind value specifying the kind of layout: sequential, union, or explicit.
pack (Optional)
An int; the packing size in bytes. Must be 1, 2, 4, 8, or 16. Default is 8.
charset (Optional)
A CharSet value specifying the default character set for contained character and string types. Default value is CharSet.Auto.
checkfastmarshal (Optional)
A bool; if true, generate a compile-time warning if the type is not blittable. Defaults to false (no warning is generated).

Remarks

structlayout is a single-use attribute. structlayout is an alias for System.InterOp.StructLayoutAttribute.

If kind is Layout.Sequential, successive members are assigned increasing offsets such that no members overlap, with padding inserted as necessary to satisfy the packing size constraint.

If kind is Layout.Union, all members are assigned offset 0. Union members cannot contain reference types.

If kind is Layout.Explicit, every field must have the structoffset attribute; otherwise, use of structoffset is prohibited.

Example

The following PDH_RAW_COUNTER struct exactly matches the Platform SDK PDH_RAW_COUNTER data structure.

[structlayout(LayoutKind.Sequential, pack=8)]
public struct PDH_RAW_COUNTER {
   public int CStatus;
   public FILETIME TimeStamp;
   public long FirstValue;
   public long SecondValue;
   public int MultiCount;
} 
[structlayout(LayoutKind.Sequential, pack=4)]
public struct FILETIME {
   public int dwLow;
   public int dwHigh;
} 

See Also

C# Attributes