Skip to content

Commit

Permalink
Implement IOCTL_CONSOLE_SETCONTROLXXX codes
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNNX authored and dz333n committed Apr 14, 2024
1 parent 81d257b commit df55bb7
Showing 1 changed file with 40 additions and 3 deletions.
43 changes: 40 additions & 3 deletions COREDLL/stdio_wcecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include <assert.h>
#include <io.h>

static HANDLE ControlEvent = NULL;

/* https://learn.microsoft.com/en-us/windows/console/clearing-the-screen */
static BOOL WceclConsoleClearScreen(
HANDLE hDevice)
Expand Down Expand Up @@ -90,6 +92,7 @@ static BOOL WceclConsoleSetMode(
{
if (nInBufSize < sizeof(DWORD))
{
SetLastError(ERROR_INSUFFICIENT_BUFFER);
return FALSE;
}
return SetConsoleMode(
Expand All @@ -107,6 +110,7 @@ static BOOL WceclConsoleGetMode(

if (nOutBufSize < sizeof(DWORD))
{
SetLastError(ERROR_INSUFFICIENT_BUFFER);
return FALSE;
}
result = GetConsoleMode(hDevice, &win32ConsoleMode);
Expand Down Expand Up @@ -156,6 +160,7 @@ static BOOL WceclConsoleGetRowsCols(

if (nOutBufSize < sizeof(DWORD))
{
SetLastError(ERROR_INSUFFICIENT_BUFFER);
return FALSE;
}

Expand All @@ -180,7 +185,38 @@ static BOOL WceclConsoleGetRowsCols(
return TRUE;
}

BOOL WceclConsoleSetControlHandler(PHANDLER_ROUTINE* pInBuffer, DWORD nInBufSize)
{
if (nInBufSize < sizeof(PHANDLER_ROUTINE))
{
SetLastError(ERROR_INSUFFICIENT_BUFFER);
return FALSE;
}
return SetConsoleCtrlHandler(*pInBuffer, FALSE);
}

BOOL __stdcall WceclConsoleSignalControlEvent(DWORD ctrlType)
{
if (ControlEvent != NULL)
{
SetEvent(ControlEvent);

/* TODO: what should this return? */
return TRUE;
}
return FALSE;
}

BOOL WceclConsoleSetControlEvent(HANDLE* pInBuffer, DWORD nInBufSize)
{
if (nInBufSize < sizeof(HANDLE))
{
SetLastError(ERROR_INSUFFICIENT_BUFFER);
return FALSE;
}
ControlEvent = *pInBuffer;
return SetConsoleCtrlHandler(WceclConsoleSignalControlEvent, FALSE);
}
BOOL WceclConsoleIoControl(
HANDLE hDevice,
DWORD dwIoControlCode,
Expand Down Expand Up @@ -209,9 +245,10 @@ BOOL WceclConsoleIoControl(
return WceclConsoleGetRowsCols(hDevice, NULL, (PDWORD)lpOutBuf, nOutBufSize);
case IOCTL_CONSOLE_GETSCREENCOLS:
return WceclConsoleGetRowsCols(hDevice, (PDWORD)lpOutBuf, NULL, nOutBufSize);
default:
/* TODO */
return FALSE;
case IOCTL_CONSOLE_SETCONTROLCHANDLER:
return WceclConsoleSetControlHandler((PHANDLER_ROUTINE*)lpInBuf, nInBufSize);
case IOCTL_CONSOLE_SETCONTROLCEVENT:
return WceclConsoleSetControlEvent((PHANDLE)lpInBuf, nInBufSize);
}

return FALSE;
Expand Down

0 comments on commit df55bb7

Please sign in to comment.