/// <summary> /// Transfers data to the object that implements this method. This method is called by an object that /// contains a data source.</summary> /// <param name="formatIn">A FORMATETC structure, passed by reference, that defines the format used /// by the data object when interpreting the data contained in the storage medium.</param> /// <param name="medium">A STGMEDIUM structure, passed by reference, that defines the storage medium /// in which the data is being passed.</param> /// <param name="release">true to specify that the data object called, which implements SetData(), /// owns the storage medium after the call returns. This means that the data object must free the /// medium after it has been used by calling the ReleaseStgMedium function. false to specify that 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 void SetData(ref FORMATETC formatIn, ref STGMEDIUM medium, bool release) { // If the format exists in our storage, remove it prior to resetting it for (var i = 0; i < m_oleStorage.Count; ++i) { var pair = m_oleStorage[i]; var format = pair.Format; if (IsFormatCompatible(ref formatIn, ref format)) { var releaseMedium = pair.Medium; ReleaseStgMedium(ref releaseMedium); m_oleStorage.Remove(pair); break; } } // If release is true, we'll take ownership of the medium. // If not, we'll make a copy of it. var sm = medium; if (!release) { sm = CopyMedium(ref medium); } // Add it to the internal storage var data = new OleData { Format = formatIn, Medium = sm }; m_oleStorage.Add(data); RaiseDataChanged(ref data); }
/// <summary> /// Raises the DataChanged event for any advisory connections that /// are listening for it. /// </summary> private void RaiseDataChanged(ref OleData dataEntry) { foreach (var connection in m_connections) { if (IsFormatCompatible(connection.Value.Format, dataEntry.Format)) { RaiseDataChanged(connection.Key, ref dataEntry); } } }
/// <summary> /// Raises the DataChanged event for the specified connection. /// </summary> private void RaiseDataChanged(int connection, ref OleData dataEntry) { var adviseEntry = m_connections[connection]; var format = dataEntry.Format; var medium = (adviseEntry.Advf & ADVF.ADVF_NODATA) != ADVF.ADVF_NODATA ? dataEntry.Medium : default(STGMEDIUM); adviseEntry.Sink.OnDataChange(ref format, ref medium); if ((adviseEntry.Advf & ADVF.ADVF_ONLYONCE) == ADVF.ADVF_ONLYONCE) { m_connections.Remove(connection); } }
private bool GetDataEntry(ref FORMATETC pFormatetc, out OleData dataEntry) { for (var i = 0; i < m_oleStorage.Count; ++i) { var entry = m_oleStorage[i]; var format = entry.Format; if (IsFormatCompatible(ref pFormatetc, ref format)) { dataEntry = entry; return(true); } } dataEntry = default(OleData); return(false); }
/// <summary> /// Raises the DataChanged event for any advisory connections that /// are listening for it. /// </summary> private void RaiseDataChanged(ref OleData dataEntry) { foreach (var connection in m_connections) { if (IsFormatCompatible(connection.Value.Format, dataEntry.Format)) RaiseDataChanged(connection.Key, ref dataEntry); } }
private bool GetDataEntry(ref FORMATETC pFormatetc, out OleData dataEntry) { for (var i = 0; i < m_oleStorage.Count; ++i) { var entry = m_oleStorage[i]; var format = entry.Format; if (IsFormatCompatible(ref pFormatetc, ref format)) { dataEntry = entry; return true; } } dataEntry = default(OleData); return false; }