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
|
#ifndef NULLSOFT_DISPATCHCALLBACK_H
#define NULLSOFT_DISPATCHCALLBACK_H
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
#pragma once
#endif
#include <windows.h>
#include <oleauto.h>
#include <vector>
typedef void (*DispatchCallbackNotifyFunc)(IDispatch* /*dispatch*/, void* /*param*/);
typedef void (*DispatchCallbackFreeFunc)(void* /*param*/);
class DispatchCallback
{
protected:
DispatchCallback();
~DispatchCallback();
public:
static HRESULT CreateInstance(IDispatch *dispatch,
DispatchCallback **instance);
public:
unsigned long AddRef();
unsigned long Release();
IDispatch *GetDispatch();
unsigned long GetThreadId();
HANDLE GetThreadHandle();
protected:
unsigned long ref;
IDispatch *dispatch;
unsigned long threadId;
HANDLE threadHandle;
};
class DispatchCallbackEnum
{
protected:
DispatchCallbackEnum();
~DispatchCallbackEnum();
public:
static HRESULT CreateInstance(DispatchCallback **objects,
size_t count,
DispatchCallbackEnum **instance);
public:
unsigned long AddRef();
unsigned long Release();
public:
HRESULT Next(DispatchCallback **buffer, size_t bufferMax, size_t *fetched);
HRESULT Reset(void);
HRESULT Skip(size_t count);
HRESULT GetCount(size_t *count);
HRESULT Notify(DispatchCallbackNotifyFunc notifyCb, DispatchCallbackFreeFunc freeCb, void *param);
protected:
unsigned long ref;
DispatchCallback **buffer;
size_t size;
size_t cursor;
};
class DispatchCallbackStore
{
public:
DispatchCallbackStore();
~DispatchCallbackStore();
public:
void Lock();
void Unlock();
CRITICAL_SECTION *GetLock();
HRESULT Register(IDispatch *dispatch);
HRESULT Unregister(IDispatch *dispatch);
void UnregisterAll();
HRESULT Enumerate(DispatchCallbackEnum **enumerator);
/* Helpers*/
HRESULT RegisterFromDispParam(DISPPARAMS *pdispparams, unsigned int position, unsigned int *puArgErr);
HRESULT UnregisterFromDispParam(DISPPARAMS *pdispparams, unsigned int position, unsigned int *puArgErr);
HRESULT Notify(DispatchCallbackNotifyFunc notifyCb, DispatchCallbackFreeFunc freeCb, void *param);
protected:
typedef std::vector<DispatchCallback*> CallbackList;
protected:
CRITICAL_SECTION lock;
CallbackList list;
};
/* Internals */
class DispatchCallbackApc
{
protected:
DispatchCallbackApc();
~DispatchCallbackApc();
public:
static HRESULT CreateInstance(DispatchCallbackNotifyFunc notifyCb,
DispatchCallbackFreeFunc freeCb,
void *param,
DispatchCallbackApc **instance);
public:
unsigned long AddRef();
unsigned long Release();
HRESULT Call(IDispatch *dispatch);
HRESULT Queue(HANDLE threadHandle, IDispatch *dispatch);
private:
static void CALLBACK QueueApcCallback(ULONG_PTR user);
protected:
unsigned long ref;
DispatchCallbackNotifyFunc notifyCb;
DispatchCallbackFreeFunc freeCb;
void *param;
};
class DispatchCallbackApcParam
{
public:
DispatchCallbackApcParam(IDispatch *dispatch, DispatchCallbackApc *apc);
~DispatchCallbackApcParam();
public:
IDispatch *GetDispatch();
DispatchCallbackApc *GetApc();
protected:
IDispatch *dispatch;
DispatchCallbackApc *apc;
};
#endif
|