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); }
/// <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); }