-
Notifications
You must be signed in to change notification settings - Fork 31
/
RDPSessionEvents.h
executable file
·173 lines (164 loc) · 5.62 KB
/
RDPSessionEvents.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
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
/*
* RDPShare: Windows Desktop Sharing remote control interface
*
* Copyright 2016 Simul Piscator
*
* RDPShare is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* RDPShare is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with RDPShare. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef RDP_SESSION_EVENTS_H
#define RDP_SESSION_EVENTS_H
#include <RdpEncomAPI.h>
#include "Utils.h"
class RDPSessionEvents : public IDispatch
{
public:
RDPSessionEvents() : mRefCount(0) {}
virtual ~RDPSessionEvents() {}
protected:
virtual void OnError( HRESULT ) {}
virtual void OnViewerConnected() {}
virtual void OnViewerAuthenticated() {}
virtual void OnViewerConnectFailed() {}
virtual void OnViewerDisconnected() {}
virtual void OnSharedDesktopSettingsChanged( int w, int h, int c ) {}
virtual void OnSharedRectChanged(int, int, int, int) {}
virtual void OnWindowOpen(ComPtr<IRDPSRAPIWindow>) {}
virtual void OnWindowClose(ComPtr<IRDPSRAPIWindow>) {}
virtual void OnWindowUpdate(ComPtr<IRDPSRAPIWindow>) {}
virtual void OnAttendeeConnected(ComPtr<IRDPSRAPIAttendee>) {}
virtual void OnAttendeeDisconnected(ComPtr<IRDPSRAPIAttendee>) {}
virtual void OnAttendeeUpdate(ComPtr<IRDPSRAPIAttendee>) {}
virtual void OnControlLevelChangeRequest(ComPtr<IRDPSRAPIAttendee>, CTRL_LEVEL) {}
public:
HRESULT __stdcall QueryInterface( REFIID riid, void** pp) override
{
if (!pp)
return E_POINTER;
*pp = nullptr;
if (IsEqualIID(riid, DIID__IRDPSessionEvents))
*pp = static_cast<IDispatch*>(this);
if(IsEqualIID(riid, IID_IDispatch))
*pp = static_cast<IDispatch*>(this);
if (IsEqualIID(riid, IID_IUnknown))
*pp = static_cast<IUnknown*>(this);
if (!(*pp))
return E_NOINTERFACE;
this->AddRef();
return S_OK;
}
ULONG __stdcall AddRef() override { ++mRefCount; return 0; }
ULONG __stdcall Release() override { if (--mRefCount == 0) delete this; return 0; }
HRESULT __stdcall GetTypeInfoCount( UINT* ) override { return E_NOTIMPL; }
HRESULT __stdcall GetTypeInfo( UINT, LCID, ITypeInfo** ) override { return E_NOTIMPL; }
HRESULT __stdcall GetIDsOfNames( REFIID,LPOLESTR*,UINT,LCID ,DISPID* ) override { return E_NOTIMPL; }
HRESULT __stdcall Invoke( DISPID dispIdMember,REFIID,LCID,WORD,DISPPARAMS* pDispParams,VARIANT*,EXCEPINFO*,UINT* ) override
{
VARIANT var = { 0 };
HRESULT hr = S_OK;
switch (dispIdMember)
{
case DISPID_RDPSRAPI_EVENT_ON_ERROR:
hr = ::DispGetParam(pDispParams, 0, VT_I4, &var, nullptr);
OnError( var.intVal );
break;
case DISPID_RDPSRAPI_EVENT_ON_VIEWER_CONNECTED:
OnViewerConnected();
break;
case DISPID_RDPSRAPI_EVENT_ON_VIEWER_AUTHENTICATED:
OnViewerAuthenticated();
break;
case DISPID_RDPSRAPI_EVENT_ON_VIEWER_CONNECTFAILED:
OnViewerConnectFailed();
break;
case DISPID_RDPSRAPI_EVENT_ON_VIEWER_DISCONNECTED:
OnViewerDisconnected();
break;
case DISPID_RDPSRAPI_EVENT_ON_SHARED_DESKTOP_SETTINGS_CHANGED:
{
long args[3];
for (int i = 0; i < sizeof(args) / sizeof(*args); ++i)
{
hr = ::DispGetParam(pDispParams, i, VT_I4, &var, nullptr);
args[i] = var.intVal;
}
OnSharedDesktopSettingsChanged(args[0], args[1], args[2]);
} break;
case DISPID_RDPSRAPI_EVENT_ON_SHARED_RECT_CHANGED:
{
long args[4];
for (int i = 0; i < sizeof(args) / sizeof(*args); ++i)
{
hr = ::DispGetParam(pDispParams, i, VT_I4, &var, nullptr);
args[i] = var.intVal;
}
OnSharedRectChanged(args[0], args[1], args[2], args[3]);
} break;
case DISPID_RDPSRAPI_EVENT_ON_WINDOW_OPEN:
case DISPID_RDPSRAPI_EVENT_ON_WINDOW_CLOSE:
case DISPID_RDPSRAPI_EVENT_ON_WINDOW_UPDATE:
hr = ::DispGetParam(pDispParams, 0, VT_DISPATCH, &var, nullptr);
if (!FAILED(hr))
{
ComPtr<IRDPSRAPIWindow> p;
hr = var.pdispVal->QueryInterface(&p);
if (!FAILED(hr)) switch (dispIdMember)
{
case DISPID_RDPSRAPI_EVENT_ON_WINDOW_OPEN:
OnWindowOpen(p);
break;
case DISPID_RDPSRAPI_EVENT_ON_WINDOW_CLOSE:
OnWindowClose(p);
break;
case DISPID_RDPSRAPI_EVENT_ON_WINDOW_UPDATE:
OnWindowUpdate(p);
break;
}
}
break;
case DISPID_RDPSRAPI_EVENT_ON_ATTENDEE_CONNECTED:
case DISPID_RDPSRAPI_EVENT_ON_ATTENDEE_DISCONNECTED:
case DISPID_RDPSRAPI_EVENT_ON_ATTENDEE_UPDATE:
case DISPID_RDPSRAPI_EVENT_ON_CTRLLEVEL_CHANGE_REQUEST:
hr = ::DispGetParam(pDispParams, 0, VT_DISPATCH, &var, nullptr);
if (!FAILED(hr))
{
ComPtr<IRDPSRAPIAttendee> p;
hr = var.pdispVal->QueryInterface(&p);
if (!FAILED(hr)) switch (dispIdMember)
{
case DISPID_RDPSRAPI_EVENT_ON_ATTENDEE_CONNECTED:
OnAttendeeConnected(p);
break;
case DISPID_RDPSRAPI_EVENT_ON_ATTENDEE_DISCONNECTED:
OnAttendeeDisconnected(p);
break;
case DISPID_RDPSRAPI_EVENT_ON_ATTENDEE_UPDATE:
OnAttendeeUpdate(p);
break;
case DISPID_RDPSRAPI_EVENT_ON_CTRLLEVEL_CHANGE_REQUEST:
hr = ::DispGetParam(pDispParams, 1, VT_I4, &var, nullptr);
OnControlLevelChangeRequest(p, CTRL_LEVEL(var.intVal));
break;
}
}
break;
default:
;
}
return hr;
}
private:
int mRefCount;
};
#endif // RDP_SESSION_EVENTS_H