OleCreateStaticFromData returns a COM pointer which you pass to the Rich Edit control. This COM pointer has had an AddRef applied to it, so you must call Release once you have passed it to the control, to signify that you no longer will be accessing it directly. The control will also do a Release when it is destroyed which should result in the COM object being deleted.You might also store the returned pointer in a smart pointer class _com_ptr_t or CComPtr and it will Release it automatically.
HRESULT OleCreateStaticFromData( _In_ LPDATAOBJECT pSrcDataObj, _In_ REFIID iid, _In_ DWORD renderopt, _In_ LPFORMATETC pFormatEtc, _In_ LPOLECLIENTSITE pClientSite, _In_ LPSTORAGE pStg, _Out_ LPVOID *ppvObj );The pSrcDataObject is still valid after OleCreateStaticFromData returns. It is the caller's responsibility to free pSrcDataObject — OLE does not release it.
_In_ LPDATAOBJECT pSrcDataObj,
_In_ REFIID iid,
_In_ DWORD renderopt,
_In_ LPFORMATETC pFormatEtc,
_In_ LPOLECLIENTSITE pClientSite,
_In_ LPSTORAGE pStg,
_Out_ LPVOID *ppvObj
);The pSrcDataObject is still valid after OleCreateStaticFromData returns. It is the caller's responsibility to free pSrcDataObject — OLE does not release it.