Inheritance: Microsoft.Win32.SafeHandles.SafeHandleZeroOrMinusOneIsInvalid
Exemplo n.º 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();
                }
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 3
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;
        }
Exemplo n.º 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;
         }
     }
 }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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;
 }
Exemplo n.º 8
0
 internal static extern bool GlobalUnlock(SafeGlobalAllocHandle h);
Exemplo n.º 9
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;
 }
Exemplo n.º 10
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;
         }
     }
 }
 internal static extern bool GlobalUnlock(SafeGlobalAllocHandle h);
 internal static extern UIntPtr GlobalSize(SafeGlobalAllocHandle h);
 internal static extern IntPtr GlobalLock(SafeGlobalAllocHandle h);
Exemplo n.º 14
0
 internal static extern UIntPtr GlobalSize(SafeGlobalAllocHandle h);
Exemplo n.º 15
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;
        }
Exemplo n.º 16
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;
        }
Exemplo n.º 17
0
 public void SetData(FORMATETC format, SafeGlobalAllocHandle data)
 {
     this.entries.Add(new DataCacheEntry(format, data, DATADIR.DATADIR_SET));
 }
Exemplo n.º 18
0
 public void SetData(FORMATETC format, SafeGlobalAllocHandle data)
 {
     this.entries.Add(new DataCacheEntry(format, data, DATADIR.DATADIR_SET));
 }
Exemplo n.º 19
0
 internal static extern IntPtr GlobalLock(SafeGlobalAllocHandle h);