상속: 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);
        }
예제 #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;
        }
예제 #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);
예제 #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;
 }
예제 #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);
예제 #14
0
 internal static extern UIntPtr GlobalSize(SafeGlobalAllocHandle h);
예제 #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;
        }
예제 #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;
        }
예제 #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);