5
#include "EnumFormatEtc.h"
13
MY_UNKNOWN_IMP1_MT(IEnumFORMATETC)
15
STDMETHOD(Next)(ULONG celt, FORMATETC *rgelt, ULONG *pceltFetched);
16
STDMETHOD(Skip)(ULONG celt);
17
STDMETHOD(Reset)(void);
18
STDMETHOD(Clone)(IEnumFORMATETC **ppEnumFormatEtc);
20
CEnumFormatEtc(const FORMATETC *pFormatEtc, ULONG numFormats);
30
static void DeepCopyFormatEtc(FORMATETC *dest, const FORMATETC *src)
35
dest->ptd = (DVTARGETDEVICE*)CoTaskMemAlloc(sizeof(DVTARGETDEVICE));
36
*(dest->ptd) = *(src->ptd);
40
CEnumFormatEtc::CEnumFormatEtc(const FORMATETC *pFormatEtc, ULONG numFormats)
45
m_Formats = new FORMATETC[numFormats];
48
m_NumFormats = numFormats;
49
for(ULONG i = 0; i < numFormats; i++)
50
DeepCopyFormatEtc(&m_Formats[i], &pFormatEtc[i]);
54
CEnumFormatEtc::~CEnumFormatEtc()
58
for(ULONG i = 0; i < m_NumFormats; i++)
60
CoTaskMemFree(m_Formats[i].ptd);
65
STDMETHODIMP CEnumFormatEtc::Next(ULONG celt, FORMATETC *pFormatEtc, ULONG *pceltFetched)
68
if(celt == 0 || pFormatEtc == 0)
70
while(m_Index < m_NumFormats && copied < celt)
72
DeepCopyFormatEtc(&pFormatEtc[copied], &m_Formats[m_Index]);
77
*pceltFetched = copied;
78
return (copied == celt) ? S_OK : S_FALSE;
81
STDMETHODIMP CEnumFormatEtc::Skip(ULONG celt)
84
return (m_Index <= m_NumFormats) ? S_OK : S_FALSE;
87
STDMETHODIMP CEnumFormatEtc::Reset(void)
93
STDMETHODIMP CEnumFormatEtc::Clone(IEnumFORMATETC ** ppEnumFormatEtc)
95
HRESULT hResult = CreateEnumFormatEtc(m_NumFormats, m_Formats, ppEnumFormatEtc);
97
((CEnumFormatEtc *)*ppEnumFormatEtc)->m_Index = m_Index;
101
// replacement for SHCreateStdEnumFmtEtc
102
HRESULT CreateEnumFormatEtc(UINT numFormats, const FORMATETC *formats, IEnumFORMATETC **enumFormat)
104
if(numFormats == 0 || formats == 0 || enumFormat == 0)
106
*enumFormat = new CEnumFormatEtc(formats, numFormats);
107
return (*enumFormat) ? S_OK : E_OUTOFMEMORY;