Пример #1
0
        public OleDataObject(OleDataObjectItem[] selectedItems)
        {
            m_SelectedItems = selectedItems;

            SetData(NativeMethods.CFSTR_FILEDESCRIPTORW, null);
            SetData(NativeMethods.CFSTR_FILECONTENTS, null);
            SetData(NativeMethods.CFSTR_PERFORMEDDROPEFFECT, null);
        }
Пример #2
0
        private MemoryStream GetFileDescriptor(OleDataObjectItem[] SelectedItems)
        {
            MemoryStream FileDescriptorMemoryStream = new MemoryStream();
            // Write out the FILEGROUPDESCRIPTOR.cItems value
            FileDescriptorMemoryStream.Write(BitConverter.GetBytes(SelectedItems.Length), 0, sizeof(UInt32));

            Win32.NativeMethods.FILEDESCRIPTORW FileDescriptor = new Win32.NativeMethods.FILEDESCRIPTORW();
            foreach (OleDataObjectItem si in SelectedItems)
            {
                FileDescriptor.cFileName = si.FileName;
                Int64 FileWriteTimeUtc = si.WriteTime.ToFileTimeUtc();
                FileDescriptor.ftLastWriteTime.dwHighDateTime = (Int32)(FileWriteTimeUtc >> 32);
                FileDescriptor.ftLastWriteTime.dwLowDateTime = (Int32)(FileWriteTimeUtc & 0xFFFFFFFF);
                FileDescriptor.nFileSizeHigh = (UInt32)(si.FileSize >> 32);
                FileDescriptor.nFileSizeLow = (UInt32)(si.FileSize & 0xFFFFFFFF);
                FileDescriptor.dwFlags = Win32.NativeMethods.FD_WRITESTIME | Win32.NativeMethods.FD_FILESIZE | Win32.NativeMethods.FD_PROGRESSUI;

                // Marshal the FileDescriptor structure into a byte array and write it to the MemoryStream.
                Int32 FileDescriptorSize = Marshal.SizeOf(FileDescriptor);
                IntPtr FileDescriptorPointer = Marshal.AllocHGlobal(FileDescriptorSize);
                Marshal.StructureToPtr(FileDescriptor, FileDescriptorPointer, true);
                Byte[] FileDescriptorByteArray = new Byte[FileDescriptorSize];
                Marshal.Copy(FileDescriptorPointer, FileDescriptorByteArray, 0, FileDescriptorSize);
                Marshal.FreeHGlobal(FileDescriptorPointer);
                FileDescriptorMemoryStream.Write(FileDescriptorByteArray, 0, FileDescriptorByteArray.Length);
            }
            return FileDescriptorMemoryStream;
        }
Пример #3
0
 private MemoryStream GetFileContents(OleDataObjectItem[] SelectedItems, Int32 FileNumber)
 {
     if (SelectedItems != null && FileNumber < SelectedItems.Length)
     {
         return SelectedItems[FileNumber].MemoryStream;
     }
     else
     {
         return null;
     }
 }