Click here to Skip to main content
16,023,117 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi have a struct like that

typedef struct ServerState{
  WORD  Zone;              
  DWORD Init:1;        
  DWORD Link:1;  
  DWORD Spares:30;    
  WORD  Sectors;              
}TDeaMapServerState;


How can I declare field with dimension like DWORD Init:1;
Posted

1 solution

This should work:
C#
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential)]
public struct ServerState
{
    public ushort Zone;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
    public uint[] Init;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
    public uint[] Link;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 30)]
    public uint[] Spares;
    public ushort Sectors;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900