sizeof(struct) in C#.net
-
hi, I want to ask how to get size of struct that I made? ex: [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] public struct MT_EVENT { public Int64 TimeStamp; // In FILETIME format //public LARGE_INTEGER TimeStamp; // In FILETIME format public uint UserStatus; // Not used by API public uint EventCode; // Event Code public uint SubReason; // Event sub-reason public uint XtraInfo; // Extra information, e.g. termination public uint FuncCode; // Function active when this event occurred public uint Board; // Board ID public uint Channel; // Global Channel ID (GCI) public IntPtr ptrBuffer; // Related play/record buffer pointer public uint DataLength; // Byte length of data accessed (played/recorded) public IntPtr ptrXtraBuffer; // Pointer to xtra buffer public uint XtraBufferLength; // Length of buffer pointed by ptrXtraBuffer public uint XtraDataLength; // Length of data in buffer pointed by ptrXtraBuffer public uint EventFlag; // Falgs of the following: // bit 0x00000001: 1 - Appl created the event // 0 - NTi DLL created the event // bit 0x00000002: 1 - Appl allocated ptrtraBuffer // 0 - NTi DLL allocated ptrXtraBuffer }
-
hi, I want to ask how to get size of struct that I made? ex: [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] public struct MT_EVENT { public Int64 TimeStamp; // In FILETIME format //public LARGE_INTEGER TimeStamp; // In FILETIME format public uint UserStatus; // Not used by API public uint EventCode; // Event Code public uint SubReason; // Event sub-reason public uint XtraInfo; // Extra information, e.g. termination public uint FuncCode; // Function active when this event occurred public uint Board; // Board ID public uint Channel; // Global Channel ID (GCI) public IntPtr ptrBuffer; // Related play/record buffer pointer public uint DataLength; // Byte length of data accessed (played/recorded) public IntPtr ptrXtraBuffer; // Pointer to xtra buffer public uint XtraBufferLength; // Length of buffer pointed by ptrXtraBuffer public uint XtraDataLength; // Length of data in buffer pointed by ptrXtraBuffer public uint EventFlag; // Falgs of the following: // bit 0x00000001: 1 - Appl created the event // 0 - NTi DLL created the event // bit 0x00000002: 1 - Appl allocated ptrtraBuffer // 0 - NTi DLL allocated ptrXtraBuffer }
can I use this: MT_EVENT evt = new MT_EVENT(); uint length= (uint) Marshal.SizeOf(evt);
-
can I use this: MT_EVENT evt = new MT_EVENT(); uint length= (uint) Marshal.SizeOf(evt);
-
can I use this: MT_EVENT evt = new MT_EVENT(); uint length= (uint) Marshal.SizeOf(evt);
Hi, if you are going to pass such a struct to the native world, that would be the way to go, yes. BTW: the value will vary, depending on Win32/Win64 as an IntPtr is elastic. :)
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.