예제 #1
0
파일: Win32DnD.cs 프로젝트: nlhepler/mono
			internal uint SetData(FORMATETC pformatetc, STGMEDIUM pmedium, bool release) {
				return E_NOTIMPL;
			}
 int IVsSimpleObjectList2.GetClipboardFormat(uint index, uint grfFlags, FORMATETC[] pFormatetc, STGMEDIUM[] pMedium)
 {
     return VSConstants.E_NOTIMPL;
 }
        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;
        }
예제 #4
0
 /// <summary>
 /// Handles DataChanged events from a COM IDataObject.
 /// </summary>
 /// <param name="format">The data format that had a change.</param>
 /// <param name="stgmedium">The data value.</param>
 public void OnDataChange(ref FORMATETC format, ref STGMEDIUM stgmedium)
 {
     // We listen to DropDescription changes, so that we can unset the IsDefault
     // drop description flag.
     object odd =
         ComDataObjectExtensions.GetDropDescription((Runtime.InteropServices.ComTypes.IDataObject) data);
     if (odd != null)
         SetDropDescriptionIsDefault(data, false);
 }
예제 #5
0
 private static extern int CopyStgMedium(ref STGMEDIUM pcstgmedSrc, ref STGMEDIUM pstgmedDest);
예제 #6
0
 public void GetDataHere(ref FORMATETC format, ref STGMEDIUM medium)
 {
     throw new NotSupportedException();
 }
예제 #7
0
 public static extern void ReleaseStgMedium(ref STGMEDIUM pmedium);
예제 #8
0
 /// <summary>
 /// Asks the given list item to renders a specific clipboard format that it supports.
 /// </summary>
 /// <param name="index"></param>
 /// <param name="grfFlags"></param>
 /// <param name="pFormatetc"></param>
 /// <param name="pMedium"></param>
 /// <returns></returns>
 public int GetClipboardFormat(uint index, uint grfFlags, FORMATETC[] pFormatetc, STGMEDIUM[] pMedium)
 {
     return VSConstants.E_NOTIMPL;
 }
예제 #9
0
 public OleDataEntry(FORMATETC fmt, STGMEDIUM stg)
 {
     format = fmt;
     stgm   = stg;
 }
        public uint GetDataHere(ref FORMATETC pFormatetc, out STGMEDIUM pMedium)
        {
            Trace.WriteLine("GetDataHere");

            pMedium = new STGMEDIUM();

            return (uint)E_NOTIMPL;
        }
        public uint SetData(ref FORMATETC a, ref STGMEDIUM b, bool fRelease)
        {
            //mpFormatetc = pFormatectIn;
            //mpmedium = pmedium;

            Trace.WriteLine("SetData");

            return (int)S_OK;
        }
        public uint GetData(ref FORMATETC pFormatetc, ref STGMEDIUM pMedium)
        {
            IntPtr hDst = mBitmap.GetHbitmap();

            pMedium.tymed = (int)TYMED.TYMED_GDI;
            pMedium.unionmember = hDst;
            pMedium.pUnkForRelease = IntPtr.Zero;

            return (uint)S_OK;
        }
예제 #13
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)
                {
                    retMedium.tymed = e.format.tymed;
                    retMedium.unionmember = CopyHGlobal(new IntPtr(e.data));
                    break;
                }
            }

            if (m != null && m.Length > 0)
                m[0] = retMedium;
        }
예제 #14
0
파일: Win32DnD.cs 프로젝트: nlhepler/mono
		private static bool AddFormatAndMedium(ClipboardFormats cfFormat, object data) {
			STGMEDIUM	medium;
			FORMATETC	format;
			IntPtr		hmem;
			IntPtr		hmem_ptr;
			byte[]		b;

			switch(cfFormat) {
				case ClipboardFormats.CF_TEXT: {
					b = XplatUIWin32.StringToAnsi ((string)data);
					hmem = XplatUIWin32.CopyToMoveableMemory (b);
					break;
				}

				case ClipboardFormats.CF_UNICODETEXT: {
					b = XplatUIWin32.StringToUnicode ((string)data);
					hmem = XplatUIWin32.CopyToMoveableMemory (b);
					break;
				}

				case ClipboardFormats.CF_HDROP: {
					IEnumerator	e;
					StringBuilder	sb;
					long		hmem_string_ptr;
					IntPtr		string_buffer;
					int		string_buffer_size;

					sb = new StringBuilder();

					// Make sure object is enumerable; otherwise
					if ((data is string) || !(data is IEnumerable)) {
						sb.Append(data.ToString());
						sb.Append('\0');
						sb.Append('\0');
					} else {
						e = ((IEnumerable)data).GetEnumerator();
						while (e.MoveNext()) {
							sb.Append(e.Current.ToString());
							sb.Append('\0');
						}
						sb.Append('\0');
					}

					string_buffer = Marshal.StringToHGlobalUni(sb.ToString());
					string_buffer_size = (int)XplatUIWin32.Win32GlobalSize(string_buffer);

					// Write DROPFILES structure
					hmem = XplatUIWin32.Win32GlobalAlloc(XplatUIWin32.GAllocFlags.GMEM_MOVEABLE | XplatUIWin32.GAllocFlags.GMEM_DDESHARE, 0x14 + string_buffer_size);
					hmem_ptr = XplatUIWin32.Win32GlobalLock(hmem);
					Marshal.WriteInt32(hmem_ptr, 0x14);					// pFiles
					Marshal.WriteInt32(hmem_ptr, 1 * Marshal.SizeOf(typeof(uint)), 0);	// point.x
					Marshal.WriteInt32(hmem_ptr, 2 * Marshal.SizeOf(typeof(uint)), 0);	// point.y
					Marshal.WriteInt32(hmem_ptr, 3 * Marshal.SizeOf(typeof(uint)), 0);	// fNc
					Marshal.WriteInt32(hmem_ptr, 4 * Marshal.SizeOf(typeof(uint)), 1);	// fWide

					hmem_string_ptr = (long)hmem_ptr;
					hmem_string_ptr += 0x14;

					XplatUIWin32.Win32CopyMemory(new IntPtr(hmem_string_ptr), string_buffer, string_buffer_size);
					Marshal.FreeHGlobal(string_buffer);
					XplatUIWin32.Win32GlobalUnlock(hmem_ptr);

					break;
				}

				case ClipboardFormats.CF_DIB: {
					b = XplatUIWin32.ImageToDIB((Image)data);
					hmem = XplatUIWin32.CopyToMoveableMemory (b);
					break;
				}

				default: {
					hmem = IntPtr.Zero;
					break;
				}
			}

			if (hmem != IntPtr.Zero) {
				medium = new STGMEDIUM();
				medium.tymed = TYMED.TYMED_HGLOBAL;
				medium.hHandle = hmem;
				medium.pUnkForRelease = IntPtr.Zero;
				DragMediums.Add(medium);

				format = new FORMATETC();
				format.ptd = IntPtr.Zero;
				format.dwAspect = DVASPECT.DVASPECT_CONTENT;
				format.lindex = -1;
				format.tymed = TYMED.TYMED_HGLOBAL;
				format.cfFormat = cfFormat;
				DragFormats.Add(format);

				return true;
			}

			return false;
		}
예제 #15
0
 /// <summary>
 /// Provides data to the client as it becomes available during asynchronous bind operations.
 /// </summary>
 void IBindStatusCallback.OnDataAvailable(BSCF grfBSCF, uint dwSize, ref FORMATETC pformatetc, ref STGMEDIUM pstgmed)
 {
     // never called by URLDownloadToFile
     LOG_UN("IBindStatusCallback", "OnDataAvailable");
 }
