示例#1
0
 public bool Equals(_DROPFILES other)
 {
     return(this.pFiles == other.pFiles &&
            this.X == other.X &&
            this.Y == other.Y &&
            this.fNC == other.fNC &&
            this.fWide == other.fWide);
 }
示例#2
0
        private IntPtr PackageSelectionData(StringBuilder sb, bool addEndFormatDelimiter)
        {
            if (sb == null || sb.ToString().Length == 0 || this.ItemsDraggedOrCutOrCopied.Count == 0)
            {
                return(IntPtr.Zero);
            }

            // Double null at end.
            if (addEndFormatDelimiter)
            {
                if (sb.ToString()[sb.Length - 1] != '\0')
                {
                    sb.Append('\0');
                }
            }

            // We request unmanaged permission to execute the below.
            new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();

            _DROPFILES df         = new _DROPFILES();
            int        dwSize     = Marshal.SizeOf(df);
            Int16      wideChar   = 0;
            int        dwChar     = Marshal.SizeOf(wideChar);
            int        structSize = dwSize + ((sb.Length + 1) * dwChar);
            IntPtr     ptr        = Marshal.AllocHGlobal(structSize);

            df.pFiles = dwSize;
            df.fWide  = 1;
            IntPtr data = IntPtr.Zero;

            try
            {
                data = UnsafeNativeMethods.GlobalLock(ptr);
                Marshal.StructureToPtr(df, data, false);
                IntPtr strData = new IntPtr((long)data + dwSize);
                DragDropHelper.CopyStringToHGlobal(sb.ToString(), strData, structSize);
            }
            finally
            {
                if (data != IntPtr.Zero)
                {
                    UnsafeNativeMethods.GlobalUnLock(data);
                }
            }

            return(ptr);
        }
示例#3
0
        /// <summary>
        /// Returns the data packed after the DROPFILES structure.
        /// </summary>
        /// <param name="dropHandle"></param>
        /// <returns></returns>
        internal static string GetData(IntPtr dropHandle)
        {
            IntPtr data = UnsafeNativeMethods.GlobalLock(dropHandle);

            try
            {
                _DROPFILES df = (_DROPFILES)Marshal.PtrToStructure(data, typeof(_DROPFILES));
                if (df.fWide != 0)
                {
                    IntPtr pdata = new IntPtr((long)data + df.pFiles);
                    return(Marshal.PtrToStringUni(pdata));
                }
            }
            finally
            {
                if (data != null)
                {
                    UnsafeNativeMethods.GlobalUnLock(data);
                }
            }

            return(null);
        }
        private IntPtr PackageSelectionData(StringBuilder sb, bool addEndFormatDelimiter)
        {
            if(sb == null || sb.ToString().Length == 0 || this.ItemsDraggedOrCutOrCopied.Count == 0)
            {
                return IntPtr.Zero;
            }

            // Double null at end.
            if(addEndFormatDelimiter)
            {
                if(sb.ToString()[sb.Length - 1] != '\0')
                {
                    sb.Append('\0');
                }
            }

            // We request unmanaged permission to execute the below.
            new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();

            _DROPFILES df = new _DROPFILES();
            int dwSize = Marshal.SizeOf(df);
            Int16 wideChar = 0;
            int dwChar = Marshal.SizeOf(wideChar);
            int structSize = dwSize + ((sb.Length + 1) * dwChar);
            IntPtr ptr = Marshal.AllocHGlobal(structSize);
            df.pFiles = dwSize;
            df.fWide = 1;
            IntPtr data = IntPtr.Zero;
            try
            {
                data = UnsafeNativeMethods.GlobalLock(ptr);
                Marshal.StructureToPtr(df, data, false);
                IntPtr strData = new IntPtr((long)data + dwSize);
                DragDropHelper.CopyStringToHGlobal(sb.ToString(), strData, structSize);
            }
            finally
            {
                if(data != IntPtr.Zero)
                    UnsafeNativeMethods.GlobalUnLock(data);
            }

            return ptr;
        }
示例#5
0
 public bool Equals(_DROPFILES other)
 {
     return this.pFiles == other.pFiles
         && this.X == other.X
         && this.Y == other.Y
         && this.fNC == other.fNC
         && this.fWide == other.fWide;
 }