-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwbienumformatetc.c
More file actions
194 lines (148 loc) · 4.08 KB
/
wbienumformatetc.c
File metadata and controls
194 lines (148 loc) · 4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#include "wbded.h"
static FORMATETC *formats;
static int nformats;
static void DeepCopyFormatEtc(FORMATETC *dest, FORMATETC *source)
{
// copy the source FORMATETC into dest
*dest = *source;
if(source->ptd)
{
// allocate memory for the DVTARGETDEVICE if necessary
dest->ptd = (DVTARGETDEVICE*)CoTaskMemAlloc(sizeof(DVTARGETDEVICE));
// copy the contents of the source DVTARGETDEVICE into dest->ptd
*(dest->ptd) = *(source->ptd);
}
}
HRESULT CreateEnumFormatEtc(UINT nNumFormats, FORMATETC *pFormatEtc, WB_IEnumFORMATETC **ppEnumFormatEtc)
{
if(nNumFormats == 0 || pFormatEtc == 0 || ppEnumFormatEtc == 0)
return E_INVALIDARG;
*ppEnumFormatEtc = WB_IEnumFORMATETC_new(nNumFormats, pFormatEtc);
// CEnumFormatEtc(pFormatEtc, nNumFormats);
// (*ppEnumFormatEtc)->m_pFormatEtc = pFormatEtc;
return (*ppEnumFormatEtc) ? S_OK : E_OUTOFMEMORY;
}
static ULONG STDMETHODCALLTYPE
ienumformatetc_addref (WB_IEnumFORMATETC* This)
{
WB_IEnumFORMATETC *en = This;
// int ref_count = ++en->ref_count;
return InterlockedIncrement(&This->m_lRefCount);
}
static HRESULT STDMETHODCALLTYPE
ienumformatetc_queryinterface (WB_IEnumFORMATETC *This,
REFIID riid,
LPVOID *ppvObject)
{
*ppvObject = NULL;
// PRINT_GUID (riid);
if (IsEqualGUID (riid, &IID_IUnknown))
{
ienumformatetc_addref (This);
*ppvObject = This;
return S_OK;
}
else if (IsEqualGUID (riid, &IID_IEnumFORMATETC))
{
ienumformatetc_addref (This);
*ppvObject = This;
return S_OK;
}
else
{
return E_NOINTERFACE;
}
}
static ULONG STDMETHODCALLTYPE
ienumformatetc_release (WB_IEnumFORMATETC* This)
{
LONG count = InterlockedDecrement(&This->m_lRefCount);
if(count == 0)
{
g_free(This);
return 0;
}
else
{
return count;
}
}
static HRESULT STDMETHODCALLTYPE
ienumformatetc_next (WB_IEnumFORMATETC* This,
ULONG celt,
LPFORMATETC pFormatEtc,
ULONG *pceltFetched)
{
ULONG copied = 0;
// MessageBox(0,"ienumformatetc_next","davide",MB_OK);
if(celt == 0 || pFormatEtc == 0)
return E_INVALIDARG;
while(This->m_nIndex < This->m_nNumFormats && copied < celt)
{
DeepCopyFormatEtc((struct tagFORMATETC*)&pFormatEtc[copied], &This->m_pFormatEtc[This->m_nIndex]);
copied++;
This->m_nIndex++;
}
if(pceltFetched != 0)
*pceltFetched = copied;
// did we copy all that was requested?
return (copied == celt) ? S_OK : S_FALSE;
}
static HRESULT STDMETHODCALLTYPE
ienumformatetc_skip (WB_IEnumFORMATETC *This,
ULONG celt)
{
WB_IEnumFORMATETC *en = This;
en->m_nIndex += celt;
return (en->m_nIndex <= en->m_nNumFormats) ? S_OK : S_FALSE;
return S_OK;
}
static HRESULT STDMETHODCALLTYPE
ienumformatetc_reset (WB_IEnumFORMATETC* This)
{
WB_IEnumFORMATETC *en = This;
en->ix = 0;
en->m_nIndex = 0;
// MessageBox(0,"ienumformatetc_reset","davide",MB_OK);
return S_OK;
}
static HRESULT STDMETHODCALLTYPE
ienumformatetc_clone (WB_IEnumFORMATETC* This,
LPWBFORMATETC *ppEnumFormatEtc)
{
WB_IEnumFORMATETC *en = This;
WB_IEnumFORMATETC *newIEnumFORMATETC;
newIEnumFORMATETC = WB_IEnumFORMATETC_new (en->m_nNumFormats, en->m_pFormatEtc);
*ppEnumFormatEtc = newIEnumFORMATETC;
(*ppEnumFormatEtc)->m_nIndex = en->m_nIndex;
return S_OK;
}
static WB_IEnumFORMATETCVtbl ief_vtbl = {
ienumformatetc_queryinterface,
ienumformatetc_addref,
ienumformatetc_release,
ienumformatetc_next,
ienumformatetc_skip,
ienumformatetc_reset,
ienumformatetc_clone
};
WB_IEnumFORMATETC *
WB_IEnumFORMATETC_new (UINT nNumFormats, FORMATETC *pFormatEtc)
{
int i = 0;
WB_IEnumFORMATETC *result;
result = g_new0 (WB_IEnumFORMATETC, 1);
(struct WB_IEnumFORMATETCVtbl*)result->ief.lpVtbl = &ief_vtbl;
result->ref_count = 1;
result->ix = 1;
result->m_nIndex = 0;
result->m_lRefCount = 1;
result->m_nNumFormats = nNumFormats;
result->m_pFormatEtc = g_new0(FORMATETC, nNumFormats);
result->m_pFormatEtc = pFormatEtc;
for(i = 0; i < (int)result->m_nNumFormats; i++)
{
DeepCopyFormatEtc(&result->m_pFormatEtc[i], &pFormatEtc[i]);
}
return result;
}