• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# ComTypes.FORMATETC类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.Runtime.InteropServices.ComTypes.FORMATETC的典型用法代码示例。如果您正苦于以下问题:C# FORMATETC类的具体用法?C# FORMATETC怎么用?C# FORMATETC使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



FORMATETC类属于System.Runtime.InteropServices.ComTypes命名空间,在下文中一共展示了FORMATETC类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: DAdvise

        /// <summary>
        /// Creates a connection between a data object and an advisory sink. This method is called by an object
        /// that supports an advisory sink and enables the advisory sink to be notified of changes in the object's data.</summary>
        /// <returns>This method supports the standard return values E_INVALIDARG, E_UNEXPECTED, and E_OUTOFMEMORY,
        /// as well as the following:
        /// ValueDescriptionS_OK -- The advisory connection was created.
        /// E_NOTIMPL -- This method is not implemented on the data object.
        /// DV_E_LINDEX -- There is an invalid value for <see cref="F:System.Runtime.InteropServices.ComTypes.FORMATETC.lindex"/>;
        ///   currently, only -1 is supported.
        /// DV_E_FORMATETC -- There is an invalid value for the <paramref name="pFormatetc"/> parameter.
        /// OLE_E_ADVISENOTSUPPORTED -- The data object does not support change notification.</returns>
        /// <param name="pFormatetc">A <see cref="T:System.Runtime.InteropServices.ComTypes.FORMATETC"/> structure,
        /// passed by reference, that defines the format, target device, aspect, and medium that will be used for
        /// future notifications.</param>
        /// <param name="advf">One of the ADVF values that specifies a group of flags for controlling the advisory
        /// connection.</param>
        /// <param name="adviseSink">A pointer to the IAdviseSink interface on the advisory sink that will receive
        /// the change notification.</param>
        /// <param name="connection">When this method returns, contains a pointer to a DWORD token that identifies
        /// this connection. You can use this token later to delete the advisory connection by passing it to
        /// <see cref="M:System.Runtime.InteropServices.ComTypes.IDataObject.DUnadvise(System.Int32)"/>.
        /// If this value is zero, the connection was not established. This parameter is passed uninitialized.</param>
        public int DAdvise(ref FORMATETC pFormatetc, ADVF advf, IAdviseSink adviseSink, out int connection)
        {
            // Check that the specified advisory flags are supported.
            const ADVF c_advfAllowed = ADVF.ADVF_NODATA | ADVF.ADVF_ONLYONCE | ADVF.ADVF_PRIMEFIRST;
            if ((int)((advf | c_advfAllowed) ^ c_advfAllowed) != 0)
            {
                connection = 0;
                return OLE_E_ADVISENOTSUPPORTED;
            }

            // Create and insert an entry for the connection list
            var entry = new AdviseEntry
            {
                Format = pFormatetc,
                Advf = advf,
                Sink = adviseSink,
            };
            m_connections.Add(m_nextConnectionId, entry);
            connection = m_nextConnectionId;
            m_nextConnectionId++;

            // If the ADVF_PRIMEFIRST flag is specified and the data exists,
            // raise the DataChanged event now.
            if ((advf & ADVF.ADVF_PRIMEFIRST) == ADVF.ADVF_PRIMEFIRST)
            {
                OleData dataEntry;
                if (GetDataEntry(ref pFormatetc, out dataEntry))
                    RaiseDataChanged(connection, ref dataEntry);
            }

            return 0;
        }
开发者ID:BeRo1985,项目名称:LevelEditor,代码行数:54,代码来源:DragDropDataObject.cs


