1

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;

1 Answer 1

1
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));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.