2
2
#include < assert.h>
3
3
#include < io.h>
4
4
5
+ static HANDLE ControlEvent = NULL ;
6
+
5
7
/* https://learn.microsoft.com/en-us/windows/console/clearing-the-screen */
6
8
static BOOL WceclConsoleClearScreen (
7
9
HANDLE hDevice)
@@ -90,6 +92,7 @@ static BOOL WceclConsoleSetMode(
90
92
{
91
93
if (nInBufSize < sizeof (DWORD))
92
94
{
95
+ SetLastError (ERROR_INSUFFICIENT_BUFFER);
93
96
return FALSE ;
94
97
}
95
98
return SetConsoleMode (
@@ -107,6 +110,7 @@ static BOOL WceclConsoleGetMode(
107
110
108
111
if (nOutBufSize < sizeof (DWORD))
109
112
{
113
+ SetLastError (ERROR_INSUFFICIENT_BUFFER);
110
114
return FALSE ;
111
115
}
112
116
result = GetConsoleMode (hDevice, &win32ConsoleMode);
@@ -156,6 +160,7 @@ static BOOL WceclConsoleGetRowsCols(
156
160
157
161
if (nOutBufSize < sizeof (DWORD))
158
162
{
163
+ SetLastError (ERROR_INSUFFICIENT_BUFFER);
159
164
return FALSE ;
160
165
}
161
166
@@ -180,7 +185,38 @@ static BOOL WceclConsoleGetRowsCols(
180
185
return TRUE ;
181
186
}
182
187
188
+ BOOL WceclConsoleSetControlHandler (PHANDLER_ROUTINE* pInBuffer, DWORD nInBufSize)
189
+ {
190
+ if (nInBufSize < sizeof (PHANDLER_ROUTINE))
191
+ {
192
+ SetLastError (ERROR_INSUFFICIENT_BUFFER);
193
+ return FALSE ;
194
+ }
195
+ return SetConsoleCtrlHandler (*pInBuffer, FALSE );
196
+ }
183
197
198
+ BOOL __stdcall WceclConsoleSignalControlEvent (DWORD ctrlType)
199
+ {
200
+ if (ControlEvent != NULL )
201
+ {
202
+ SetEvent (ControlEvent);
203
+
204
+ /* TODO: what should this return? */
205
+ return TRUE ;
206
+ }
207
+ return FALSE ;
208
+ }
209
+
210
+ BOOL WceclConsoleSetControlEvent (HANDLE* pInBuffer, DWORD nInBufSize)
211
+ {
212
+ if (nInBufSize < sizeof (HANDLE))
213
+ {
214
+ SetLastError (ERROR_INSUFFICIENT_BUFFER);
215
+ return FALSE ;
216
+ }
217
+ ControlEvent = *pInBuffer;
218
+ return SetConsoleCtrlHandler (WceclConsoleSignalControlEvent, FALSE );
219
+ }
184
220
BOOL WceclConsoleIoControl (
185
221
HANDLE hDevice,
186
222
DWORD dwIoControlCode,
@@ -209,9 +245,10 @@ BOOL WceclConsoleIoControl(
209
245
return WceclConsoleGetRowsCols (hDevice, NULL , (PDWORD)lpOutBuf, nOutBufSize);
210
246
case IOCTL_CONSOLE_GETSCREENCOLS:
211
247
return WceclConsoleGetRowsCols (hDevice, (PDWORD)lpOutBuf, NULL , nOutBufSize);
212
- default :
213
- /* TODO */
214
- return FALSE ;
248
+ case IOCTL_CONSOLE_SETCONTROLCHANDLER:
249
+ return WceclConsoleSetControlHandler ((PHANDLER_ROUTINE*)lpInBuf, nInBufSize);
250
+ case IOCTL_CONSOLE_SETCONTROLCEVENT:
251
+ return WceclConsoleSetControlEvent ((PHANDLE)lpInBuf, nInBufSize);
215
252
}
216
253
217
254
return FALSE ;
0 commit comments