Inheritance: Microsoft.Win32.SafeHandles.SafeHandleZeroOrMinusOneIsInvalid
示例#1
0
        void IDataObject.GetData(FORMATETC[] fmt, STGMEDIUM[] m)
        {
            STGMEDIUM retMedium = new STGMEDIUM();

            if (fmt == null || fmt.Length < 1)
            {
                return;
            }

            SafeGlobalAllocHandle copy = null;

            foreach (DataCacheEntry e in this.entries)
            {
                if (e.Format.cfFormat == fmt[0].cfFormat /*|| fmt[0].cfFormat == InternalNativeMethods.CF_HDROP*/)
                {
                    retMedium.tymed = e.Format.tymed;

                    // Caller must delete the memory.
                    copy = DragDropHelper.CopyHGlobal(e.Data);
                    retMedium.unionmember = copy.DangerousGetHandle();
                    break;
                }
            }

            if (m != null && m.Length > 0)
            {
                m[0] = retMedium;
                if (copy != null)
                {
                    copy.SetHandleAsInvalid();
                }
            }
        }
示例#2
0
        public static SafeGlobalAllocHandle CopyHGlobal(SafeGlobalAllocHandle data)
        {
            IntPtr  src  = UnsafeNativeMethods.GlobalLock(data);
            UIntPtr size = UnsafeNativeMethods.GlobalSize(data);
            SafeGlobalAllocHandle ptr = UnsafeNativeMethods.GlobalAlloc(0, size);
            IntPtr buffer             = UnsafeNativeMethods.GlobalLock(ptr);

            try
            {
                UnsafeNativeMethods.MoveMemory(buffer, src, size);
            }
            finally
            {
                if (buffer != IntPtr.Zero)
                {
                    UnsafeNativeMethods.GlobalUnlock(ptr);
                }

                if (src != IntPtr.Zero)
                {
                    UnsafeNativeMethods.GlobalUnlock(data);
                }
            }

            return(ptr);
        }
        public static SafeGlobalAllocHandle CopyHGlobal(SafeGlobalAllocHandle data)
        {
            IntPtr src = UnsafeNativeMethods.GlobalLock(data);
            UIntPtr size = UnsafeNativeMethods.GlobalSize(data);
            SafeGlobalAllocHandle ptr = UnsafeNativeMethods.GlobalAlloc(0, size);
            IntPtr buffer = UnsafeNativeMethods.GlobalLock(ptr);

            try
            {
                UnsafeNativeMethods.MoveMemory(buffer, src, size);
            }
            finally
            {
                if(buffer != IntPtr.Zero)
                {
                    UnsafeNativeMethods.GlobalUnlock(ptr);
                }

                if(src != IntPtr.Zero)
                {
                    UnsafeNativeMethods.GlobalUnlock(data);
                }
            }

            return ptr;
        }
示例#4
0
 /// <summary>
 /// The method that does the cleanup.
 /// </summary>
 /// <param name="disposing"></param>
 private void Dispose(bool disposing)
 {
     if (disposing)
     {
         SafeGlobalAllocHandle handle = this.data;
         if (handle != null)
         {
             handle.Dispose();
             data = null;
         }
     }
 }
示例#5
0
        public static string GetSourceProjectPath(Microsoft.VisualStudio.OLE.Interop.IDataObject dataObject)
        {
            string    projectPath = null;
            FORMATETC fmtetc      = CreateFormatEtc(CF_VSPROJECTCLIPDESCRIPTOR);

            if (QueryGetData(dataObject, ref fmtetc) == VSConstants.S_OK)
            {
                STGMEDIUM stgmedium = DragDropHelper.GetData(dataObject, ref fmtetc);
                if (stgmedium.tymed == (uint)TYMED.TYMED_HGLOBAL && stgmedium.unionmember != IntPtr.Zero)
                {
                    // We are releasing the cloned hglobal here.
                    using (SafeGlobalAllocHandle dropInfoHandle = new SafeGlobalAllocHandle(stgmedium.unionmember, true))
                    {
                        projectPath = GetData(dropInfoHandle);
                    }
                }
            }

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

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

            return(null);
        }