示例2: DAdvise

		/// <summary>
		/// Adds an advisory connection for the specified format.
		/// </summary>
		/// <param name="pFormatetc">The format for which this sink is called for changes.</param>
		/// <param name="advf">Advisory flags to specify callback behavior.</param>
		/// <param name="adviseSink">The IAdviseSink to call for this connection.</param>
		/// <param name="connection">Returns the new connection's ID.</param>
		/// <returns>An HRESULT.</returns>
		public int DAdvise(ref FORMATETC pFormatetc, ADVF advf, IAdviseSink adviseSink, out int connection) {
			// Check that the specified advisory flags are supported.
			const ADVF ADVF_ALLOWED = ADVF.ADVF_NODATA | ADVF.ADVF_ONLYONCE | ADVF.ADVF_PRIMEFIRST;
			if ((int) ((advf | ADVF_ALLOWED) ^ ADVF_ALLOWED) != 0) {
				connection = 0;
				return OLE_E_ADVISENOTSUPPORTED;
			}

			// Create and insert an entry for the connection list
			var entry = new AdviseEntry(ref pFormatetc, advf, adviseSink);
			connections.Add(nextConnectionId, entry);
			connection = nextConnectionId;
			nextConnectionId++;

			// If the ADVF_PRIMEFIRST flag is specified and the data exists,
			// raise the DataChanged event now.
			if ((advf & ADVF.ADVF_PRIMEFIRST) == ADVF.ADVF_PRIMEFIRST) {
				KeyValuePair<FORMATETC, STGMEDIUM> dataEntry;
				if (GetDataEntry(ref pFormatetc, out dataEntry))
					RaiseDataChanged(connection, ref dataEntry);
			}

			// S_OK
			return 0;
		}
开发者ID:hbaes,项目名称:updateSystem.NET,代码行数:33,代码来源:DataObject.cs


示例3: getHtml

        /// <summary>
        /// Extracts data of type <c>Dataformat.Html</c> from an <c>IDataObject</c> data container
        /// This method shouldn't throw any exception but writes relevant exception informations in the debug window
        /// </summary>
        /// <param name="data">data container</param>
        /// <returns>A byte[] array with the decoded string or null if the method fails</returns>
        /// <remarks>Added 2006-06-12, <c>Uwe Keim</c>.</remarks>
        private static byte[] getHtml(
            IDataObject data)
        {
            var interopData = (System.Runtime.InteropServices.ComTypes.IDataObject)data;

            var format =
                new FORMATETC
                {
                    cfFormat = ((short)DataFormats.GetFormat(DataFormats.Html).Id),
                    dwAspect = DVASPECT.DVASPECT_CONTENT,
                    lindex = (-1),
                    tymed = TYMED.TYMED_HGLOBAL
                };

            STGMEDIUM stgmedium;
            stgmedium.tymed = TYMED.TYMED_HGLOBAL;
            stgmedium.pUnkForRelease = null;

            var queryResult = interopData.QueryGetData(ref format);

            if (queryResult != 0)
            {
                return null;
            }

            interopData.GetData(ref format, out stgmedium);

            if (stgmedium.unionmember == IntPtr.Zero)
            {
                return null;
            }

            var pointer = stgmedium.unionmember;

            var handleRef = new HandleRef(null, pointer);

            byte[] rawArray;

            try
            {
                var ptr1 = GlobalLock(handleRef);

                var length = GlobalSize(handleRef);

                rawArray = new byte[length];

                Marshal.Copy(ptr1, rawArray, 0, length);
            }
            finally
            {
                GlobalUnlock(handleRef);
            }

            return rawArray;
        }
开发者ID:iraychen,项目名称:ZetaHtmlEditControl,代码行数:62,代码来源:HtmlClipboardHelper.cs


示例4: GetFileList

        /// <summary>
        /// Gets the file list.
        /// </summary>
        /// <param name="this">The IDataObject instance.</param>
        /// <returns>The file list in the data object.</returns>
        public static List<string> GetFileList(this IDataObject @this)
        {
            //  Create the format object.
            var formatEtc = new FORMATETC();

            //  Set up the format object, based on CF_HDROP.
            formatEtc.cfFormat = (short)CLIPFORMAT.CF_HDROP;
            formatEtc.ptd = IntPtr.Zero;
            formatEtc.dwAspect = DVASPECT.DVASPECT_CONTENT;
            formatEtc.lindex = -1;
            formatEtc.tymed = TYMED.TYMED_HGLOBAL;

            //  Get the data.
            // ReSharper disable RedundantAssignment
            var storageMedium = new STGMEDIUM();
            // ReSharper restore RedundantAssignment
            @this.GetData(ref formatEtc, out storageMedium);

            var fileList = new List<string>();

            //  Things can get risky now.
            try
            {
                //  Get the handle to the HDROP.
                var hDrop = storageMedium.unionmember;
                if (hDrop == IntPtr.Zero)
                    throw new ArgumentException("Failed to get the handle to the drop data.");

                //  Get the count of the files in the operation.
                var fileCount = Shell32.DragQueryFile(hDrop, UInt32.MaxValue, null, 0);

                //  Go through each file.
                for (uint i = 0; i < fileCount; i++)
                {
                    //  Storage for the file name.
                    var fileNameBuilder = new StringBuilder(MaxPath);

                    //  Get the file name.
                    var result = Shell32.DragQueryFile(hDrop, i, fileNameBuilder, (uint)fileNameBuilder.Capacity);

                    //  If we have a valid result, add the file name to the list of files.
                    if (result != 0)
                        fileList.Add(fileNameBuilder.ToString());
                }

            }
            finally
            {
                Ole32.ReleaseStgMedium(ref storageMedium);
            }

            return fileList;
        }