예제 #16
0
        internal static string[] GetFilenamesAnsi(NativeMethods.IDataObject data)
        {
            log.Debug("Getting filenames (ANSI)");
            IntPtr    ptrFgd = IntPtr.Zero;
            STGMEDIUM medium = new STGMEDIUM();

            try
            {
                //Define FileGroupDescriptor format
                FORMATETC format = new FORMATETC();
                format.cfFormat = (short)GetClipboardFormat("FileGroupDescriptor");
                format.dwAspect = DVASPECT.DVASPECT_CONTENT;
                format.lindex   = -1;
                format.ptd      = IntPtr.Zero;
                format.tymed    = TYMED.TYMED_ISTREAM | TYMED.TYMED_ISTORAGE | TYMED.TYMED_HGLOBAL;

                //Query if format exists in data
                if (data.QueryGetData(format) != NativeMethods.S_OK)
                {
                    log.Debug("No filenames found");
                    return(null);
                }

                //Get data into medium
                int retVal = data.GetData(format, out medium);
                if (retVal != NativeMethods.S_OK)
                {
                    throw new Exception(string.Format("Could not get FileGroupDescriptor format.  Error returned: {0}", retVal));
                }

                //Read medium into byte array
                log.Debug("Reading structure into memory stream");
                byte[] bytes;
                using (MemoryStream stream = new MemoryStream())
                {
                    DataObjectHelper.ReadMediumIntoStream(medium, stream);
                    bytes = new byte[stream.Length];
                    stream.Seek(0, SeekOrigin.Begin);
                    stream.Read(bytes, 0, bytes.Length);
                }

                //Copy byte array into unmanaged memory
                log.Debug("Copying structure into unmanaged memory");
                ptrFgd = Marshal.AllocHGlobal(bytes.Length);
                Marshal.Copy(bytes, 0, ptrFgd, bytes.Length);

                //Marshal unmanaged memory to a FILEGROUPDESCRIPTORA struct
                log.Debug("Marshaling unmanaged memory into FILEGROUPDESCRIPTORA struct");
                NativeMethods.FILEGROUPDESCRIPTORA fgd = (NativeMethods.FILEGROUPDESCRIPTORA)Marshal.PtrToStructure(ptrFgd, typeof(NativeMethods.FILEGROUPDESCRIPTORA));
                log.Debug(string.Format("Files found: {0}", fgd.cItems));

                //Create an array to store file names
                string[] filenames = new string[fgd.cItems];

                //Get the pointer to the first file descriptor
                IntPtr fdPtr = IntPtr.Add(ptrFgd, sizeof(uint));

                //Loop for the number of files acording to the file group descriptor
                for (int fdIndex = 0; fdIndex < fgd.cItems; fdIndex++)
                {
                    log.DebugFormat("Filenames found: {0}", string.Join(", ", filenames));

                    //Marshal pointer to a FILEDESCRIPTORA struct
                    NativeMethods.FILEDESCRIPTORA fd = (NativeMethods.FILEDESCRIPTORA)Marshal.PtrToStructure(fdPtr, typeof(NativeMethods.FILEDESCRIPTORA));

                    //Get filename of file descriptor and put in array
                    filenames[fdIndex] = fd.cFileName;

                    //Move the file descriptor pointer to the next file descriptor
                    fdPtr = IntPtr.Add(fdPtr, Marshal.SizeOf(fd));
                }

                log.DebugFormat("Filenames found: {0}", string.Join(", ", filenames));

                return(filenames);
            }
            finally
            {
                //Release all unmanaged objects
                Marshal.FreeHGlobal(ptrFgd);
                if (medium.pUnkForRelease == null)
                {
                    NativeMethods.ReleaseStgMedium(ref medium);
                }
            }
        }
        void IDataObject.GetData(ref FORMATETC format, out STGMEDIUM medium)
        {
            medium = new STGMEDIUM();
            var hr = ((IDataObject)this).QueryGetData(ref format);

            if (NativeMethods.SUCCEEDED(hr))
            {
                // Find the best match
                var formatCopy = format;
                // Cannot use ref or out parameter inside an anonymous method, lambda expression, or query expression
                DataObject dataObject = null;
                foreach (DataObject d in _dataObjects)
                {
                    if ((d.FORMATETC.cfFormat == formatCopy.cfFormat) && (d.FORMATETC.dwAspect == formatCopy.dwAspect) &&
                        (0 != (d.FORMATETC.tymed & formatCopy.tymed) && (d.FORMATETC.lindex == formatCopy.lindex)))
                    {
                        dataObject = d;
                        break;
                    }
                }

                /*
                 * var dataObject = _dataObjects
                 *  .Where(d =>
                 *      (d.FORMATETC.cfFormat == formatCopy.cfFormat) &&
                 *      (d.FORMATETC.dwAspect == formatCopy.dwAspect) &&
                 *      (0 != (d.FORMATETC.tymed & formatCopy.tymed) &&
                 *      (d.FORMATETC.lindex == formatCopy.lindex)))
                 *  .FirstOrDefault();*/
                if (dataObject != null)
                {
                    if (!IsAsynchronous && (FILEDESCRIPTORW == dataObject.FORMATETC.cfFormat) && !_inOperation)
                    {
                        // Enter the operation and call the start action
                        _inOperation = true;
                        if (null != _startAction)
                        {
                            _startAction(this);
                        }
                    }

                    // Populate the STGMEDIUM
                    medium.tymed = dataObject.FORMATETC.tymed;
                    var result = dataObject.GetData(); // Possible call to user code
                    hr = result.Item2;
                    if (NativeMethods.SUCCEEDED(hr))
                    {
                        medium.unionmember = result.Item1;
                    }
                }
                else
                {
                    // Couldn't find a match
                    hr = NativeMethods.DV_E_FORMATETC;
                }
            }
            if (!NativeMethods.SUCCEEDED(hr)) // Not redundant; hr gets updated in the block above
            {
                Marshal.ThrowExceptionForHR(hr);
            }
        }
        /// <summary>
        /// 初始化上下文菜单处理程序
        /// </summary>
        /// <param name="pidlFolder">
        /// 指向标识文件夹的 ITEMIDLIST 结构的指针.
        /// </param>
        /// <param name="pDataObj">
        /// 一个指向 IDataObject 接口对象的指针可以用来检索对象.
        /// </param>
        /// <param name="hKeyProgID">
        /// 对象或文件夹的文件类型的注册表项.
        /// </param>
        public void Initialize(IntPtr pidlFolder, IntPtr pDataObj, IntPtr hKeyProgID)
        {
            if (pDataObj == IntPtr.Zero)
            {
                throw new ArgumentException();
            }

            selectedFiles.Clear();

            FORMATETC fe = new FORMATETC();

            fe.cfFormat = (short)CLIPFORMAT.CF_HDROP;
            fe.ptd      = IntPtr.Zero;
            fe.dwAspect = DVASPECT.DVASPECT_CONTENT;
            fe.lindex   = -1;
            fe.tymed    = TYMED.TYMED_HGLOBAL;
            STGMEDIUM stm = new STGMEDIUM();

            // pDataObj 指针指向对象. 在这示例,我们得到一个HDROP的句柄的枚举在选定的文件和文件夹

            IDataObject dataObject = (IDataObject)Marshal.GetObjectForIUnknown(pDataObj);

            dataObject.GetData(ref fe, out stm);

            try
            {
                // 取到HDROP句柄
                IntPtr hDrop = stm.unionmember;
                if (hDrop == IntPtr.Zero)
                {
                    throw new ArgumentException();
                }

                //确定在此操作中涉及多少个文件.
                uint nFiles = NativeMethods.DragQueryFile(hDrop, UInt32.MaxValue, null, 0);

                //只有一个文件被选中时,示例代码将显示自定义上下文菜单项中.
                //if (nFiles == 1)
                //{
                //    //获取文件名.
                //    StringBuilder fileName = new StringBuilder(260);
                //    if (0 == NativeMethods.DragQueryFile(hDrop, 0, fileName,
                //        fileName.Capacity))
                //    {
                //        Marshal.ThrowExceptionForHR(WinError.E_FAIL);
                //    }
                //    this.selectedFile = fileName.ToString();
                //    selectedFiles.Add(this.selectedFile);
                //}
                //else
                //{
                //    Marshal.ThrowExceptionForHR(WinError.E_FAIL);
                //}

                // [-或者-]

                //  枚举被选中的文件和文件夹.
                if (nFiles > 0)
                {
                    StringBuilder fileName = new StringBuilder(260);
                    for (uint i = 0; i < nFiles; i++)
                    {
                        // Get the next file name.
                        if (0 != NativeMethods.DragQueryFile(hDrop, i, fileName,
                                                             fileName.Capacity))
                        {
                            // Add the file name to the list.
                            selectedFiles.Add(fileName.ToString());
                        }
                    }

                    // If we did not find any files we can work with, throw
                    // exception.
                    if (selectedFiles.Count == 0)
                    {
                        Marshal.ThrowExceptionForHR(WinError.E_FAIL);
                    }
                }
                else
                {
                    Marshal.ThrowExceptionForHR(WinError.E_FAIL);
                }
            }
            finally
            {
                NativeMethods.ReleaseStgMedium(ref stm);
            }
        }
