-
Notifications
You must be signed in to change notification settings - Fork 1
/
eventproxy.h
98 lines (77 loc) · 2.43 KB
/
eventproxy.h
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
#pragma once
class Ball;
class EventProxyBase
{
public:
virtual HRESULT FireDispID(DISPID dispid, DISPPARAMS *pdispparams) = 0;
void FireVoidEvent(int dispid)
{
DISPPARAMS dispparams = { NULL, NULL, 0, 0 };
FireDispID(dispid, &dispparams);
}
void FireVoidEventParm(int dispid, float parm)
{
CComVariant rgvar[1] = { CComVariant(parm) };
DISPPARAMS dispparams = { rgvar, NULL, 1, 0 };
FireDispID(dispid, &dispparams);
}
void FireVoidEventParm(int dispid, int parm)
{
CComVariant rgvar[1] = { CComVariant(parm) };
DISPPARAMS dispparams = { rgvar, NULL, 1, 0 };
FireDispID(dispid, &dispparams);
}
/* void FireVoidEventParm(int dispid, unsigned int parm)
{
CComVariant rgvar[1] = { CComVariant(parm)};
DISPPARAMS dispparams = {rgvar,NULL,1,0};
FireDispID(dispid, &dispparams);
}
*/
void FireVoidEventParm(int dispid, char* parm)
{
CComVariant rgvar[1] = { CComVariant(parm) };
DISPPARAMS dispparams = { rgvar, NULL, 1, 0 };
FireDispID(dispid, &dispparams);
}
};
template <class T, const IID* psrcid>
class EventProxy : public EventProxyBase, public IConnectionPointImpl<T, psrcid, CComDynamicUnkArray>
{
public:
EventProxy() {}
virtual ~EventProxy() {}
void FireVoidGroupEvent(int dispid)
{
T* const pT = (T*)this;
for (size_t i = 0; i < pT->m_vEventCollection.size(); ++i)
{
Collection * const pcollection = pT->m_vEventCollection[i];
if (pcollection!=NULL)
{
CComVariant rgvar[1] = { CComVariant((long)pT->m_viEventCollection[i]) };
DISPPARAMS dispparams = { rgvar, NULL, 1, 0 };
pcollection->FireDispID(dispid, &dispparams);
}
}
if (pT->m_singleEvents)
FireVoidEvent(dispid);
}
virtual HRESULT FireDispID(DISPID dispid, DISPPARAMS *pdispparams)
{
T* const pT = (T*)this;
pT->Lock();
IUnknown** pp = IConnectionPointImpl<T, psrcid, CComDynamicUnkArray>::m_vec.begin();
while (pp < IConnectionPointImpl<T, psrcid, CComDynamicUnkArray>::m_vec.end())
{
if (*pp != NULL)
{
IDispatch* const pDispatch = reinterpret_cast<IDispatch*>(*pp);
pDispatch->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, pdispparams, NULL, NULL, NULL);
}
++pp;
}
pT->Unlock();
return S_OK;
}
};