示例#7
0
 /// <summary>
 /// The IntPtr is data allocated that should be removed. It is allocated by the ProcessSelectionData method.
 /// </summary>
 public DataCacheEntry(FORMATETC fmt, SafeGlobalAllocHandle data, DATADIR dir)
 {
     this.format  = fmt;
     this.data    = data;
     this.dataDir = dir;
 }
示例#8
0
 internal static extern bool GlobalUnlock(SafeGlobalAllocHandle h);
 /// <summary>
 /// The IntPtr is data allocated that should be removed. It is allocated by the ProcessSelectionData method.
 /// </summary>
 public DataCacheEntry(FORMATETC fmt, SafeGlobalAllocHandle data, DATADIR dir)
 {
     this.format = fmt;
     this.data = data;
     this.dataDir = dir;
 }
 /// <summary>
 /// The method that does the cleanup.
 /// </summary>
 /// <param name="disposing"></param>
 private void Dispose(bool disposing)
 {
     if (disposing)
     {
         SafeGlobalAllocHandle handle = this.data;
         if (handle != null)
         {
             handle.Dispose();
             data = null;
         }
     }
 }
 internal static extern bool GlobalUnlock(SafeGlobalAllocHandle h);
 internal static extern UIntPtr GlobalSize(SafeGlobalAllocHandle h);
 internal static extern IntPtr GlobalLock(SafeGlobalAllocHandle h);
示例#14
0
 internal static extern UIntPtr GlobalSize(SafeGlobalAllocHandle h);
        /// <summary>
        /// Returns the data packed after the DROPFILES structure.
        /// </summary>
        /// <param name="dropHandle"></param>
        /// <returns></returns>
        public static string GetData(SafeGlobalAllocHandle dropHandle)
        {
            IntPtr data = UnsafeNativeMethods.GlobalLock(dropHandle);
            try
            {
                _DROPFILES df = (_DROPFILES)Marshal.PtrToStructure(data, typeof(_DROPFILES));
                if(df.fWide)
                {
                    IntPtr pdata = new IntPtr((long)data + df.pFiles);
                    return Marshal.PtrToStringUni(pdata);
                }
            }
            finally
            {
                if(data != null)
                {
                    UnsafeNativeMethods.GlobalUnlock(dropHandle);
                }
            }

            return null;
        }
        public static string GetSourceProjectPath(Microsoft.VisualStudio.OLE.Interop.IDataObject dataObject)
        {
            string projectPath = null;
            FORMATETC fmtetc = CreateFormatEtc(CF_VSPROJECTCLIPDESCRIPTOR);

            if(QueryGetData(dataObject, ref fmtetc) == VSConstants.S_OK)
            {
                STGMEDIUM stgmedium = DragDropHelper.GetData(dataObject, ref fmtetc);
                if(stgmedium.tymed == (uint)TYMED.TYMED_HGLOBAL && stgmedium.unionmember != IntPtr.Zero)
                {
                    // We are releasing the cloned hglobal here.
                    using (SafeGlobalAllocHandle dropInfoHandle = new SafeGlobalAllocHandle(stgmedium.unionmember, true))
                    {
                        projectPath = GetData(dropInfoHandle);
                    }
                }
            }

            return projectPath;
        }
示例#17
0
 public void SetData(FORMATETC format, SafeGlobalAllocHandle data)
 {
     this.entries.Add(new DataCacheEntry(format, data, DATADIR.DATADIR_SET));
 }
示例#18
0
 public void SetData(FORMATETC format, SafeGlobalAllocHandle data)
 {
     this.entries.Add(new DataCacheEntry(format, data, DATADIR.DATADIR_SET));
 }
示例#19
0
 internal static extern IntPtr GlobalLock(SafeGlobalAllocHandle h);