예제 #19
0
 private static extern void ReleaseStgMedium(ref STGMEDIUM pmedium);
예제 #20
0
 void System.Runtime.InteropServices.ComTypes.IDataObject.SetData(ref FORMATETC format, ref STGMEDIUM medium, bool release)
 {
 }
예제 #21
0
 internal static extern void ReleaseStgMedium(ref STGMEDIUM medium);
예제 #22
0
        void System.Runtime.InteropServices.ComTypes.IDataObject.GetData(ref System.Runtime.InteropServices.ComTypes.FORMATETC formatetc, out System.Runtime.InteropServices.ComTypes.STGMEDIUM medium)
        {
            try
            {
                medium = new System.Runtime.InteropServices.ComTypes.STGMEDIUM();

                if (formatetc.cfFormat == (Int16)DataFormats.GetFormat(NativeMethods.CFSTR_FILECONTENTS).Id)
                {
                    m_lindex = formatetc.lindex;
                }

                if (GetTymedUseable(formatetc.tymed))
                {
                    if ((formatetc.tymed & TYMED.TYMED_ISTREAM) != TYMED.TYMED_NULL)
                    {
                        if (objectType != ClipboardDataType.File)
                        {
                            return;
                        }

                        try
                        {
                            //DropSuccess?.Invoke(this, null);
                            medium.tymed = TYMED.TYMED_ISTREAM;
                            IStream o = (IStream)GetData("FileContents", false);
                            medium.unionmember = Marshal.GetComInterfaceForObject(o, typeof(IStream));
                            return;
                        }
                        catch (Exception ex)
                        {
                            //ISLogger.Write("InputshareDataObject: Get FileContents failed: " + ex.Message);
                            return;
                        }
                    }
                    else if ((formatetc.tymed & TYMED.TYMED_HGLOBAL) != TYMED.TYMED_NULL)
                    {
                        medium.tymed       = TYMED.TYMED_HGLOBAL;
                        medium.unionmember = NativeMethods.GlobalAlloc(NativeMethods.GHND | NativeMethods.GMEM_DDESHARE, 1);
                        if (medium.unionmember == IntPtr.Zero)
                        {
                            throw new OutOfMemoryException();
                        }
                        try
                        {
                            ((System.Runtime.InteropServices.ComTypes.IDataObject) this).GetDataHere(ref formatetc, ref medium);
                            return;
                        }
                        catch
                        {
                            NativeMethods.GlobalFree(new HandleRef((STGMEDIUM)medium, medium.unionmember));
                            medium.unionmember = IntPtr.Zero;
                            return;
                        }
                    }
                    medium.tymed = formatetc.tymed;
                    ((System.Runtime.InteropServices.ComTypes.IDataObject) this).GetDataHere(ref formatetc, ref medium);
                }
                else
                {
                    Marshal.ThrowExceptionForHR(NativeMethods.DV_E_TYMED);
                }
            }catch (Exception ex)
            {
                medium = new STGMEDIUM();
                ISLogger.Write("InputshareDataObject: " + ex.Message);
            }
        }
예제 #23
0
        /// <summary>
        /// Gets the specified data.
        /// </summary>
        /// <param name="format">The requested data format.</param>
        /// <param name="medium">When the function returns, contains the requested data.</param>
        /// <remarks>Differs from GetData only in that the STGMEDIUM storage is
        /// allocated and owned by the caller.</remarks>
        public void GetDataHere(ref FORMATETC format, ref STGMEDIUM medium)
        {
            // Locate the data
            KeyValuePair<FORMATETC, STGMEDIUM> dataEntry;
            if (GetDataEntry(ref format, out dataEntry))
            {
                STGMEDIUM source = dataEntry.Value;
                medium = CopyMedium(ref source);
                return;
            }

            // Didn't find it. Return an empty data medium.
            medium = default(STGMEDIUM);
        }
예제 #24
0
        override public bool GetMTEF()
        {
            bool bReturn = false;

            if (!sdk.Init())
            {
                return(bReturn);
            }

            IDataObject dataObject = MathTypeSDK.getIDataObject();

            if (dataObject == null)
            {
                sdk.DeInit();
                return(bReturn);
            }

            FORMATETC formatEtc = new FORMATETC();
            STGMEDIUM stgMedium = new STGMEDIUM();

            try
            {
                // Setup the formatting information to use for the conversion.
                formatEtc.cfFormat = (Int16)DataFormats.GetFormat(strInTrans).Id;
                formatEtc.dwAspect = DVASPECT.DVASPECT_CONTENT;
                formatEtc.lindex   = -1;
                formatEtc.ptd      = (IntPtr)0;
                formatEtc.tymed    = TYMED.TYMED_HGLOBAL;

                // Setup the MathML content to convert
                stgMedium.unionmember    = Marshal.StringToHGlobalAuto(strEquation);
                stgMedium.tymed          = TYMED.TYMED_HGLOBAL;
                stgMedium.pUnkForRelease = 0;

                // Perform the conversion
                dataObject.SetData(ref formatEtc, ref stgMedium, false);

                // Set the format for the output
                formatEtc.cfFormat = (Int16)DataFormats.GetFormat("MathType EF").Id;
                formatEtc.dwAspect = DVASPECT.DVASPECT_CONTENT;
                formatEtc.lindex   = -1;
                formatEtc.ptd      = (IntPtr)0;
                formatEtc.tymed    = TYMED.TYMED_ISTORAGE;

                // Create a blank data structure to hold the converted result.
                stgMedium                = new STGMEDIUM();
                stgMedium.tymed          = TYMED.TYMED_NULL;
                stgMedium.pUnkForRelease = 0;

                // Get the conversion result in MTEF format
                dataObject.GetData(ref formatEtc, out stgMedium);
            }
            catch (COMException e)
            {
                Console.WriteLine("MathML conversion to MathType threw an exception: " + Environment.NewLine + e.ToString());
                sdk.DeInit();
                return(bReturn);
            }

            // The pointer now becomes a Handle reference.
            HandleRef handleRef = new HandleRef(null, stgMedium.unionmember);

            try
            {
                // Lock in the handle to get the pointer to the data
                IntPtr ptrToHandle = MathTypeSDK.GlobalLock(handleRef);

                // Get the size of the memory block
                m_iMTEF_Length = MathTypeSDK.GlobalSize(handleRef);

                // New an array of bytes and Marshal the data across.
                m_bMTEF = new byte[m_iMTEF_Length];
                Marshal.Copy(ptrToHandle, m_bMTEF, 0, m_iMTEF_Length);
                m_strMTEF = System.Text.ASCIIEncoding.ASCII.GetString(m_bMTEF);
                bReturn   = true;
            }
            catch (Exception e)
            {
                Console.WriteLine("Generation of image from MathType failed: " + Environment.NewLine + e.ToString());
            }
            finally
            {
                MathTypeSDK.GlobalUnlock(handleRef);
            }

            sdk.DeInit();
            return(bReturn);
        }
