Skip to content

Commit df55bb7

Browse files
TheNNXdz333n
authored andcommitted
Implement IOCTL_CONSOLE_SETCONTROLXXX codes
1 parent 81d257b commit df55bb7

File tree

1 file changed

+40
-3
lines changed

1 file changed

+40
-3
lines changed

COREDLL/stdio_wcecl.cpp

+40-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#include <assert.h>
33
#include <io.h>
44

5+
static HANDLE ControlEvent = NULL;
6+
57
/* https://learn.microsoft.com/en-us/windows/console/clearing-the-screen */
68
static BOOL WceclConsoleClearScreen(
79
HANDLE hDevice)
@@ -90,6 +92,7 @@ static BOOL WceclConsoleSetMode(
9092
{
9193
if (nInBufSize < sizeof(DWORD))
9294
{
95+
SetLastError(ERROR_INSUFFICIENT_BUFFER);
9396
return FALSE;
9497
}
9598
return SetConsoleMode(
@@ -107,6 +110,7 @@ static BOOL WceclConsoleGetMode(
107110

108111
if (nOutBufSize < sizeof(DWORD))
109112
{
113+
SetLastError(ERROR_INSUFFICIENT_BUFFER);
110114
return FALSE;
111115
}
112116
result = GetConsoleMode(hDevice, &win32ConsoleMode);
@@ -156,6 +160,7 @@ static BOOL WceclConsoleGetRowsCols(
156160

157161
if (nOutBufSize < sizeof(DWORD))
158162
{
163+
SetLastError(ERROR_INSUFFICIENT_BUFFER);
159164
return FALSE;
160165
}
161166

@@ -180,7 +185,38 @@ static BOOL WceclConsoleGetRowsCols(
180185
return TRUE;
181186
}
182187

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+
}
183197

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+
}
184220
BOOL WceclConsoleIoControl(
185221
HANDLE hDevice,
186222
DWORD dwIoControlCode,
@@ -209,9 +245,10 @@ BOOL WceclConsoleIoControl(
209245
return WceclConsoleGetRowsCols(hDevice, NULL, (PDWORD)lpOutBuf, nOutBufSize);
210246
case IOCTL_CONSOLE_GETSCREENCOLS:
211247
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);
215252
}
216253

217254
return FALSE;

0 commit comments

Comments
 (0)