Exemple #1
0
        static void Main(string[] args)

        {
            OUTER ed = new OUTER();

            INNER[] inn = new INNER[10];

            INNER test = new INNER();

            int iStructSize = Marshal.SizeOf(test);



            int sz = inn.Length * iStructSize;

            ed.inner = new byte[sz];



            try

            {
                CallTest(ref ed);
            }

            catch (Exception e)

            {
                Console.WriteLine(e.Message);
            }

            IntPtr buffer = Marshal.AllocCoTaskMem(iStructSize * 10);

            Marshal.Copy(ed.inner, 0, buffer, iStructSize * 10);



            int iCurOffset = 0;

            for (int i = 0; i < 10; i++)

            {
                inn[i] = (INNER)Marshal.PtrToStructure(new
                                                       IntPtr(buffer.ToInt32() + iCurOffset), typeof(INNER));

                iCurOffset += iStructSize;
            }

            Console.WriteLine(ed.field1);

            Marshal.FreeCoTaskMem(buffer);
        }
Exemple #2
0
 public static extern void CallTest(ref OUTER po);