예제 #25
0
        /// <summary>
        /// Creates a copy of the STGMEDIUM structure.
        /// </summary>
        /// <param name="medium">The data to copy.</param>
        /// <returns>The copied data.</returns>
        private STGMEDIUM CopyMedium(ref STGMEDIUM medium)
        {
            STGMEDIUM sm = new STGMEDIUM();
            int hr = CopyStgMedium(ref medium, ref sm);
            if (hr != 0)
                throw Marshal.GetExceptionForHR(hr);

            return sm;
        }
예제 #26
0
        void IDataObject.GetData(FORMATETC[] fmt, STGMEDIUM[] m) {
            STGMEDIUM retMedium = new STGMEDIUM();

            foreach (DataCacheEntry e in this.entries) {
                if (e.format.cfFormat == fmt[0].cfFormat) {
                    retMedium.tymed = e.format.tymed;
                    retMedium.unionmember = CopyHGlobal(e.data);
                    break;
                }
            }

            m[0] = retMedium;
        }
예제 #27
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();
            }
        }
예제 #28
0
 void IDataObject.GetDataHere(FORMATETC[] fmt, STGMEDIUM[] m) {
     throw new NotImplementedException();
 }
 void IDataObject.SetData(FORMATETC[] fmt, STGMEDIUM[] m, int fRelease) {
 }
예제 #30
0
 void IDataObject.SetData(FORMATETC[] fmt, STGMEDIUM[] m, int fRelease) {
     throw new NotImplementedException();
 }
예제 #31
0
        internal static void GetSelectedItems(IntPtr pidlFolder, IntPtr pDataObj, IntPtr hKeyProgID, ref List <String> SelectedItems, ref bool isClickOnEmptyArea)
        {
            if (pDataObj == IntPtr.Zero && pidlFolder == IntPtr.Zero)
            {
                throw new ArgumentException();
            }
            else if (pDataObj == IntPtr.Zero)
            {
                //User Click on Empty Area of a Folder, pDataObj is empty while pidlFolder is the current path
                StringBuilder sb = new StringBuilder(260);
                if (!NativeMethods.SHGetPathFromIDListW(pidlFolder, sb))
                {
                    Marshal.ThrowExceptionForHR(WinError.E_FAIL);
                }
                else
                {
                    isClickOnEmptyArea = true;
                    SelectedItems      = new List <string>();
                    SelectedItems.Add(sb.ToString());
                }
            }
            else
            {
                //User actually select some item, pDataObj is the list while pidlFolder is empty
                isClickOnEmptyArea = false;

                FORMATETC fe = new FORMATETC();
                fe.cfFormat = (short)CLIPFORMAT.CF_HDROP;
                fe.ptd      = IntPtr.Zero;
                fe.dwAspect = DVASPECT.DVASPECT_CONTENT;
                fe.lindex   = -1;
                fe.tymed    = TYMED.TYMED_HGLOBAL;
                STGMEDIUM stm = new STGMEDIUM();

                IDataObject dataObject = (IDataObject)Marshal.GetObjectForIUnknown(pDataObj);
                dataObject.GetData(ref fe, out stm);

                try
                {
                    IntPtr hDrop = stm.unionmember;
                    if (hDrop == IntPtr.Zero)
                    {
                        throw new ArgumentException();
                    }

                    uint nFiles = NativeMethods.DragQueryFile(hDrop, UInt32.MaxValue, null, 0);

                    if (nFiles == 0)
                    {
                        Marshal.ThrowExceptionForHR(WinError.E_FAIL);
                    }

                    SelectedItems = new List <string>();

                    for (int i = 0; i < nFiles; i++)
                    {
                        StringBuilder sb = new StringBuilder(260);
                        if (NativeMethods.DragQueryFile(hDrop, (uint)i, sb, sb.Capacity) == 0)
                        {
                            Marshal.ThrowExceptionForHR(WinError.E_FAIL);
                        }
                        else
                        {
                            SelectedItems.Add(sb.ToString());
                        }
                    }
                }
                finally
                {
                    NativeMethods.ReleaseStgMedium(ref stm);
                }
            }
        }
