I'm new to C#, and am converting a C++ app which interfaces with a legacy Delphi app. We pass messages between the two apps over UDP, and my colleague is writing a conversion utility to take his Delphi message structure definitions and produce the equivalent in C#. However we have hit upon several issues, which I can't find a way round. The main one seems though to be when using the size of a previously defined message structure to define a constant for use elsewhere. So, in Delphi we have:
Expand|Select|Wrap|Line Numbers
- type
- T_UDP_pkt = array[0..MAX_UDP_PACKET_SIZE - 1] of char;
- T_UDP_header = packed record
- From_MAC: T_MAC;
- From_Area_ID: word; // 0= PC
- Signature: array[0..5] of char;
- Pkt_count: word; // Total number of packets in this set
- Pkt_number: word; // Packet Number
- Transaction: longword;
- spare1: array[0..5] of byte;
- AC_to_AC: array[0..3] of byte;
- datalen: longword; // length of data block following header
- Code: longword;
- Last_received_transaction: longword;
- Hash: TDigest;
- AC_WAN_Port: word;
- Spare2: array[0..7] of byte;
- end;
- const MAX_UDP_DATA_SIZE = (sizeof(T_UDP_pkt) - sizeof(T_UDP_header));
Expand|Select|Wrap|Line Numbers
- [StructLayout(LayoutKind.Sequential, Pack = 1)]
[MarshalAs(UnmanagedType.ByValArray, SizeConst = x)] commands,
but I can't define the constant MAX_UDP_DATA_SIZE as if I use
Expand|Select|Wrap|Line Numbers
- Marshal.Sizeof(T_UDP_pkt)
Expand|Select|Wrap|Line Numbers
- Marshal.Sizeof(typeof(T_UDP_pkt))
Expand|Select|Wrap|Line Numbers
- sizeof(T_UDP_pkt)
s
Expand|Select|Wrap|Line Numbers
- izeof(typeof(T_UDP_pkt))
So I'm a bit stumped. Any help would be muich appreciated, as I'm sure it must be reasonably easy?!