# IDataObject::GetData

Called by a data consumer to obtain data from a source data object. The GetData method renders the data described in the specified FORMATETC structure and transfers it through the specified STGMEDIUM structure. The caller then assumes responsibility for releasing the STGMEDIUM structure.

HRESULT GetData(

FORMATETC * pFormatetc, | //Pointer to the FORMATETC structure
STGMEDIUM * pmedium | //Pointer to the STGMEDIUM structure
); |

Parameters

pFormatetc
  [in] 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.
pmedium
  [out] Pointer to the STGMEDIUMstructure 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 punkOuter 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.

Return Values

This method supports the standard return values E_INVALIDARG, E_UNEXPECTED, and E_OUTOFMEMORY, as well as the following:

S_OK
  Data was successfully retrieved and placed in the storage medium provided.
DV_E_LINDEX
  Invalid value for lindex; currently, only -1 is supported.
DV_E_FORMATETC
  Invalid value for pFormatetc.
DV_E_TYMED
  Invalid tymed value.
DV_E_DVASPECT
  Invalid dwAspect value.
OLE_E_NOTRUNNING
  Object application is not running.
STG_E_MEDIUMFULL
  An error occurred when allocating the medium.

Remarks

A data consumer calls IDataObject::GetData to retrieve data from a data object, conveyed through a storage medium (defined through the STGMEDIUM structure).

#### Notes to Callers

You can specify more than one acceptable TYMED medium with the Boolean OR operator. IDataObject::GetData must choose from the OR’d values the medium that best represents the data, do the allocation, and indicate responsibility for releasing the medium.

Data transferred across a stream extends from position zero of the stream pointer through to the position immediately before the current stream pointer (that is, the stream pointer position upon exit).

#### Notes to Implementers

IDataObject::GetData must check all fields in the FORMATETC structure. It is important that IDataObject::GetData render the requested aspect and, if possible, use the requested medium. If the data object cannot comply with the information specified in the FORMATETC, the method should return DV_E_FORMATETC. If an attempt to allocate the medium fails, the method should return STG_E_MEDIUMFULL. It is important to fill in all of the fields in the STGMEDIUM structure.

Although the caller can specify more than one medium for returning the data, IDataObject::GetData can supply only one medium. If the initial transfer fails with the selected medium, this method can be implemented to try one of the other media specified before returning an error.

See Also

IDataObject::GetDataHere, IDataObject::SetData, FORMATETC, STGMEDIUM