Reputation: 4229
I need to create an array inside a structure for the purpose of connecting to an embedded device. As such we using pointers to both the structure and it's internal fields...I tried the code below but should i just create 100 ints and be done??
[StructLayout( LayoutKind.Sequential )]
public struct HRTF
{
UInt32 PPP;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 100)]
UInt32[] taps;
. . .
}
. . .
HRTF effects = new HRTF();
/* --- ERROR cannot get address of, Sizeof ect ..to unmanaged typE 'HRTF' */
int offset = ((int)&effects.taps - startOffset) / 4;
int length = sizeof(HRTF) / 4;
Upvotes: 1
Views: 107
Reputation: 14522
fixed (uint* pt = effects.taps)
{
// pt is not pointer to taps
}
var bts = Marshal.SizeOf(effects); // bts has size of HRTF in bytes.
OR
var bts = Marshal.SizeOf(typeof(HRTF));
Upvotes: 1