예제 #32
0
        void CopyStgMedium(IntPtr cfFormat, ref STGMEDIUM lpDest, ref STGMEDIUM lpSource) {
            /* STGMEDIUM appears to be messed up...
      if (lpDest.tymed == TYMED_NULL) {
        Debug.Assert(lpSource.tymed != TYMED_NULL);
        switch (lpSource.tymed) {
          case TYMED_ENHMF:
          case TYMED_HGLOBAL:
            lpDest.tymed = lpSource.tymed;
            lpDest.hGlobal = NULL;
            break;  

          case TYMED_ISTREAM:
            lpDest.pstm = lpSource.pstm;
            lpDest.pstm.AddRef();
            lpDest.tymed = TYMED_ISTREAM;
            return TRUE;

          case TYMED_ISTORAGE:
            lpDest.pstg = lpSource.pstg;
            lpDest.pstg.AddRef();
            lpDest.tymed = TYMED_ISTORAGE;
            return TRUE;

          case TYMED_MFPICT: {
            // copy LPMETAFILEPICT struct + embedded HMETAFILE
            HGLOBAL hDest = ::CopyGlobalMemory(NULL, lpSource.hGlobal);
            if (hDest == NULL)
              return FALSE;
            LPMETAFILEPICT lpPict = (LPMETAFILEPICT)::GlobalLock(hDest);
            ASSERT(lpPict != NULL);
            lpPict.hMF = ::CopyMetaFile(lpPict.hMF, NULL);
            if (lpPict.hMF == NULL) {
              ::GlobalUnlock(hDest);
              ::GlobalFree(hDest);
              return FALSE;
            }
            ::GlobalUnlock(hDest);

            // fill STGMEDIUM struct
            lpDest.hGlobal = hDest;
            lpDest.tymed = TYMED_MFPICT;
          }
            return TRUE;

          case TYMED_GDI:
            lpDest.tymed = TYMED_GDI;
            lpDest.hGlobal = NULL;
            break;

          case TYMED_FILE: {
            USES_CONVERSION;
            lpDest.tymed = TYMED_FILE;
            ASSERT(lpSource.lpszFileName != NULL);
            UINT cbSrc = (int)ocslen(lpSource.lpszFileName);
            LPOLESTR szFileName = (LPOLESTR)CoTaskMemAlloc(cbSrc*sizeof(OLECHAR));
            lpDest.lpszFileName = szFileName;
            if (szFileName == NULL)
              return FALSE;
            memcpy(szFileName, lpSource.lpszFileName,  (cbSrc+1)*sizeof(OLECHAR));
            return TRUE;
          }

            // unable to create + copy other TYMEDs
          default:
            return FALSE;
        }
      }
      ASSERT(lpDest.tymed == lpSource.tymed);

      switch (lpSource.tymed) {
        case TYMED_HGLOBAL: {
          HGLOBAL hDest = ::CopyGlobalMemory(lpDest.hGlobal,
                              lpSource.hGlobal);
          if (hDest == NULL)
            return FALSE;

          lpDest.hGlobal = hDest;
        }
          return TRUE;

        case TYMED_ISTREAM: {
          ASSERT(lpDest.pstm != NULL);
          ASSERT(lpSource.pstm != NULL);

          // get the size of the source stream
          STATSTG stat;
          if (lpSource.pstm.Stat(&stat, STATFLAG_NONAME) != S_OK) {
            // unable to get size of source stream
            return FALSE;
          }
          ASSERT(stat.pwcsName == NULL);

          // always seek to zero before copy
          LARGE_INTEGER zero = { 0, 0 };
          lpDest.pstm.Seek(zero, STREAM_SEEK_SET, NULL);
          lpSource.pstm.Seek(zero, STREAM_SEEK_SET, NULL);

          // copy source to destination
          if (lpSource.pstm.CopyTo(lpDest.pstm, stat.cbSize,
            NULL, NULL) != NULL) {
            // copy from source to dest failed
            return FALSE;
          }

          // always seek to zero after copy
          lpDest.pstm.Seek(zero, STREAM_SEEK_SET, NULL);
          lpSource.pstm.Seek(zero, STREAM_SEEK_SET, NULL);
        }
          return TRUE;

        case TYMED_ISTORAGE: {
          ASSERT(lpDest.pstg != NULL);
          ASSERT(lpSource.pstg != NULL);

          // just copy source to destination
          if (lpSource.pstg.CopyTo(0, NULL, NULL, lpDest.pstg) != S_OK)
            return FALSE;
        }
          return TRUE;

        case TYMED_FILE: {
          USES_CONVERSION;
          ASSERT(lpSource.lpszFileName != NULL);
          ASSERT(lpDest.lpszFileName != NULL);
          return CopyFile(OLE2T(lpSource.lpszFileName), OLE2T(lpDest.lpszFileName), FALSE);
        }


        case TYMED_ENHMF:
        case TYMED_GDI: {
          ASSERT(sizeof(HGLOBAL) == sizeof(HENHMETAFILE));

          // with TYMED_GDI cannot copy into existing HANDLE
          if (lpDest.hGlobal != NULL)
            return FALSE;

          // otherwise, use OleDuplicateData for the copy
          lpDest.hGlobal = OleDuplicateData(lpSource.hGlobal, cfFormat, 0);
          if (lpDest.hGlobal == NULL)
            return FALSE;
        }
          return TRUE;

          // other TYMEDs cannot be copied
        default:
          return FALSE;
      }
      */
        }
예제 #33
0
 /// <summary>
 /// Gets the specified data.
 /// </summary>
 /// <param name="format">The requested data format.</param>
 /// <param name="medium">When the function returns, contains the requested data.</param>
 public void GetData(ref FORMATETC format, out STGMEDIUM medium)
 {
     medium = new STGMEDIUM();
     GetDataHere(ref format, ref medium);
 }
예제 #34
0
        void System.Runtime.InteropServices.ComTypes.IDataObject.GetData(ref FORMATETC format, out STGMEDIUM medium)
        {
            medium = new STGMEDIUM();
            var hr = ((System.Runtime.InteropServices.ComTypes.IDataObject) this).QueryGetData(ref format);

            if (NativeMethods.SUCCEEDED(hr))
            {
                // Find the best match
                var formatCopy = format; // Cannot use ref or out parameter inside an anonymous method, lambda expression, or query expression
                var dataObject = _dataObjects
                                 .Where(d =>
                                        (d.FORMATETC.cfFormat == formatCopy.cfFormat) &&
                                        (d.FORMATETC.dwAspect == formatCopy.dwAspect) &&
                                        (0 != (d.FORMATETC.tymed & formatCopy.tymed) &&
                                         (d.FORMATETC.lindex == formatCopy.lindex)))
                                 .FirstOrDefault();
                if (dataObject != null)
                {
                    if (!IsAsynchronous && (FILEDESCRIPTORW == dataObject.FORMATETC.cfFormat) && !_inOperation)
                    {
                        // Enter the operation and call the start action
                        _inOperation = true;
                        if (null != _startAction)
                        {
                            _startAction(this);
                        }
                    }

                    // Populate the STGMEDIUM
                    medium.tymed = dataObject.FORMATETC.tymed;
                    var result = dataObject.GetData(); // Possible call to user code
                    hr = result.Item2;
                    if (NativeMethods.SUCCEEDED(hr))
                    {
                        medium.unionmember = result.Item1;
                    }
                }
                else
                {
                    // Couldn't find a match
                    hr = NativeMethods.DV_E_FORMATETC;
                }
            }
            if (!NativeMethods.SUCCEEDED(hr))    // Not redundant; hr gets updated in the block above
            {
                Marshal.ThrowExceptionForHR(hr); // KFreon: Can fail here with FORMATETC problem when running through debugger. Use Ctrl+F5 to run without debugger.
            }
        }
 /// <summary>
 /// Obtains data from a source data object.
 /// </summary>
 /// <param name="format">A pointer to a FORMATETC structure that defines the format, medium, and target device to use when passing the data.</param>
 /// <param name="medium">A STGMEDIUM that defines the storage medium containing the data being transferred.</param>
 void IDataObject.GetDataHere(ref FORMATETC format, ref STGMEDIUM medium)
 {
     throw new NotImplementedException();
 }
예제 #36
0
 /// <summary>
 /// Obtains data from a source data object.
 /// </summary>
 /// <param name="format">A pointer to a FORMATETC structure that defines the format, medium, and target device to use when passing the data.</param>
 /// <param name="medium">A STGMEDIUM that defines the storage medium containing the data being transferred.</param>
 void System.Runtime.InteropServices.ComTypes.IDataObject.GetDataHere(ref FORMATETC format, ref STGMEDIUM medium)
 {
     throw new NotImplementedException();
 }
예제 #37
0
 private static extern int CopyStgMedium(ref STGMEDIUM pcstgmedSrc, ref STGMEDIUM pstgmedDest);
