[Help] C#: Marshalling of a structure with a float array field.

festijazz
festijazz used Ask the Experts™
on
Hello Everyone,

I have a question about the marshalling of a structure with a float array field defined.
How should I defined the marshalling type ?

        private const int _LIMIT_ROWS = 128;
        private const int _LIMIT_COLS = 2;

        private struct stBNC
        {
            [MarshalAs(UnmanagedType.I4)]
            public int Rows;

            [MarshalAs(UnmanagedType.I4)]
            public int Cols;

            [[b]MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)]
            public float[_LIMIT_ROWS * _LIMIT_COLS] Level;[/b]
        }

Open in new window


Thank you very much in advance.
Best regards.
MiQi
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Hello All,

I think I have found the solution:

        private const int _SPL_LIMIT_ROWS = 128;
        private const int _SPL_LIMIT_COLS = 2;

        [StructLayout(LayoutKind.Sequential)]
        private struct stBackgroundNoiseCorrection
        {
            [MarshalAs(UnmanagedType.I4)]
            public int lVersionNumber;

            [MarshalAs(UnmanagedType.I4)]
            public int Rows;

            [MarshalAs(UnmanagedType.I4)]
            public int Cols;

            [MarshalAs(UnmanagedType.ByValArray, SizeConst = _SPL_LIMIT_ROWS * _SPL_LIMIT_COLS)]
            public float[] Level;

        }

Open in new window


Best regards.
MiQi

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial