/// <summary> /// Create an OleStgMediumCOMOBJECT that encapsulates the passed STGMEDIUM /// </summary> /// <param name="stg">Underlying STGMEDIUM</param> public OleStgMediumCOMOBJECT(STGMEDIUM stg) : base(stg) { // store the com object m_comObject = Marshal.GetObjectForIUnknown(stg.contents); Debug.Assert(m_comObject != null); }
/// <summary> /// Create an OleStgMediumHandle that encapsulates the passed STGMEDIUM /// </summary> /// <param name="stg">Underlying STGMEDIUM</param> public OleStgMediumFILE(STGMEDIUM stg) : base(stg) { // validate that the correct type has been passed in ValidateType(TYMED.FILE); // marshall the file path into a .NET string m_path = Marshal.PtrToStringAuto(stg.contents); }
/// <summary> /// Create an OleStgMediumSTREAM that encapsulates the passed STGMEDIUM /// </summary> /// <param name="stg">Underlying STGMEDIUM</param> public OleStgMediumISTREAM(STGMEDIUM stg) : base(stg) { // validate that the correct type has been passed in ValidateType(TYMED.ISTREAM); // initialize the .NET stream m_stream = new ComStream((IStream)m_comObject); }
/// <summary> /// Create an OleStgMediumSTORAGE that encapsulates the passed STGMEDIUM /// </summary> /// <param name="stg">Underlying STGMEDIUM</param> public OleStgMediumISTORAGE(STGMEDIUM stg) : base(stg) { // validate that the correct type has been passed in ValidateType(TYMED.ISTORAGE); // initialize the storage m_storage = new Storage((IStorage)m_comObject, false); }
/// <summary> /// Renders the data described in a FORMATETC structure and transfers it /// through the STGMEDIUM structure. /// </summary> /// <param name="pFormatEtc">Pointer to the FORMATETC structure that defines /// the format, medium, and target device to use when passing the data. It is /// possible to specify more than one medium by using the Boolean OR operator, /// allowing the method to choose the best medium among those specified</param> /// <param name="pMedium">Pointer to the STGMEDIUM structure that indicates /// the storage medium containing the returned data through its tymed member, /// and the responsibility for releasing the medium through the value of its /// pUnkForRelease member. If pUnkForRelease is NULL, the receiver of the medium /// is responsible for releasing it; otherwise, pUnkForRelease points to the /// IUnknown on the appropriate object so its Release method can be called. /// The medium must be allocated and filled in by IDataObject::GetData</param> public int GetData(ref FORMATETC pFormatEtc, ref STGMEDIUM pMedium) { // check to see if we have data of the requested type int dataFormatIndex; int result = FindDataFormat(ref pFormatEtc, out dataFormatIndex); // if we do then return a clone of it (returns error code if an // error occurs during the clone) if (result == HRESULT.S_OK) { // lookup the entry OleDataEntry dataEntry = (OleDataEntry)oleDataEntries[dataFormatIndex]; // clone the storage and return return CloneStgMedium(dataEntry.stgm, ref pMedium); } // don't have the data, return the error code passed back to us // from FindDataFormat else { return result; } }
/// <summary> /// Create an OleStgMediumHandle that encapsulates the passed STGMEDIUM /// </summary> /// <param name="stg">Underlying STGMEDIUM</param> public OleStgMediumHGLOBAL(STGMEDIUM stg) : base(stg) { ValidateType(TYMED.HGLOBAL); }
/// <summary> /// Create an OleStgMediumHandle that encapsulates the passed STGMEDIUM /// </summary> /// <param name="stg">Underlying STGMEDIUM</param> public OleStgMediumGDI(STGMEDIUM stg) : base(stg) { ValidateType(TYMED.GDI); }
/// <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"); }
public static extern void ReleaseStgMedium(ref STGMEDIUM pmedium);
/// <summary> /// Create an OleStgMediumHandle that encapsulates the passed STGMEDIUM /// </summary> /// <param name="stg">Underlying STGMEDIUM</param> public OleStgMediumMFPICT(STGMEDIUM stg) : base(stg) { ValidateType(TYMED.MFPICT); }
/// <summary> /// Create a cloned copy of the the passed storage medium. This method works via /// a combination of actually copying underling data and incrementing reference /// counts on embedded objects. /// </summary> /// <param name="stgmIn">storage medium in</param> /// <param name="stgmOut">storage medium out</param> /// <returns>HRESULT.S_OK if the medium was successfully cloned, various /// OLE error codes if an error occurs during the clone </returns> private int CloneStgMedium(STGMEDIUM stgmIn, ref STGMEDIUM stgmOut) { // copy storage type stgmOut.tymed = stgmIn.tymed; // copy or add ref count to the actual data switch (stgmIn.tymed) { // global memory blocks get copied case TYMED.HGLOBAL: using (HGlobalLock input = new HGlobalLock(stgmIn.contents)) stgmOut.contents = input.Clone(); break; // COM interfaces get copied w/ their ref-count incremented case TYMED.ISTREAM: case TYMED.ISTORAGE: stgmOut.contents = stgmIn.contents; Marshal.AddRef(stgmOut.contents); break; // don't know how to clone other storage medium types (return error) case TYMED.ENHMF: case TYMED.FILE: case TYMED.GDI: case TYMED.MFPICT: default: return DV_E.TYMED; } // copy pUnkForRelease and add a reference count on it if there is one stgmOut.pUnkForRelease = stgmIn.pUnkForRelease; if (stgmOut.pUnkForRelease != IntPtr.Zero) Marshal.AddRef(stgmOut.pUnkForRelease); // return success return HRESULT.S_OK; }
/// <summary> /// Renders the data described in a FORMATETC structure and transfers it /// through the STGMEDIUM structure allocated by the caller. /// </summary> /// <param name="pFormatEtc">Pointer to the FORMATETC structure that defines /// the format, medium, and target device to use when passing the data. It is /// possible to specify more than one medium by using the Boolean OR operator, /// allowing the method to choose the best medium among those specified</param> /// <param name="pMedium">Pointer to the STGMEDIUM structure that defines the /// storage medium containing the data being transferred. The medium must be /// allocated by the caller and filled in by IDataObject::GetDataHere. The /// caller must also free the medium. The implementation of this method must /// always supply a value of NULL for the punkForRelease member of the /// STGMEDIUM structure to which this parameter points</param> public int GetDataHere(ref FORMATETC pFormatEtc, ref STGMEDIUM pMedium) { // For now we don't support this method. MFC uses the internal method // AfxCopyStgMedium to implement this -- if we absolutely positively // need to suppport this then we should base are implementation on // that code (source is the file atlmfc\src\mfc\olemisc.cpp) return HRESULT.E_NOTIMPL; }
/// <summary> /// Provides the source data object with data described by a FORMATETC /// structure and an STGMEDIUM structure /// </summary> /// <param name="pFormatEtc">Pointer to the FORMATETC structure defining the /// format used by the data object when interpreting the data contained in the /// storage medium</param> /// <param name="pMedium">Pointer to the STGMEDIUM structure defining the storage /// medium in which the data is being passed</param> /// <param name="fRelease">If TRUE, the data object called, which implements /// IDataObject::SetData, owns the storage medium after the call returns. This /// means it must free the medium after it has been used by calling the /// ReleaseStgMedium function. If FALSE, the caller retains ownership of the /// storage medium and the data object called uses the storage medium for the /// duration of the call only</param> public int SetData(ref FORMATETC pFormatEtc, ref STGMEDIUM pMedium, bool fRelease) { // check and see if we have an existing format of this type int dataFormatIndex; int result = FindDataFormat(ref pFormatEtc, out dataFormatIndex); // if we have an existing format of this type then free it and // remove it from the list if (result == HRESULT.S_OK) { OleDataEntry oleDataEntry = (OleDataEntry)oleDataEntries[dataFormatIndex]; Ole32.ReleaseStgMedium(ref oleDataEntry.stgm); oleDataEntries.RemoveAt(dataFormatIndex); } // create an entry to add to our internal list OleDataEntry dataEntry; // if the caller is releasing the data that is being set then just // copy bit for bit (we are now responsible for freeing the storage) if (fRelease) { dataEntry = new OleDataEntry(pFormatEtc, pMedium); } // if the caller is not releasing the data object to us then // we only get to use it for the duration of the call -- we need // to therefore clone the storage so that we have our own // copy/reference else { // attempt to clone the storage medium STGMEDIUM mediumClone = new STGMEDIUM(); result = CloneStgMedium(pMedium, ref mediumClone); if (result != HRESULT.S_OK) return result; // cloned it, initialize the data entry using the cloned storage dataEntry = new OleDataEntry(pFormatEtc, mediumClone); } // add the entry to our internal list oleDataEntries.Add(dataEntry); // return OK return HRESULT.S_OK; }
/// <summary> /// Create an OleStgMediumHandle that encapsulates the passed STGMEDIUM /// </summary> /// <param name="stg">Underlying STGMEDIUM</param> public OleStgMediumHandle(STGMEDIUM stg) : base(stg) { m_handle = stg.contents; }
/// <summary> /// Create an OleStgMedium that encapsulates the passed STGMEDIUM /// </summary> /// <param name="stg">Underlying STGMEDIUM</param> public OleStgMedium(STGMEDIUM stg) { m_stg = stg; }
/// <summary> /// Create an OleStgMediumHandle that encapsulates the passed STGMEDIUM /// </summary> /// <param name="stg">Underlying STGMEDIUM</param> public OleStgMediumENHMF(STGMEDIUM stg) : base(stg) { ValidateType(TYMED.ENHMF); }
/// <summary> /// Extract the date from within an OleDataObject. Pass in the requested /// clipboard format and type (or types ORed together) that you want /// the data in. The method will return an OleStgMedium for the type(s) /// requested if it is available, otherwise it will return null. /// If a single type is requested then the return value can be safely /// cast to the requested OleStgMedium subclasss. If multiple types /// are requested then the return value will represent the object's /// preferred storage representation and client code will need to use /// the 'is' operator to determine what type was returned. /// </summary> /// <param name="lindex">Index of item to retreive</param> /// <param name="clipFormat">Name of clipboard format requested</param> /// <param name="types">type(s) requested</param> /// <returns>OleStgMedium instance if format and requested storage type /// are available, otherwise null</returns> public OleStgMedium GetData(int lindex, string clipFormat, TYMED types) { // populate contents of FORMATETC structure FORMATETC formatEtc = new FORMATETC(); OleDataObjectHelper.PopulateFORMATETC(lindex, clipFormat, types, ref formatEtc); // attempt to get the data using the requested format STGMEDIUM stgMedium = new STGMEDIUM(); if (m_dataObject != null) { int result = m_dataObject.GetData(ref formatEtc, ref stgMedium); // check for errors if (result != HRESULT.S_OK) { // data format not supported (expected error condition) if (result == DV_E.FORMATETC) return null; // unexpected error condition else Marshal.ThrowExceptionForHR(result); } // return the correct OleStgMedium subclass depending upon the type switch (stgMedium.tymed) { case TYMED.NULL: return null; case TYMED.HGLOBAL: return new OleStgMediumHGLOBAL(stgMedium); case TYMED.FILE: return new OleStgMediumFILE(stgMedium); case TYMED.GDI: return new OleStgMediumGDI(stgMedium); case TYMED.MFPICT: return new OleStgMediumMFPICT(stgMedium); case TYMED.ENHMF: return new OleStgMediumENHMF(stgMedium); case TYMED.ISTREAM: return new OleStgMediumISTREAM(stgMedium); case TYMED.ISTORAGE: return new OleStgMediumISTORAGE(stgMedium); default: Debug.Assert(false, "Invalid TYMED value"); return null; } } else return null; }
public OleDataEntry(FORMATETC fmt, STGMEDIUM stg) { format = fmt; stgm = stg; }