예제 #38
0
        void System.Runtime.InteropServices.ComTypes.IDataObject.SetData(ref FORMATETC formatIn, ref STGMEDIUM medium, bool release)
        {
            var handled = false;

            if ((formatIn.dwAspect == DVASPECT.DVASPECT_CONTENT) &&
                (formatIn.tymed == TYMED.TYMED_HGLOBAL) &&
                (medium.tymed == formatIn.tymed))
            {
                // Supported format; capture the data
                var ptr = NativeMethods.GlobalLock(medium.unionmember);
                if (IntPtr.Zero != ptr)
                {
                    try
                    {
                        var length = NativeMethods.GlobalSize(ptr).ToInt32();
                        var data   = new byte[length];
                        Marshal.Copy(ptr, data, 0, length);
                        // Store it in our own format
                        SetData(formatIn.cfFormat, data);
                        handled = true;
                    }
                    finally
                    {
                        NativeMethods.GlobalUnlock(medium.unionmember);
                    }
                }

                // Release memory if we now own it
                if (release)
                {
                    Marshal.FreeHGlobal(medium.unionmember);
                }
            }

            // Handle synchronous mode
            if (!IsAsynchronous && (PERFORMEDDROPEFFECT == formatIn.cfFormat) && _inOperation)
            {
                // Call the end action and exit the operation
                if (null != _endAction)
                {
                    _endAction(this);
                }
                _inOperation = false;
            }

            // Throw if unhandled
            if (!handled)
            {
                throw new NotImplementedException();
            }
        }
        /// <summary>
        /// Initialize the context menu handler.
        /// </summary>
        /// <param name="pidlFolder">
        /// A pointer to an ITEMIDLIST structure that uniquely identifies a folder.
        /// </param>
        /// <param name="pDataObj">
        /// A pointer to an IDataObject interface object that can be used to retrieve
        /// the objects being acted upon.
        /// </param>
        /// <param name="hKeyProgID">
        /// The registry key for the file object or folder type.
        /// </param>
        public void Initialize(IntPtr pidlFolder, IntPtr pDataObj, IntPtr hKeyProgID)
        {
            if (pDataObj == IntPtr.Zero)
            {
                throw new ArgumentException();
            }

            FORMATETC fe = new FORMATETC();

            fe.cfFormat = (short)CLIPFORMAT.CF_HDROP;
            fe.ptd      = IntPtr.Zero;
            fe.dwAspect = DVASPECT.DVASPECT_CONTENT;
            fe.lindex   = -1;
            fe.tymed    = TYMED.TYMED_HGLOBAL;
            STGMEDIUM stm = new STGMEDIUM();

            // The pDataObj pointer contains the objects being acted upon. In this
            // example, we get an HDROP handle for enumerating the selected files
            // and folders.
            IDataObject dataObject = (IDataObject)Marshal.GetObjectForIUnknown(pDataObj);

            dataObject.GetData(ref fe, out stm);

            try
            {
                // Get an HDROP handle.
                IntPtr hDrop = stm.unionmember;
                if (hDrop == IntPtr.Zero)
                {
                    throw new ArgumentException();
                }

                // Determine how many files are involved in this operation.
                uint nFiles = NativeMethods.DragQueryFile(hDrop, UInt32.MaxValue, null, 0);

                // This code sample displays the custom context menu item when only
                // one file is selected.
                if (nFiles == 1)
                {
                    // Get the path of the file.
                    StringBuilder fileName = new StringBuilder(260);
                    if (0 == NativeMethods.DragQueryFile(hDrop, 0, fileName,
                                                         fileName.Capacity))
                    {
                        Marshal.ThrowExceptionForHR(WinError.E_FAIL);
                    }
                    this.selectedFile = fileName.ToString();
                }
                else
                {
                    Marshal.ThrowExceptionForHR(WinError.E_FAIL);
                }

                // [-or-]

                // Enumerate the selected files and folders.
                //if (nFiles > 0)
                //{
                //    StringCollection selectedFiles = new StringCollection();
                //    StringBuilder fileName = new StringBuilder(260);
                //    for (uint i = 0; i < nFiles; i++)
                //    {
                //        // Get the next file name.
                //        if (0 != NativeMethods.DragQueryFile(hDrop, i, fileName,
                //            fileName.Capacity))
                //        {
                //            // Add the file name to the list.
                //            selectedFiles.Add(fileName.ToString());
                //        }
                //    }
                //
                //    // If we did not find any files we can work with, throw
                //    // exception.
                //    if (selectedFiles.Count == 0)
                //    {
                //        Marshal.ThrowExceptionForHR(WinError.E_FAIL);
                //    }
                //}
                //else
                //{
                //    Marshal.ThrowExceptionForHR(WinError.E_FAIL);
                //}
            }
            finally
            {
                NativeMethods.ReleaseStgMedium(ref stm);
            }
        }
예제 #40
0
 internal static extern void ReleaseStgMedium(ref STGMEDIUM medium);
예제 #41
0
        /// <summary>
        /// Retrieves the data associated with the specified data format at the specified index.
        /// </summary>
        /// <param name="format">The format of the data to retrieve. See <see cref="T:System.Windows.Forms.DataFormats"></see> for predefined formats.</param>
        /// <param name="index">The index of the data to retrieve.</param>
        /// <returns>
        /// A <see cref="MemoryStream"/> containing the raw data for the specified data format at the specified index.
        /// </returns>
        public MemoryStream GetData(string format, int index)
        {
            //create a FORMATETC struct to request the data with
            FORMATETC formatetc = new FORMATETC();

            formatetc.cfFormat = (short)DataFormats.GetFormat(format).Id;
            formatetc.dwAspect = DVASPECT.DVASPECT_CONTENT;
            formatetc.lindex   = index;
            formatetc.ptd      = new IntPtr(0);
            formatetc.tymed    = TYMED.TYMED_ISTREAM | TYMED.TYMED_ISTORAGE | TYMED.TYMED_HGLOBAL;

            //create STGMEDIUM to output request results into
            STGMEDIUM medium = new STGMEDIUM();

            //using the Com IDataObject interface get the data using the defined FORMATETC
            this.comUnderlyingDataObject.GetData(ref formatetc, out medium);

            //retrieve the data depending on the returned store type
            switch (medium.tymed)
            {
            case TYMED.TYMED_ISTORAGE:
                //to handle a IStorage it needs to be written into a second unmanaged
                //memory mapped storage and then the data can be read from memory into
                //a managed byte and returned as a MemoryStream

                Win32.NativeMethods.IStorage   iStorage   = null;
                Win32.NativeMethods.IStorage   iStorage2  = null;
                Win32.NativeMethods.ILockBytes iLockBytes = null;
                System.Runtime.InteropServices.ComTypes.STATSTG iLockBytesStat;
                try
                {
                    //marshal the returned pointer to a IStorage object
                    iStorage = (Win32.NativeMethods.IStorage)Marshal.GetObjectForIUnknown(medium.unionmember);
                    Marshal.Release(medium.unionmember);

                    //create a ILockBytes (unmanaged byte array) and then create a IStorage using the byte array as a backing store
                    iLockBytes = Win32.NativeMethods.CreateILockBytesOnHGlobal(IntPtr.Zero, true);
                    iStorage2  = Win32.NativeMethods.StgCreateDocfileOnILockBytes(iLockBytes, 0x00001012, 0);

                    //copy the returned IStorage into the new IStorage
                    iStorage.CopyTo(0, null, IntPtr.Zero, iStorage2);
                    iLockBytes.Flush();
                    iStorage2.Commit(0);

                    //get the STATSTG of the ILockBytes to determine how many bytes were written to it
                    iLockBytesStat = new System.Runtime.InteropServices.ComTypes.STATSTG();
                    iLockBytes.Stat(out iLockBytesStat, 1);
                    int iLockBytesSize = (int)iLockBytesStat.cbSize;

                    //read the data from the ILockBytes (unmanaged byte array) into a managed byte array
                    byte[] iLockBytesContent = new byte[iLockBytesSize];
                    iLockBytes.ReadAt(0, iLockBytesContent, iLockBytesContent.Length, null);

                    //wrapped the managed byte array into a memory stream and return it
                    return(new MemoryStream(iLockBytesContent));
                }
                finally
                {
                    //release all unmanaged objects
                    Marshal.ReleaseComObject(iStorage2);
                    Marshal.ReleaseComObject(iLockBytes);
                    Marshal.ReleaseComObject(iStorage);
                }

            case TYMED.TYMED_ISTREAM:
                //to handle a IStream it needs to be read into a managed byte and
                //returned as a MemoryStream

                IStream iStream = null;
                System.Runtime.InteropServices.ComTypes.STATSTG iStreamStat;
                try
                {
                    //marshal the returned pointer to a IStream object
                    iStream = (IStream)Marshal.GetObjectForIUnknown(medium.unionmember);
                    Marshal.Release(medium.unionmember);

                    //get the STATSTG of the IStream to determine how many bytes are in it
                    iStreamStat = new System.Runtime.InteropServices.ComTypes.STATSTG();
                    iStream.Stat(out iStreamStat, 0);
                    int iStreamSize = (int)iStreamStat.cbSize;

                    //read the data from the IStream into a managed byte array
                    byte[] iStreamContent = new byte[iStreamSize];
                    iStream.Read(iStreamContent, iStreamContent.Length, IntPtr.Zero);

                    //wrapped the managed byte array into a memory stream and return it
                    return(new MemoryStream(iStreamContent));
                }
                finally
                {
                    //release all unmanaged objects
                    Marshal.ReleaseComObject(iStream);
                }

            case TYMED.TYMED_HGLOBAL:
                //to handle a HGlobal the exisitng "GetDataFromHGLOBLAL" method is invoked via
                //reflection

                return((MemoryStream)this.getDataFromHGLOBLALMethod.Invoke(this.oleUnderlyingDataObject, new object[] { DataFormats.GetFormat((short)formatetc.cfFormat).Name, medium.unionmember }));
            }

            return(null);
        }