开发者ID:JamesLinus,项目名称:sharpshell,代码行数:58,代码来源:IDataObjectExtensions.cs


示例5: OutOfMemoryException

        void System.Runtime.InteropServices.ComTypes.IDataObject.GetData(ref FORMATETC formatetc, out STGMEDIUM medium)
        {
            if (formatetc.cfFormat == (Int16)DataFormats.GetFormat(NativeMethods.CFSTR_FILECONTENTS).Id)
            m_lindex = formatetc.lindex;

              medium = new System.Runtime.InteropServices.ComTypes.STGMEDIUM();
              if (GetTymedUseable(formatetc.tymed)) {
            if (formatetc.cfFormat == (Int16)DataFormats.GetFormat(NativeMethods.CFSTR_FILECONTENTS).Id) {
              if ((formatetc.tymed & TYMED.TYMED_ISTREAM) != TYMED.TYMED_NULL) {
            medium.tymed = TYMED.TYMED_ISTREAM;
            // medium.unionmember = Marshal.GetComInterfaceForObject(GetFileContents(this.m_SelectedItems, formatetc.lindex), typeof(IStreamWrapper));
            medium.unionmember = NativeMethods.VirtualAlloc(IntPtr.Zero, new UIntPtr(1), NativeMethods.MEM_COMMIT, NativeMethods.PAGE_READWRITE);
            if (medium.unionmember == IntPtr.Zero) {
              throw new OutOfMemoryException();
            }

            try {
              ((System.Runtime.InteropServices.ComTypes.IDataObject)this).GetDataHere(ref formatetc, ref medium);
              return;
            } catch {
              NativeMethods.VirtualFree(medium.unionmember, new UIntPtr(1), NativeMethods.MEM_DECOMMIT);
              medium.unionmember = IntPtr.Zero;
              throw;
            }
              }
            } 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;
              throw;
            }
              }
            }
            medium.tymed = formatetc.tymed;
            ((System.Runtime.InteropServices.ComTypes.IDataObject)this).GetDataHere(ref formatetc, ref medium);
              } else {
            Marshal.ThrowExceptionForHR(NativeMethods.DV_E_TYMED);
              }
        }
开发者ID:MTGUli,项目名称:TREExplorer,代码行数:49,代码来源:ClassDataObjectEx.cs


示例6: Initialize

        public void Initialize(IntPtr pidlFolder, IntPtr pDataObj, IntPtr hKeyProgID)
        {
            if (pDataObj == IntPtr.Zero)
            {
                throw new ArgumentException();
            }

            FORMATETC fe = new FORMATETC();
            fe.cfFormat = (short)CLIPFORMAT.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();
                }

                uint nFiles = Import.DragQueryFile(hDrop, UInt32.MaxValue, null, 0);
                if (nFiles == 0)
                {
                    Marshal.ThrowExceptionForHR(ErrorCode.E_FAIL);
                }

                selectedFiles = new List<string>();
                for (uint i = 0; i < nFiles; i++)
                {
                    selectedFiles.Add(getFileName(hDrop, i));
                }
            }
            finally
            {
                Import.ReleaseStgMedium(ref stm);
            }
        }
开发者ID:nuxeo,项目名称:nuxeo-otg-win,代码行数:47,代码来源:ContextMenuExt.cs


