public static SafeUnmanagedProcThreadAttributeList Create(int attributeCount)
        {
            var result     = default(SafeUnmanagedProcThreadAttributeList);
            var size       = IntPtr.Zero;
            int win32Error = 0;

            Kernel32.InitializeProcThreadAttributeList(IntPtr.Zero, attributeCount, 0, ref size);

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
            }
            finally
            {
                var buffer = Marshal.AllocHGlobal(size.ToInt32());

                if (!Kernel32.InitializeProcThreadAttributeList(buffer, attributeCount, 0, ref size))
                {
                    win32Error = Marshal.GetLastWin32Error();
                    Marshal.FreeHGlobal(buffer);
                }

                result = new SafeUnmanagedProcThreadAttributeList(buffer);
            }

            if (win32Error != 0)
            {
                throw new Win32Exception(win32Error);
            }

            return(result);
        }
 public static extern unsafe bool UpdateProcThreadAttribute(
     [In] SafeUnmanagedProcThreadAttributeList lpAttributeList,
     [In] int dwFlags,
     [In] IntPtr Attribute,
     [In] void *lpValue,
     [In] IntPtr cbSize,
     [In] IntPtr lpPreviousValue,
     [In] IntPtr lpReturnSize);
 public ProcThreadAttributeList(int attributeCount)
 {
     _unmanaged = SafeUnmanagedProcThreadAttributeList.Create(attributeCount);
 }