예제 #42
0
 internal static uint GetDataHere(IntPtr @this, ref FORMATETC pformatetc, ref STGMEDIUM pmedium)
 {
     return(DV_E_FORMATETC);
 }
예제 #43
0
        /// <summary>
        /// Serializes managed data to an HGLOBAL.
        /// </summary>
        /// <param name="data">The managed data object.</param>
        /// <returns>An STGMEDIUM pointing to the allocated HGLOBAL.</returns>
        private static void GetMediumFromObject(object data, out STGMEDIUM medium)
        {
            // We'll serialize to a managed stream temporarily
            MemoryStream stream = new MemoryStream();

            // Write an indentifying stamp, so we can recognize this as custom
            // marshaled data.
            stream.Write(ManagedDataStamp.ToByteArray(), 0, Marshal.SizeOf(typeof (Guid)));

            // Now serialize the data. Note, if the data is not directly serializable,
            // we'll try type conversion. Also, we serialize the type. That way,
            // during deserialization, we know which type to convert back to, if
            // appropriate.
            BinaryFormatter formatter = new BinaryFormatter();
            formatter.Serialize(stream, data.GetType());
            formatter.Serialize(stream, GetAsSerializable(data));

            // Now copy to an HGLOBAL
            byte[] bytes = stream.GetBuffer();
            IntPtr p = Marshal.AllocHGlobal(bytes.Length);
            try
            {
                Marshal.Copy(bytes, 0, p, bytes.Length);
            }
            catch
            {
                // Make sure to free the memory on exceptions
                Marshal.FreeHGlobal(p);
                throw;
            }

            // Now allocate an STGMEDIUM to wrap the HGLOBAL
            medium.unionmember = p;
            medium.tymed = TYMED.TYMED_HGLOBAL;
            medium.pUnkForRelease = null;
        }
예제 #44
0
 internal static uint SetData(IntPtr this_, ref FORMATETC pformatetc, ref STGMEDIUM pmedium, bool release)
 {
     return(E_NOTIMPL);
 }
예제 #45
0
 /// <summary>
 /// Gets the specified data.
 /// </summary>
 /// <param name="format">The requested data format.</param>
 /// <param name="medium">When the function returns, contains the requested data.</param>
 public void GetData(ref FORMATETC format, out STGMEDIUM medium)
 {
     medium = new STGMEDIUM();
     GetDataHere(ref format, ref medium);
 }
예제 #46
0
 internal uint GetDataHere(FORMATETC pformatetc, ref STGMEDIUM pmedium)
 {
     return(E_NOTIMPL);
 }
예제 #47
0
        /// <summary>
        /// Sets data in the specified format into storage.
        /// </summary>
        /// <param name="formatIn">The format of the data.</param>
        /// <param name="medium">The data.</param>
        /// <param name="release">If true, ownership of the medium's memory will be transferred
        /// to this object. If false, a copy of the medium will be created and maintained, and
        /// the caller is responsible for the memory of the medium it provided.</param>
        public void SetData(ref FORMATETC formatIn, ref STGMEDIUM medium, bool release)
        {
            // If the format exists in our storage, remove it prior to resetting it
            foreach (KeyValuePair<FORMATETC, STGMEDIUM> pair in storage)
            {
                if ((pair.Key.tymed & formatIn.tymed) > 0
                    && pair.Key.dwAspect == formatIn.dwAspect
                    && pair.Key.cfFormat == formatIn.cfFormat)
                {
                    STGMEDIUM releaseMedium = pair.Value;
                    ReleaseStgMedium(ref releaseMedium);
                    storage.Remove(pair);
                    break;
                }
            }

            // If release is true, we'll take ownership of the medium.
            // If not, we'll make a copy of it.
            STGMEDIUM sm = medium;
            if (!release)
                sm = CopyMedium(ref medium);

            // Add it to the internal storage
            KeyValuePair<FORMATETC, STGMEDIUM> addPair = new KeyValuePair<FORMATETC, STGMEDIUM>(formatIn, sm);
            storage.Add(addPair);

            RaiseDataChanged(ref addPair);
        }
예제 #48
0
 internal uint SetData(FORMATETC pformatetc, STGMEDIUM pmedium, bool release)
 {
     return(E_NOTIMPL);
 }
예제 #49
0
 private static extern void ReleaseStgMedium(ref STGMEDIUM pmedium);
