Paste is essentially the same operation as checking pastability except that instead of calling IDataObject::QueryGetData we call IDataObject::GetData with the following steps:
Obtain a data object pointer by calling OleGetClipboard, which calls AddRef through the pointer before returning.
Call IDataObject::GetData to retrieve whatever data you want. As a consumer, you now own the data, so call ReleaseStgMedium when you finish with it. Also, you must not hold on to this data—copy it as necessary. This is no different from what is required with data obtained from the clipboard using GetClipboardData.
Call IDataObject::Release to match the AddRef called in OleGetClipboard.
Cosmo implements these steps in CCosmoDoc::Paste:
BOOL CCosmoDoc::Paste(HWND hWndFrame)
{
LPDATAOBJECT pIDataObject;
BOOL fRet;
if (FAILED(OleGetClipboard(&pIDataObject)))
return FALSE;
fRet=PasteFromData(pIDataObject);
pIDataObject->Release();
return fRet;
}
BOOL CCosmoDoc::PasteFromData(LPDATAOBJECT pIDataObject)
{
FORMATETC fe;
STGMEDIUM stm;
BOOL fRet;
SETDefFormatEtc(fe, m_cf, TYMED_HGLOBAL);
fRet=SUCCEEDED(pIDataObject->GetData(&fe, &stm));
if (fRet && NULL!=stm.hGlobal)
{
m_pPL->DataSetMem(stm.hGlobal, FALSE, FALSE, TRUE);
ReleaseStgMedium(&stm);
FDirtySet(TRUE);
}
return fRet;
}
As we did for Cosmo's FQueryPaste, Paste obtains the data object pointer from OleGetClipboard and passes it to PasteFromData. A function such as PasteFromData is reusable (like FQueryPasteFromData), and I encourage you to make such a function because it will become useful in later work.