-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathRetryIOleFilter.cpp
67 lines (54 loc) · 1.73 KB
/
RetryIOleFilter.cpp
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
#include <Windows.h>
#include <wrl/implements.h>
using namespace Microsoft::WRL;
// https://msdn.microsoft.com/en-us/library/ms228772.aspx
class MessageFilter : public RuntimeClass<RuntimeClassFlags<ClassicCom>, IMessageFilter>
{
//
// Class containing the IOleMessageFilter
// thread error-handling functions.
// Start the filter.
public:
// IOleMessageFilter functions.
// Handle incoming thread requests.
virtual DWORD STDMETHODCALLTYPE HandleInComingCall(DWORD dwCallType, HTASK htaskCaller, DWORD dwTickCount, LPINTERFACEINFO lpInterfaceInfo)
{
return SERVERCALL_ISHANDLED;
}
// Thread call was rejected, so try again.
virtual DWORD STDMETHODCALLTYPE RetryRejectedCall(HTASK htaskCallee, DWORD dwTickCount, DWORD dwRejectType)
{
if (dwRejectType == SERVERCALL_RETRYLATER)
{
// Retry the thread call immediately if return >=0 &
// <100.
return 99;
}
// Too busy; cancel call.
return -1;
}
virtual DWORD STDMETHODCALLTYPE MessagePending(_In_ HTASK htaskCallee, _In_ DWORD dwTickCount, _In_ DWORD dwPendingType)
{
//Return the flag .
return PENDINGMSG_WAITDEFPROCESS;
}
};
__declspec(dllexport) int __stdcall Register()
{
#pragma comment(linker, "/EXPORT:" __FUNCTION__ "=" __FUNCDNAME__)
ComPtr<MessageFilter> newFilter = Make<MessageFilter>();
IMessageFilter* oldFilter = nullptr;
CoRegisterMessageFilter(newFilter.Get(), &oldFilter);
if (oldFilter) {
oldFilter->Release();
}
return 0;
}
// Done with the filter, close it.
__declspec(dllexport) int __stdcall Revoke()
{
#pragma comment(linker, "/EXPORT:" __FUNCTION__ "=" __FUNCDNAME__)
ComPtr<IMessageFilter> oldFilter;
CoRegisterMessageFilter(nullptr, &oldFilter);
return 0;
}