예제 #50
0
        private static bool AddFormatAndMedium(ClipboardFormats cfFormat, object data)
        {
            STGMEDIUM medium;
            FORMATETC format;
            IntPtr    hmem;
            IntPtr    hmem_ptr;

            byte[] b;

            switch (cfFormat)
            {
            case ClipboardFormats.CF_TEXT: {
                b    = XplatUIWin32.StringToAnsi((string)data);
                hmem = XplatUIWin32.CopyToMoveableMemory(b);
                break;
            }

            case ClipboardFormats.CF_UNICODETEXT: {
                b    = XplatUIWin32.StringToUnicode((string)data);
                hmem = XplatUIWin32.CopyToMoveableMemory(b);
                break;
            }

            case ClipboardFormats.CF_HDROP: {
                IEnumerator   e;
                StringBuilder sb;
                long          hmem_string_ptr;
                IntPtr        string_buffer;
                int           string_buffer_size;

                sb = new StringBuilder();

                // Make sure object is enumerable; otherwise
                if ((data is string) || !(data is IEnumerable))
                {
                    sb.Append(data.ToString());
                    sb.Append('\0');
                    sb.Append('\0');
                }
                else
                {
                    e = ((IEnumerable)data).GetEnumerator();
                    while (e.MoveNext())
                    {
                        sb.Append(e.Current.ToString());
                        sb.Append('\0');
                    }
                    sb.Append('\0');
                }

                string_buffer      = Marshal.StringToHGlobalUni(sb.ToString());
                string_buffer_size = (int)XplatUIWin32.Win32GlobalSize(string_buffer);

                // Write DROPFILES structure
                hmem     = XplatUIWin32.Win32GlobalAlloc(XplatUIWin32.GAllocFlags.GMEM_MOVEABLE | XplatUIWin32.GAllocFlags.GMEM_DDESHARE, 0x14 + string_buffer_size);
                hmem_ptr = XplatUIWin32.Win32GlobalLock(hmem);
                Marshal.WriteInt32(hmem_ptr, 0x14);                                                             // pFiles
                Marshal.WriteInt32(hmem_ptr, 1 * Marshal.SizeOf(typeof(uint)), 0);                              // point.x
                Marshal.WriteInt32(hmem_ptr, 2 * Marshal.SizeOf(typeof(uint)), 0);                              // point.y
                Marshal.WriteInt32(hmem_ptr, 3 * Marshal.SizeOf(typeof(uint)), 0);                              // fNc
                Marshal.WriteInt32(hmem_ptr, 4 * Marshal.SizeOf(typeof(uint)), 1);                              // fWide

                hmem_string_ptr  = (long)hmem_ptr;
                hmem_string_ptr += 0x14;

                XplatUIWin32.Win32CopyMemory(new IntPtr(hmem_string_ptr), string_buffer, string_buffer_size);
                Marshal.FreeHGlobal(string_buffer);
                XplatUIWin32.Win32GlobalUnlock(hmem_ptr);

                break;
            }

            case ClipboardFormats.CF_DIB: {
                b    = XplatUIWin32.ImageToDIB((Image)data);
                hmem = XplatUIWin32.CopyToMoveableMemory(b);
                break;
            }

            default: {
                hmem = IntPtr.Zero;
                break;
            }
            }

            if (hmem != IntPtr.Zero)
            {
                medium                = new STGMEDIUM();
                medium.tymed          = TYMED.TYMED_HGLOBAL;
                medium.hHandle        = hmem;
                medium.pUnkForRelease = IntPtr.Zero;
                DragMediums.Add(medium);

                format          = new FORMATETC();
                format.ptd      = IntPtr.Zero;
                format.dwAspect = DVASPECT.DVASPECT_CONTENT;
                format.lindex   = -1;
                format.tymed    = TYMED.TYMED_HGLOBAL;
                format.cfFormat = cfFormat;
                DragFormats.Add(format);

                return(true);
            }

            return(false);
        }
예제 #51
0
        public static STGMEDIUM GetData(Microsoft.VisualStudio.OLE.Interop.IDataObject dataObject, ref FORMATETC fmtetc)
        {
            if (dataObject == null)
                throw new ArgumentNullException("dataObject");

            FORMATETC[] af = new FORMATETC[1];
            af[0] = fmtetc;
            STGMEDIUM[] sm = new STGMEDIUM[1];
            dataObject.GetData(af, sm);
            fmtetc = af[0];
            return sm[0];
        }
예제 #52
0
        IntPtr IBindStatusCallback.OnDataAvailable(uint grfBSCF, uint dwSize, ref FORMATETC pformatetc, ref STGMEDIUM pstgmed)
        {
            if (pstgmed.tymed != TYMED.TYMED_ISTREAM)
            {
                throw new InvalidOperationException("This callback handler only supports IStreams.");
            }

            // assume an IStream has been requested in BindMonikerToObject
            IStream stream = (IStream)Marshal.GetObjectForIUnknown(pstgmed.unionmember);

            IntPtr hresult;
            bool   shouldContinue = true;

            do
            {
                byte[] buffer     = new byte[bufferSize];
                IntPtr pBytesRead = Marshal.AllocHGlobal(sizeof(uint));
                hresult = stream.Read(buffer, buffer.Length, pBytesRead);
                uint bytesRead = (uint)Marshal.PtrToStructure(pBytesRead, typeof(uint));
                Marshal.FreeHGlobal(pBytesRead);

                if (bytesRead > 0)
                {
                    shouldContinue = viewEvents.OnDataAvailable(buffer, (int)bytesRead);
                }
                //if (HResults.Equals(hresult, HResults.E_PENDING))
                //{
                //	Thread.Sleep(1000);
                //	hresult = HResults.S_OK;
                //}
            } while (shouldContinue && HResults.Succeeded(hresult) && !HResults.Equals(hresult, HResults.S_FALSE));

            Marshal.ReleaseComObject(stream);

            if (!shouldContinue)
            {
                Abort();
            }

            if (!HResults.Succeeded(hresult))
            {
                return(hresult);
            }

            return(HResults.S_OK);
        }
예제 #53
0
파일: ShellDll.cs 프로젝트: dizzydezz/jmm
� � public static extern void ReleaseStgMedium(ref STGMEDIUM pmedium);
예제 #54
0
        private static MemoryStream GetFileContentFromIStream(this System.Windows.Forms.IDataObject data, STGMEDIUM medium)
        {
            var iStream = (IStream)Marshal.GetObjectForIUnknown(medium.unionmember);

            Marshal.Release(medium.unionmember);

            var iStreamStat = new System.Runtime.InteropServices.ComTypes.STATSTG();

            iStream.Stat(out iStreamStat, 0);

            var content = new byte[(int)iStreamStat.cbSize];

            iStream.Read(content, content.Length, IntPtr.Zero);

            return(new MemoryStream(content));
        }
예제 #55
0
 /// <summary>
 /// Asks the given list item to renders a specific clipboard format that it supports.
 /// </summary>
 /// <param name="index"></param>
 /// <param name="grfFlags"></param>
 /// <param name="pFormatetc"></param>
 /// <param name="pMedium"></param>
 /// <returns></returns>
 public int GetClipboardFormat(uint index, uint grfFlags, FORMATETC[] pFormatetc, STGMEDIUM[] pMedium)
 {
     throw new NotImplementedException();
 }
예제 #56
0
        private static MemoryStream GetFileContentFromHGlobal(this System.Windows.Forms.IDataObject data, STGMEDIUM medium)
        {
            var innerDataField = data.GetType().GetField("innerData", BindingFlags.NonPublic | BindingFlags.Instance);
            var oldData        = (System.Windows.Forms.IDataObject)innerDataField.GetValue(data);

            var getDataFromHGLOBLALMethod = oldData.GetType().GetMethod("GetDataFromHGLOBLAL", BindingFlags.NonPublic | BindingFlags.Instance);

            return((MemoryStream)getDataFromHGLOBLALMethod.Invoke(oldData, new object[] { "FileContents", medium.unionmember }));
        }
 void IDataObject.GetDataHere(FORMATETC[] fmt, STGMEDIUM[] m) {
 }
예제 #58
0
 public int GetDataHere(ref FORMATETC format, ref STGMEDIUM medium)
 {
     log.DebugFormat("IDataObject.QueryGetData called -- cfFormat {0} dwAspect {1} lindex {2} ptd {3} tymed {4}", format.cfFormat, format.dwAspect, format.lindex, format.ptd, format.tymed);
     return(NativeMethods.E_NOTIMPL);
 }
 public static STGMEDIUM GetData(Microsoft.VisualStudio.OLE.Interop.IDataObject pDataObject, ref FORMATETC fmtetc) {
     FORMATETC[] af = new FORMATETC[1];
     af[0] = fmtetc;
     STGMEDIUM[] sm = new STGMEDIUM[1];
     pDataObject.GetData(af, sm);
     fmtetc = af[0];
     return sm[0];
 }
예제 #60
0
파일: Win32DnD.cs 프로젝트: nlhepler/mono
			internal uint GetDataHere(FORMATETC pformatetc, ref STGMEDIUM pmedium) {
				return E_NOTIMPL;
			}