示例7: DAdvise

 public int DAdvise(ref FORMATETC formatetc, ADVF advf, IAdviseSink adviseSink, out int connection)
 {
     if (((advf | ADVF.ADVF_NODATA | ADVF.ADVF_PRIMEFIRST | ADVF.ADVF_ONLYONCE) ^ (ADVF.ADVF_NODATA | ADVF.ADVF_PRIMEFIRST | ADVF.ADVF_ONLYONCE)) != (ADVF)0)
     {
         connection = 0;
         return -2147221501;
     }
     else
     {
         this.connections.Add(this.nextConnectionId, new AdviseEntry(ref formatetc, advf, adviseSink));
         connection = this.nextConnectionId;
         ++this.nextConnectionId;
         KeyValuePair<FORMATETC, STGMEDIUM> dataEntry;
         if ((advf & ADVF.ADVF_PRIMEFIRST) == ADVF.ADVF_PRIMEFIRST && this.GetDataEntry(ref formatetc, out dataEntry))
             this.RaiseDataChanged(connection, ref dataEntry);
         return 0;
     }
 }
开发者ID:kingpin2k,项目名称:MCS,代码行数:18,代码来源:DataObject.cs


示例8: IsFormatValid

        internal static bool IsFormatValid(FORMATETC[] formats) {

            Debug.Assert(formats != null, "Null returned from GetFormats");
            if (formats != null) {
                if (formats.Length <= 4) {
                    for (int i = 0; i < formats.Length; i++) {
                        short format = formats[i].cfFormat;
                        if (format != NativeMethods.CF_TEXT &&
                            format !=  NativeMethods.CF_UNICODETEXT && 
                            format !=  DataFormats.GetFormat("System.String").Id &&
                            format !=  DataFormats.GetFormat("Csv").Id) {
                                return false;
                        }
                    }
                    return true;
                }
            }
            return false;
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:19,代码来源:Clipboard.cs


示例9: Drop

        public void Drop(IDataObject dataObject, uint keyState, Point pt, ref uint effect)
        {
            FORMATETC format = new FORMATETC()
            {
                cfFormat = NativeMethods.CF_HDROP,
                dwAspect = DVASPECT.DVASPECT_CONTENT,
                tymed = TYMED.TYMED_HGLOBAL
            };
            STGMEDIUM medium;
            string[] files;
            dataObject.GetData(ref format, out medium);
            try
            {
                IntPtr dropHandle = medium.unionmember;
                int fileCount = NativeMethods.DragQueryFile(new HandleRef(this, dropHandle), -1, null, 0);
                files = new string[fileCount];
                for (int x = 0; x < fileCount; ++x)
                {
                    int size = NativeMethods.DragQueryFile(new HandleRef(this, dropHandle), x, null, 0);
                    if (size > 0)
                    {
                        StringBuilder fileName = new StringBuilder(size + 1);
                        if (NativeMethods.DragQueryFile(new HandleRef(this, dropHandle), x, fileName, fileName.Capacity) > 0)
                            files[x] = fileName.ToString();
                    }
                }
            }
            finally
            {
                NativeMethods.ReleaseStgMedium(ref medium);
            }

            foreach (string file in files)
            {
                Client.OpenGLContextThread.Add(() => 
                {
                    ImportExportUtil.Import(file);
                });
            }
        }
开发者ID:law4x,项目名称:stonevox3d,代码行数:40,代码来源:DragDropTarget.cs


示例10: IsFormatValid

 internal static bool IsFormatValid(FORMATETC[] formats)
 {
     if ((formats == null) || (formats.Length > 4))
     {
         return false;
     }
     for (int i = 0; i < formats.Length; i++)
     {
         short cfFormat = formats[i].cfFormat;
         if (((cfFormat != 1) && (cfFormat != 13)) && ((cfFormat != DataFormats.GetFormat("System.String").Id) && (cfFormat != DataFormats.GetFormat("Csv").Id)))
         {
             return false;
         }
     }
     return true;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:16,代码来源:Clipboard.cs


示例11: OnDataChange

 /// <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.
     var odd = DropDescriptionHelper.GetDropDescription(m_data);
     if (odd != null)
     {
         DropDescriptionHelper.SetDropDescriptionIsDefault(m_data, false);
     }
 }
开发者ID:JanDeHud,项目名称:LevelEditor,代码行数:15,代码来源:DragDropExtender.cs


示例12: SetVirtualFiles

 public static void SetVirtualFiles(this System.Windows.IDataObject dataObject, VirtualFile[] files)
 {
     if (files == null)
         throw new ArgumentNullException();
     MemoryStream memoryStream = new MemoryStream();
     memoryStream.Write(BitConverter.GetBytes(files.Length), 0, 4);
     for (int index = 0; index < files.Length; ++index)
     {
         VirtualFile file = files[index];
         if (file.Contents == null || file.Contents.Length == 0)
             throw new ArgumentException("VirtualFile does not have any contents.");
         FORMATETC formatIn = new FORMATETC()
         {
             cfFormat = (short)DataFormats.GetDataFormat("FileContents").Id,
             dwAspect = DVASPECT.DVASPECT_CONTENT,
             lindex = index,
             ptd = IntPtr.Zero,
             tymed = TYMED.TYMED_ISTREAM
         };
         STGMEDIUM medium = DataObjectExtensions.WriteBytesToMedium(file.Contents);
         ((System.Runtime.InteropServices.ComTypes.IDataObject)dataObject).SetData(ref formatIn, ref medium, true);
         DataObjectExtensions.WriteFileDescriptor((Stream)memoryStream, file);
     }
     IntPtr num = Marshal.AllocHGlobal((int)memoryStream.Length);
     try
     {
         Marshal.Copy(memoryStream.GetBuffer(), 0, num, (int)memoryStream.Length);
     }
     catch
     {
         Marshal.FreeHGlobal(num);
         throw;
     }
     STGMEDIUM medium1;
     medium1.pUnkForRelease = (object)null;
     medium1.tymed = TYMED.TYMED_HGLOBAL;
     medium1.unionmember = num;
     FORMATETC formatIn1 = new FORMATETC()
     {
         cfFormat = (short)DataFormats.GetDataFormat("FileGroupDescriptorW").Id,
         dwAspect = DVASPECT.DVASPECT_CONTENT,
         lindex = -1,
         ptd = IntPtr.Zero,
         tymed = TYMED.TYMED_HGLOBAL
     };
     ((System.Runtime.InteropServices.ComTypes.IDataObject)dataObject).SetData(ref formatIn1, ref medium1, true);
 }
开发者ID:kingpin2k,项目名称:MCS,代码行数:47,代码来源:DataObjectExtensions.cs


示例13: SetDataEx

        public static void SetDataEx(this System.Windows.IDataObject dataObject, string format, object data)
        {
            DataFormat dataFormat = DataFormats.GetDataFormat(format);
            FORMATETC formatetc = new FORMATETC()
            {
                cfFormat = (short)dataFormat.Id,
                dwAspect = DVASPECT.DVASPECT_CONTENT,
                lindex = -1,
                ptd = IntPtr.Zero
            };
            TYMED compatibleTymed = DataObjectExtensions.GetCompatibleTymed(format, data);
            if (compatibleTymed != TYMED.TYMED_NULL)
            {
                formatetc.tymed = compatibleTymed;
                System.Windows.IDataObject dataObject1 = new System.Windows.DataObject();

                dataObject1.SetData(format, data, true);

                STGMEDIUM medium;

                ((System.Runtime.InteropServices.ComTypes.IDataObject)dataObject1).GetData(ref formatetc, out medium);

                try
                {
                    ((System.Runtime.InteropServices.ComTypes.IDataObject)dataObject).SetData(ref formatetc, ref medium, true);
                }
                catch
                {
                    Advent.Common.Interop.NativeMethods.ReleaseStgMedium(ref medium);
                    throw;
                }
            }
            else
                DataObjectExtensions.SetManagedData(dataObject, format, data);
        }
开发者ID:kingpin2k,项目名称:MCS,代码行数:35,代码来源:DataObjectExtensions.cs


示例14: NotImplementedException

        void IComDataObject.SetData(ref FORMATETC pFormatetcIn, ref STGMEDIUM pmedium, bool fRelease) {

            Debug.WriteLineIf(CompModSwitches.DataObject.TraceVerbose, "SetData");
            if (innerData is OleConverter) {
                ((OleConverter)innerData).OleDataObject.SetData(ref pFormatetcIn, ref pmedium, fRelease);
                return;
            }
            // 

            throw new NotImplementedException();
        }
开发者ID:JianwenSun,项目名称:cc,代码行数:11,代码来源:DataObject.cs


示例15: GetDataIntoOleStructs

 void IComDataObject.GetDataHere(ref FORMATETC formatetc, ref STGMEDIUM medium) {
     Debug.WriteLineIf(CompModSwitches.DataObject.TraceVerbose, "GetDataHere");
     if (innerData is OleConverter) {
         ((OleConverter)innerData).OleDataObject.GetDataHere(ref formatetc, ref medium);
     }
     else {
         GetDataIntoOleStructs(ref formatetc, ref medium);
     }
 }
开发者ID:JianwenSun,项目名称:cc,代码行数:9,代码来源:DataObject.cs


示例16: return

 int IComDataObject.GetCanonicalFormatEtc(ref FORMATETC pformatetcIn, out FORMATETC pformatetcOut) {
     Debug.WriteLineIf(CompModSwitches.DataObject.TraceVerbose, "GetCanonicalFormatEtc");
     if (innerData is OleConverter) {
         return ((OleConverter)innerData).OleDataObject.GetCanonicalFormatEtc(ref pformatetcIn, out pformatetcOut);
     }
     pformatetcOut = new FORMATETC();
     return (DATA_S_SAMEFORMATETC);
 }
开发者ID:JianwenSun,项目名称:cc,代码行数:8,代码来源:DataObject.cs


示例17: OutOfMemoryException

        void IComDataObject.GetData(ref FORMATETC formatetc, out STGMEDIUM medium) {
            Debug.WriteLineIf(CompModSwitches.DataObject.TraceVerbose, "GetData");
            if (innerData is OleConverter) {
                ((OleConverter)innerData).OleDataObject.GetData(ref formatetc, out medium);
                return;
            }

            medium = new STGMEDIUM();

            if (GetTymedUseable(formatetc.tymed)) {
                if ((formatetc.tymed & TYMED.TYMED_HGLOBAL) != 0) {
                    medium.tymed = TYMED.TYMED_HGLOBAL;
                    medium.unionmember = UnsafeNativeMethods.GlobalAlloc(NativeMethods.GMEM_MOVEABLE
                                                             | NativeMethods.GMEM_DDESHARE
                                                             | NativeMethods.GMEM_ZEROINIT,
                                                             1);
                    if (medium.unionmember == IntPtr.Zero) {
                        throw new OutOfMemoryException();
                    }
 
                    try {
                        ((IComDataObject)this).GetDataHere(ref formatetc, ref medium);
                    }
                    catch {
                        UnsafeNativeMethods.GlobalFree(new HandleRef(medium, medium.unionmember));
                        medium.unionmember = IntPtr.Zero;
                        throw;
                    }
                }
                else {
                    medium.tymed  = formatetc.tymed;
                    ((IComDataObject)this).GetDataHere(ref formatetc, ref medium);
                }
            }
            else {
                Marshal.ThrowExceptionForHR(DV_E_TYMED);
            }
        }
开发者ID:JianwenSun,项目名称:cc,代码行数:38,代码来源:DataObject.cs


示例18: GetDataFromOleHGLOBAL

            /// <include file='doc\DataObject.uex' path='docs/doc[@for="DataObject.OleConverter.GetDataFromOleHGLOBAL"]/*' />
            /// <devdoc>
            ///     Uses HGLOBALs and retrieves the specified format from the bound IComDatabject.
            /// </devdoc>
            /// <internalonly/>
            private Object GetDataFromOleHGLOBAL(string format) {
                Debug.Assert(innerData != null, "You must have an innerData on all DataObjects");

                FORMATETC formatetc = new FORMATETC();
                STGMEDIUM medium = new STGMEDIUM();

                formatetc.cfFormat = unchecked((short)(ushort)(DataFormats.GetFormat(format).Id));
                formatetc.dwAspect = DVASPECT.DVASPECT_CONTENT;
                formatetc.lindex = -1;
                formatetc.tymed = TYMED.TYMED_HGLOBAL;

                medium.tymed = TYMED.TYMED_HGLOBAL;

                object data = null;

                if (NativeMethods.S_OK == QueryGetDataUnsafe(ref formatetc)) {
                    try {
                        IntSecurity.UnmanagedCode.Assert();
                        try {
                             innerData.GetData(ref formatetc, out medium);
                        }
                        finally {
                            CodeAccessPermission.RevertAssert();
                        }

                        if (medium.unionmember != IntPtr.Zero) {
                            data = GetDataFromHGLOBLAL(format, medium.unionmember);
                        }
                    }
                    catch {
                    }
                }
                return data;
            }
开发者ID:JianwenSun,项目名称:cc,代码行数:39,代码来源:DataObject.cs


示例19: GetDataFromOleOther

            /// <include file='doc\DataObject.uex' path='docs/doc[@for="DataObject.OleConverter.GetDataFromOleOther"]/*' />
            /// <devdoc>
            ///     Retrieves the specified format data from the bound IComDataObject, from
            ///     other sources that IStream and HGLOBAL... this is really just a place
            ///     to put the "special" formats like BITMAP, ENHMF, etc.
            /// </devdoc>
            /// <internalonly/>
            private Object GetDataFromOleOther(string format) {
                Debug.Assert(innerData != null, "You must have an innerData on all DataObjects");

                FORMATETC formatetc = new FORMATETC();
                STGMEDIUM medium = new STGMEDIUM();

                TYMED tymed = (TYMED)0;

                if (format.Equals(DataFormats.Bitmap)) {
                    tymed = TYMED.TYMED_GDI;
                }
                else if (format.Equals(DataFormats.EnhancedMetafile)) {
                    tymed = TYMED.TYMED_ENHMF;
                }

                if (tymed == (TYMED)0) {
                    return null;
                }

                formatetc.cfFormat = unchecked((short)(ushort)(DataFormats.GetFormat(format).Id));
                formatetc.dwAspect = DVASPECT.DVASPECT_CONTENT;
                formatetc.lindex = -1;
                formatetc.tymed = tymed;
                medium.tymed = tymed;

                Object data = null;
                if (NativeMethods.S_OK == QueryGetDataUnsafe(ref formatetc)) {
                    try {
                        IntSecurity.UnmanagedCode.Assert();
                        try {
                             innerData.GetData(ref formatetc, out medium);
                        }
                        finally {
                            CodeAccessPermission.RevertAssert();
                        }
                    }
                    catch {
                    }
                }

                if (medium.unionmember != IntPtr.Zero) {

                    if (format.Equals(DataFormats.Bitmap)
                        //||format.Equals(DataFormats.Dib))
                    ) { 
                        // as/urt 140870 -- GDI+ doesn't own this HBITMAP, but we can't
                        // delete it while the object is still around.  So we have to do the really expensive
                        // thing of cloning the image so we can release the HBITMAP.
                        //

                        //This bitmap is created by the com object which originally copied the bitmap to tbe 
                        //clipboard. We call Add here, since DeleteObject calls Remove.
                        System.Internal.HandleCollector.Add(medium.unionmember, NativeMethods.CommonHandles.GDI);
                        Image clipboardImage = null;
                        IntSecurity.ObjectFromWin32Handle.Assert();
                        try
                        {
                            clipboardImage = Image.FromHbitmap(medium.unionmember);
                        }
                        finally
                        {
                            CodeAccessPermission.RevertAssert();
                        }
                        if (clipboardImage != null) {
                            Image firstImage = clipboardImage;
                            clipboardImage = (Image)clipboardImage.Clone();
                            SafeNativeMethods.DeleteObject(new HandleRef(null, medium.unionmember));
                            firstImage.Dispose();
                        }
                        data = clipboardImage;
                    }
/* gpr:
                    else if (format.Equals(DataFormats.EnhancedMetafile)) {
                        data = new Metafile(medium.unionmember);
                    }
*/
                }

                return data;
            }
开发者ID:JianwenSun,项目名称:cc,代码行数:87,代码来源:DataObject.cs


示例20: OnDataChange

 public void OnDataChange(ref FORMATETC format, ref STGMEDIUM stgmedium)
 {
     if (DataObjectExtensions.GetDropDescription(this.data) == null)
         return;
     DataObjectExtensions.SetDropDescriptionIsDefault(this.data, false);
 }
开发者ID:kingpin2k,项目名称:MCS,代码行数:6,代码来源:DataObjectExtensions.cs



注:本文中的System.Runtime.InteropServices.ComTypes.FORMATETC类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# ComTypes.STGMEDIUM类代码示例发布时间:2022-05-26
下一篇:
C# InteropServices.StringBuffer类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap