示例#1
0
        public static int LaunchDebugTargets(this IVsDebugger2 debugger, params VsDebugTargetInfo2[] targets)
        {
            IntPtr ptr             = IntPtr.Zero;
            int    marshalledCount = 0;

            try
            {
                ptr = Marshal.AllocHGlobal(targets.Length * Marshal.SizeOf(typeof(VsDebugTargetInfo2)));
                for (int i = 0; i < targets.Length; i++)
                {
                    IntPtr current = new IntPtr(ptr.ToInt64() + i * Marshal.SizeOf(typeof(VsDebugTargetInfo2)));
                    Marshal.StructureToPtr(targets[i], current, false);
                    marshalledCount++;
                }

                return(debugger.LaunchDebugTargets2((uint)targets.Length, ptr));
            }
            finally
            {
                if (ptr != IntPtr.Zero)
                {
                    for (int i = 0; i < marshalledCount; i++)
                    {
                        IntPtr current = new IntPtr(ptr.ToInt64() + i * Marshal.SizeOf(typeof(VsDebugTargetInfo2)));
                        Marshal.DestroyStructure(current, typeof(VsDebugTargetInfo2));
                    }

                    Marshal.FreeHGlobal(ptr);
                    ptr = IntPtr.Zero;
                }
            }
        }