Microsoft.VisualStudio.Project.DragDropHelper.CopyHGlobal C# (CSharp) Method

CopyHGlobal() public static method

public static CopyHGlobal ( SafeGlobalAllocHandle data ) : SafeGlobalAllocHandle
data SafeGlobalAllocHandle
return SafeGlobalAllocHandle
        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;
        }

Usage Example

Esempio n. 1
0
        void IDataObject.GetData(FORMATETC[] fmt, STGMEDIUM[] m)
        {
            STGMEDIUM retMedium = new STGMEDIUM();

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

            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.
                    retMedium.unionmember = DragDropHelper.CopyHGlobal(new IntPtr(e.Data));
                    break;
                }
            }

            if (m != null && m.Length > 0)
            {
                m[0] = retMedium;
            }
        }
All Usage Examples Of Microsoft.VisualStudio.Project.DragDropHelper::CopyHGlobal