2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: dll/win32/kernel32/client/console/console.c
5 * PURPOSE: Win32 server console functions
6 * PROGRAMMERS: James Tabor <jimtabor@adsl-64-217-116-74.dsl.hstntx.swbell.net>
7 * Hermes Belusca-Maito (hermes.belusca@sfr.fr)
10 /* INCLUDES *******************************************************************/
18 /* GLOBALS ********************************************************************/
20 extern RTL_CRITICAL_SECTION ConsoleLock
;
21 extern BOOLEAN ConsoleInitialized
;
23 /* Console reserved "file" names */
24 static LPCWSTR BaseConFileName
= CONSOLE_FILE_NAME
;
25 static LPCWSTR BaseConInputFileName
= CONSOLE_INPUT_FILE_NAME
;
26 static LPCWSTR BaseConOutputFileName
= CONSOLE_OUTPUT_FILE_NAME
;
28 /* Console Control handling */
29 static PHANDLER_ROUTINE InitialHandler
[1];
30 static PHANDLER_ROUTINE
* CtrlHandlers
;
31 static ULONG NrCtrlHandlers
;
32 static ULONG NrAllocatedHandlers
;
33 static BOOLEAN LastCloseNotify
= FALSE
;
35 extern BOOL WINAPI
IsDebuggerPresent(VOID
);
37 /* Console Input facilities */
38 HANDLE InputWaitHandle
= INVALID_HANDLE_VALUE
;
40 #define EXENAME_LENGTH 255 + 1
41 static RTL_CRITICAL_SECTION ExeNameLock
;
42 static BOOLEAN ExeNameInitialized
;
43 static WCHAR ExeNameBuffer
[EXENAME_LENGTH
]; // NULL-terminated
44 static USHORT ExeNameLength
; // Count in number of characters without NULL
45 static WCHAR StartDirBuffer
[MAX_PATH
+ 1]; // NULL-terminated
46 static USHORT StartDirLength
; // Count in number of characters without NULL
49 /* Default Console Control Handler ********************************************/
53 DefaultConsoleCtrlHandler(DWORD Event
)
55 DPRINT("Default handler called: %lx\n", Event
);
59 DPRINT("Ctrl-C Event\n");
62 case CTRL_BREAK_EVENT
:
63 DPRINT("Ctrl-Break Event\n");
66 case CTRL_CLOSE_EVENT
:
67 DPRINT("Ctrl Close Event\n");
70 case CTRL_LAST_CLOSE_EVENT
:
71 DPRINT("Ctrl Last Close Event\n");
74 case CTRL_LOGOFF_EVENT
:
75 DPRINT("Ctrl Logoff Event\n");
78 case CTRL_SHUTDOWN_EVENT
:
79 DPRINT("Ctrl Shutdown Event\n");
83 ExitProcess(CONTROL_C_EXIT
);
89 ConsoleControlDispatcher(IN LPVOID lpThreadParameter
)
92 DWORD CodeAndFlag
= PtrToUlong(lpThreadParameter
);
93 DWORD nCode
= CodeAndFlag
& MAXLONG
;
95 EXCEPTION_RECORD erException
;
97 DPRINT1("Console Dispatcher Active: %lx %lx\n", CodeAndFlag
, nCode
);
98 SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST
);
103 case CTRL_BREAK_EVENT
:
105 if (IsDebuggerPresent())
107 erException
.ExceptionCode
= (nCode
== CTRL_C_EVENT
?
108 DBG_CONTROL_C
: DBG_CONTROL_BREAK
);
109 erException
.ExceptionFlags
= 0;
110 erException
.ExceptionRecord
= NULL
;
111 erException
.ExceptionAddress
= DefaultConsoleCtrlHandler
;
112 erException
.NumberParameters
= 0;
116 RtlRaiseException(&erException
);
118 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
120 RtlEnterCriticalSection(&ConsoleLock
);
122 if ((nCode
!= CTRL_C_EVENT
) ||
123 (NtCurrentPeb()->ProcessParameters
->ConsoleFlags
!= 1))
125 for (i
= NrCtrlHandlers
; i
> 0; i
--)
127 if (CtrlHandlers
[i
- 1](nCode
)) break;
131 RtlLeaveCriticalSection(&ConsoleLock
);
140 case CTRL_CLOSE_EVENT
:
141 case CTRL_LOGOFF_EVENT
:
142 case CTRL_SHUTDOWN_EVENT
:
145 case CTRL_LAST_CLOSE_EVENT
:
147 * In case the console app hasn't register for last close notification,
148 * just kill this console handler thread. We don't want that such apps
149 * get killed for unexpected reasons. On the contrary apps that registered
150 * can be killed because they expect to be.
152 if (!LastCloseNotify
) ExitThread(0);
156 ExitProcess(CONTROL_C_EXIT
);
164 ASSERT(ConsoleInitialized
);
166 RtlEnterCriticalSection(&ConsoleLock
);
169 if ((nCode
!= CTRL_C_EVENT
) || (NtCurrentPeb()->ProcessParameters
->ConsoleFlags
!= 1))
171 for (i
= NrCtrlHandlers
; i
> 0; i
--)
174 (CodeAndFlag
& MINLONG
) &&
175 ((nCode
== CTRL_LOGOFF_EVENT
) || (nCode
== CTRL_SHUTDOWN_EVENT
)))
177 DPRINT("Skipping system/service apps\n");
181 if (CtrlHandlers
[i
- 1](nCode
))
185 case CTRL_CLOSE_EVENT
:
186 case CTRL_LAST_CLOSE_EVENT
:
187 case CTRL_LOGOFF_EVENT
:
188 case CTRL_SHUTDOWN_EVENT
:
189 nExitCode
= CodeAndFlag
;
197 RtlLeaveCriticalSection(&ConsoleLock
);
199 ExitThread(nExitCode
);
200 return STATUS_SUCCESS
;
204 InitializeCtrlHandling(VOID
)
206 /* Initialize Console Ctrl Handler */
207 NrAllocatedHandlers
= NrCtrlHandlers
= 1;
208 CtrlHandlers
= InitialHandler
;
209 CtrlHandlers
[0] = DefaultConsoleCtrlHandler
;
213 /* Input EXE Name Support *****************************************************/
219 PPEB Peb
= NtCurrentPeb();
220 PCURDIR CurrentDirectory
= &Peb
->ProcessParameters
->CurrentDirectory
;
221 PLDR_DATA_TABLE_ENTRY ImageEntry
;
223 if (ExeNameInitialized
) return;
225 /* Initialize the EXE name lock */
226 Status
= RtlInitializeCriticalSection(&ExeNameLock
);
227 if (!NT_SUCCESS(Status
)) return;
228 ExeNameInitialized
= TRUE
;
230 ImageEntry
= CONTAINING_RECORD(Peb
->Ldr
->InLoadOrderModuleList
.Flink
,
231 LDR_DATA_TABLE_ENTRY
,
234 /* Retrieve the EXE name, NULL-terminate it... */
235 ExeNameLength
= min(sizeof(ExeNameBuffer
)/sizeof(ExeNameBuffer
[0]),
236 ImageEntry
->BaseDllName
.Length
/ sizeof(WCHAR
));
237 RtlCopyMemory(ExeNameBuffer
,
238 ImageEntry
->BaseDllName
.Buffer
,
239 ImageEntry
->BaseDllName
.Length
);
240 ExeNameBuffer
[ExeNameLength
] = UNICODE_NULL
;
242 /* ... and retrieve the current directory path and NULL-terminate it. */
243 StartDirLength
= min(sizeof(StartDirBuffer
)/sizeof(StartDirBuffer
[0]),
244 CurrentDirectory
->DosPath
.Length
/ sizeof(WCHAR
));
245 RtlCopyMemory(StartDirBuffer
,
246 CurrentDirectory
->DosPath
.Buffer
,
247 CurrentDirectory
->DosPath
.Length
);
248 StartDirBuffer
[StartDirLength
] = UNICODE_NULL
;
253 * The "LPDWORD Length" parameters point on input to the maximum size of
254 * the buffers that can hold data (if != 0), and on output they hold the
255 * real size of the data. If "Length" are == 0 on input, then on output
256 * they receive the full size of the data.
257 * The "LPWSTR* String" parameters have a double meaning:
258 * - when "CaptureStrings" is TRUE, data is copied to the buffers pointed
259 * by the pointers (*String).
260 * - when "CaptureStrings" is FALSE, "*String" are set to the addresses of
264 SetUpAppName(IN BOOLEAN CaptureStrings
,
265 IN OUT LPDWORD CurDirLength
,
266 IN OUT LPWSTR
* CurDir
,
267 IN OUT LPDWORD AppNameLength
,
268 IN OUT LPWSTR
* AppName
)
272 /* Retrieve the needed buffer size */
273 Length
= (StartDirLength
+ 1) * sizeof(WCHAR
);
274 if (*CurDirLength
> 0) Length
= min(Length
, *CurDirLength
);
275 *CurDirLength
= Length
;
277 /* Capture the data if needed, or, return a pointer to it */
281 * Length is always >= sizeof(WCHAR). Copy everything but the
282 * possible trailing NULL character, and then NULL-terminate.
284 Length
-= sizeof(WCHAR
);
285 RtlCopyMemory(*CurDir
, StartDirBuffer
, Length
);
286 (*CurDir
)[Length
/ sizeof(WCHAR
)] = UNICODE_NULL
;
290 *CurDir
= StartDirBuffer
;
293 /* Retrieve the needed buffer size */
294 Length
= (ExeNameLength
+ 1) * sizeof(WCHAR
);
295 if (*AppNameLength
> 0) Length
= min(Length
, *AppNameLength
);
296 *AppNameLength
= Length
;
298 /* Capture the data if needed, or, return a pointer to it */
302 * Length is always >= sizeof(WCHAR). Copy everything but the
303 * possible trailing NULL character, and then NULL-terminate.
305 Length
-= sizeof(WCHAR
);
306 RtlCopyMemory(*AppName
, ExeNameBuffer
, Length
);
307 (*AppName
)[Length
/ sizeof(WCHAR
)] = UNICODE_NULL
;
311 *AppName
= ExeNameBuffer
;
316 GetCurrentExeName(OUT PWCHAR ExeName
,
317 IN USHORT BufferSize
)
321 if (ExeNameInitialized
)
323 RtlEnterCriticalSection(&ExeNameLock
);
325 if (BufferSize
> ExeNameLength
* sizeof(WCHAR
))
326 BufferSize
= ExeNameLength
* sizeof(WCHAR
);
328 RtlCopyMemory(ExeName
, ExeNameBuffer
, BufferSize
);
330 RtlLeaveCriticalSection(&ExeNameLock
);
331 ExeLength
= BufferSize
;
335 *ExeName
= UNICODE_NULL
;
342 /* FUNCTIONS ******************************************************************/
345 IntCheckForConsoleFileName(IN LPCWSTR pszName
,
346 IN DWORD dwDesiredAccess
)
348 LPCWSTR ConsoleName
= pszName
;
349 ULONG DeviceNameInfo
;
352 * Check whether we deal with a DOS device, and if so,
353 * strip the path till the file name.
354 * Therefore, things like \\.\CON or C:\some_path\CONIN$
355 * are transformed into CON or CONIN$, for example.
357 DeviceNameInfo
= RtlIsDosDeviceName_U(pszName
);
358 if (DeviceNameInfo
!= 0)
360 ConsoleName
= (LPCWSTR
)((ULONG_PTR
)ConsoleName
+ ((DeviceNameInfo
>> 16) & 0xFFFF));
363 /* Return a standard console "file" name according to what we passed in parameters */
364 if (_wcsicmp(ConsoleName
, BaseConInputFileName
) == 0)
366 return BaseConInputFileName
;
368 else if (_wcsicmp(ConsoleName
, BaseConOutputFileName
) == 0)
370 return BaseConOutputFileName
;
372 else if (_wcsicmp(ConsoleName
, BaseConFileName
) == 0)
374 if ((dwDesiredAccess
& (GENERIC_READ
| GENERIC_WRITE
)) == GENERIC_READ
)
376 return BaseConInputFileName
;
378 else if ((dwDesiredAccess
& (GENERIC_READ
| GENERIC_WRITE
)) == GENERIC_WRITE
)
380 return BaseConOutputFileName
;
384 /* If we are there, that means that either the file name or the desired access are wrong */
390 * @implemented (Undocumented)
391 * @note See http://undoc.airesoft.co.uk/kernel32.dll/ConsoleMenuControl.php
396 ConsoleMenuControl(HANDLE hConsoleOutput
,
400 CONSOLE_API_MESSAGE ApiMessage
;
401 PCONSOLE_MENUCONTROL MenuControlRequest
= &ApiMessage
.Data
.MenuControlRequest
;
403 MenuControlRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
404 MenuControlRequest
->OutputHandle
= hConsoleOutput
;
405 MenuControlRequest
->CmdIdLow
= dwCmdIdLow
;
406 MenuControlRequest
->CmdIdHigh
= dwCmdIdHigh
;
407 MenuControlRequest
->MenuHandle
= NULL
;
409 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
411 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepMenuControl
),
412 sizeof(*MenuControlRequest
));
414 return MenuControlRequest
->MenuHandle
;
424 DuplicateConsoleHandle(HANDLE hConsole
,
425 DWORD dwDesiredAccess
,
429 CONSOLE_API_MESSAGE ApiMessage
;
430 PCONSOLE_DUPLICATEHANDLE DuplicateHandleRequest
= &ApiMessage
.Data
.DuplicateHandleRequest
;
432 if ( (dwOptions
& ~(DUPLICATE_CLOSE_SOURCE
| DUPLICATE_SAME_ACCESS
)) ||
433 (!(dwOptions
& DUPLICATE_SAME_ACCESS
) &&
434 (dwDesiredAccess
& ~(GENERIC_READ
| GENERIC_WRITE
))) )
436 SetLastError(ERROR_INVALID_PARAMETER
);
437 return INVALID_HANDLE_VALUE
;
440 DuplicateHandleRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
441 DuplicateHandleRequest
->SourceHandle
= hConsole
;
442 DuplicateHandleRequest
->DesiredAccess
= dwDesiredAccess
;
443 DuplicateHandleRequest
->InheritHandle
= bInheritHandle
;
444 DuplicateHandleRequest
->Options
= dwOptions
;
446 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
448 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepDuplicateHandle
),
449 sizeof(*DuplicateHandleRequest
));
450 if (!NT_SUCCESS(ApiMessage
.Status
))
452 BaseSetLastNTError(ApiMessage
.Status
);
453 return INVALID_HANDLE_VALUE
;
456 return DuplicateHandleRequest
->TargetHandle
;
465 GetConsoleHandleInformation(IN HANDLE hHandle
,
466 OUT LPDWORD lpdwFlags
)
468 CONSOLE_API_MESSAGE ApiMessage
;
469 PCONSOLE_GETHANDLEINFO GetHandleInfoRequest
= &ApiMessage
.Data
.GetHandleInfoRequest
;
471 GetHandleInfoRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
472 GetHandleInfoRequest
->Handle
= hHandle
;
474 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
476 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetHandleInformation
),
477 sizeof(*GetHandleInfoRequest
));
478 if (!NT_SUCCESS(ApiMessage
.Status
))
480 BaseSetLastNTError(ApiMessage
.Status
);
484 *lpdwFlags
= GetHandleInfoRequest
->Flags
;
495 SetConsoleHandleInformation(IN HANDLE hHandle
,
499 CONSOLE_API_MESSAGE ApiMessage
;
500 PCONSOLE_SETHANDLEINFO SetHandleInfoRequest
= &ApiMessage
.Data
.SetHandleInfoRequest
;
502 SetHandleInfoRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
503 SetHandleInfoRequest
->Handle
= hHandle
;
504 SetHandleInfoRequest
->Mask
= dwMask
;
505 SetHandleInfoRequest
->Flags
= dwFlags
;
507 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
509 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetHandleInformation
),
510 sizeof(*SetHandleInfoRequest
));
511 if (!NT_SUCCESS(ApiMessage
.Status
))
513 BaseSetLastNTError(ApiMessage
.Status
);
526 GetConsoleDisplayMode(LPDWORD lpModeFlags
)
528 CONSOLE_API_MESSAGE ApiMessage
;
529 PCONSOLE_GETDISPLAYMODE GetDisplayModeRequest
= &ApiMessage
.Data
.GetDisplayModeRequest
;
531 if (lpModeFlags
== NULL
)
533 SetLastError(ERROR_INVALID_PARAMETER
);
537 GetDisplayModeRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
539 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
541 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetDisplayMode
),
542 sizeof(*GetDisplayModeRequest
));
543 if (!NT_SUCCESS(ApiMessage
.Status
))
545 BaseSetLastNTError(ApiMessage
.Status
);
549 *lpModeFlags
= GetDisplayModeRequest
->DisplayMode
; // ModeFlags
556 * @unimplemented (Undocumented)
560 GetConsoleFontInfo(HANDLE hConsoleOutput
,
563 PCONSOLE_FONT_INFO lpConsoleFontInfo
)
565 DPRINT1("GetConsoleFontInfo(0x%p, %d, %lu, 0x%p) UNIMPLEMENTED!\n", hConsoleOutput
, bMaximumWindow
, nFontCount
, lpConsoleFontInfo
);
566 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
577 GetConsoleFontSize(HANDLE hConsoleOutput
,
580 COORD Empty
= {0, 0};
581 DPRINT1("GetConsoleFontSize(0x%p, 0x%x) UNIMPLEMENTED!\n", hConsoleOutput
, nFont
);
582 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
588 * @implemented (Undocumented)
592 GetConsoleHardwareState(HANDLE hConsoleOutput
,
596 CONSOLE_API_MESSAGE ApiMessage
;
597 PCONSOLE_GETSETHWSTATE HardwareStateRequest
= &ApiMessage
.Data
.HardwareStateRequest
;
599 DPRINT1("GetConsoleHardwareState(%lu, 0x%p) UNIMPLEMENTED!\n", Flags
, State
);
601 if (Flags
== NULL
|| State
== NULL
)
603 SetLastError(ERROR_INVALID_PARAMETER
);
607 HardwareStateRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
608 HardwareStateRequest
->OutputHandle
= hConsoleOutput
;
610 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
612 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetHardwareState
),
613 sizeof(*HardwareStateRequest
));
614 if (!NT_SUCCESS(ApiMessage
.Status
))
616 BaseSetLastNTError(ApiMessage
.Status
);
620 *Flags
= HardwareStateRequest
->Flags
;
621 *State
= HardwareStateRequest
->State
;
628 * @implemented (Undocumented)
632 GetConsoleInputWaitHandle(VOID
)
634 return InputWaitHandle
;
643 GetCurrentConsoleFont(HANDLE hConsoleOutput
,
645 PCONSOLE_FONT_INFO lpConsoleCurrentFont
)
647 DPRINT1("GetCurrentConsoleFont(0x%p, 0x%x, 0x%p) UNIMPLEMENTED!\n", hConsoleOutput
, bMaximumWindow
, lpConsoleCurrentFont
);
648 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
654 * @unimplemented (Undocumented)
659 GetNumberOfConsoleFonts(VOID
)
661 DPRINT1("GetNumberOfConsoleFonts() UNIMPLEMENTED!\n");
662 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
668 * @implemented (Undocumented)
669 * @note See http://blog.airesoft.co.uk/2012/10/things-ms-can-do-that-they-dont-tell-you-about-console-graphics/
673 InvalidateConsoleDIBits(IN HANDLE hConsoleOutput
,
674 IN PSMALL_RECT lpRect
)
676 CONSOLE_API_MESSAGE ApiMessage
;
677 PCONSOLE_INVALIDATEDIBITS InvalidateDIBitsRequest
= &ApiMessage
.Data
.InvalidateDIBitsRequest
;
681 SetLastError(ERROR_INVALID_PARAMETER
);
685 InvalidateDIBitsRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
686 InvalidateDIBitsRequest
->OutputHandle
= hConsoleOutput
;
687 InvalidateDIBitsRequest
->Region
= *lpRect
;
689 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
691 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepInvalidateBitMapRect
),
692 sizeof(*InvalidateDIBitsRequest
));
693 if (!NT_SUCCESS(ApiMessage
.Status
))
695 BaseSetLastNTError(ApiMessage
.Status
);
704 * @implemented (Undocumented)
708 OpenConsoleW(LPCWSTR wsName
,
709 DWORD dwDesiredAccess
,
713 CONSOLE_API_MESSAGE ApiMessage
;
714 PCONSOLE_OPENCONSOLE OpenConsoleRequest
= &ApiMessage
.Data
.OpenConsoleRequest
;
715 CONSOLE_HANDLE_TYPE HandleType
;
717 if (wsName
&& (_wcsicmp(wsName
, BaseConInputFileName
) == 0))
719 HandleType
= HANDLE_INPUT
;
721 else if (wsName
&& (_wcsicmp(wsName
, BaseConOutputFileName
) == 0))
723 HandleType
= HANDLE_OUTPUT
;
727 SetLastError(ERROR_INVALID_PARAMETER
);
728 return INVALID_HANDLE_VALUE
;
731 if ( (dwDesiredAccess
& ~(GENERIC_READ
| GENERIC_WRITE
)) ||
732 (dwShareMode
& ~(FILE_SHARE_READ
| FILE_SHARE_WRITE
)) )
734 SetLastError(ERROR_INVALID_PARAMETER
);
735 return INVALID_HANDLE_VALUE
;
738 OpenConsoleRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
739 OpenConsoleRequest
->HandleType
= HandleType
;
740 OpenConsoleRequest
->DesiredAccess
= dwDesiredAccess
;
741 OpenConsoleRequest
->InheritHandle
= bInheritHandle
;
742 OpenConsoleRequest
->ShareMode
= dwShareMode
;
744 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
746 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepOpenConsole
),
747 sizeof(*OpenConsoleRequest
));
748 if (!NT_SUCCESS(ApiMessage
.Status
))
750 BaseSetLastNTError(ApiMessage
.Status
);
751 return INVALID_HANDLE_VALUE
;
754 return OpenConsoleRequest
->Handle
;
759 * @implemented (Undocumented)
760 * @note See http://undoc.airesoft.co.uk/kernel32.dll/SetConsoleCursor.php
765 SetConsoleCursor(HANDLE hConsoleOutput
,
768 CONSOLE_API_MESSAGE ApiMessage
;
769 PCONSOLE_SETCURSOR SetCursorRequest
= &ApiMessage
.Data
.SetCursorRequest
;
771 SetCursorRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
772 SetCursorRequest
->OutputHandle
= hConsoleOutput
;
773 SetCursorRequest
->CursorHandle
= hCursor
;
775 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
777 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetCursor
),
778 sizeof(*SetCursorRequest
));
779 if (!NT_SUCCESS(ApiMessage
.Status
))
781 BaseSetLastNTError(ApiMessage
.Status
);
794 SetConsoleDisplayMode(HANDLE hConsoleOutput
,
795 DWORD dwFlags
, // dwModeFlags
796 PCOORD lpNewScreenBufferDimensions
)
798 CONSOLE_API_MESSAGE ApiMessage
;
799 PCONSOLE_SETDISPLAYMODE SetDisplayModeRequest
= &ApiMessage
.Data
.SetDisplayModeRequest
;
801 SetDisplayModeRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
802 SetDisplayModeRequest
->OutputHandle
= hConsoleOutput
;
803 SetDisplayModeRequest
->DisplayMode
= dwFlags
; // ModeFlags ; dwModeFlags
804 SetDisplayModeRequest
->NewSBDim
.X
= 0;
805 SetDisplayModeRequest
->NewSBDim
.Y
= 0;
806 /* SetDisplayModeRequest->EventHandle; */
808 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
810 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetDisplayMode
),
811 sizeof(*SetDisplayModeRequest
));
812 if (!NT_SUCCESS(ApiMessage
.Status
))
814 BaseSetLastNTError(ApiMessage
.Status
);
818 if (lpNewScreenBufferDimensions
)
819 *lpNewScreenBufferDimensions
= SetDisplayModeRequest
->NewSBDim
;
826 * @unimplemented (Undocumented)
831 SetConsoleFont(HANDLE hConsoleOutput
,
834 DPRINT1("SetConsoleFont(0x%p, %lu) UNIMPLEMENTED!\n", hConsoleOutput
, nFont
);
835 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
841 * @implemented (Undocumented)
845 SetConsoleHardwareState(HANDLE hConsoleOutput
,
849 CONSOLE_API_MESSAGE ApiMessage
;
850 PCONSOLE_GETSETHWSTATE HardwareStateRequest
= &ApiMessage
.Data
.HardwareStateRequest
;
852 DPRINT1("SetConsoleHardwareState(%lu, %lu) UNIMPLEMENTED!\n", Flags
, State
);
854 HardwareStateRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
855 HardwareStateRequest
->OutputHandle
= hConsoleOutput
;
856 HardwareStateRequest
->Flags
= Flags
;
857 HardwareStateRequest
->State
= State
;
859 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
861 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetHardwareState
),
862 sizeof(*HardwareStateRequest
));
863 if (!NT_SUCCESS(ApiMessage
.Status
))
865 BaseSetLastNTError(ApiMessage
.Status
);
874 * @unimplemented (Undocumented)
879 SetConsoleKeyShortcuts(DWORD Unknown0
,
884 DPRINT1("SetConsoleKeyShortcuts(0x%x, 0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
, Unknown2
, Unknown3
);
885 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
891 * @implemented (Undocumented)
892 * @note See http://undoc.airesoft.co.uk/kernel32.dll/SetConsoleMaximumWindowSize.php
893 * Does nothing, returns TRUE only. Checked on Windows Server 2003.
897 SetConsoleMaximumWindowSize(HANDLE hConsoleOutput
,
900 DPRINT1("SetConsoleMaximumWindowSize(0x%p, {%d, %d}) does nothing\n",
901 hConsoleOutput
, dwMaximumSize
.X
, dwMaximumSize
.Y
);
907 * @implemented (Undocumented)
912 SetConsoleMenuClose(BOOL bEnable
)
914 CONSOLE_API_MESSAGE ApiMessage
;
915 PCONSOLE_SETMENUCLOSE SetMenuCloseRequest
= &ApiMessage
.Data
.SetMenuCloseRequest
;
917 SetMenuCloseRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
918 SetMenuCloseRequest
->Enable
= bEnable
;
920 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
922 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetMenuClose
),
923 sizeof(*SetMenuCloseRequest
));
924 if (!NT_SUCCESS(ApiMessage
.Status
))
926 BaseSetLastNTError(ApiMessage
.Status
);
935 * @implemented (Undocumented)
936 * @note See http://comments.gmane.org/gmane.comp.lang.harbour.devel/27844
937 * Usage example: https://github.com/harbour/core/commit/d79a1b7b812cbde6ddf718ebfd6939a24f633e52
942 SetConsolePalette(HANDLE hConsoleOutput
,
946 CONSOLE_API_MESSAGE ApiMessage
;
947 PCONSOLE_SETPALETTE SetPaletteRequest
= &ApiMessage
.Data
.SetPaletteRequest
;
949 SetPaletteRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
950 SetPaletteRequest
->OutputHandle
= hConsoleOutput
;
951 SetPaletteRequest
->PaletteHandle
= hPalette
;
952 SetPaletteRequest
->Usage
= dwUsage
;
954 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
956 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetPalette
),
957 sizeof(*SetPaletteRequest
));
958 if (!NT_SUCCESS(ApiMessage
.Status
))
960 BaseSetLastNTError(ApiMessage
.Status
);
968 * @implemented (Undocumented)
969 * @note See http://undoc.airesoft.co.uk/kernel32.dll/ShowConsoleCursor.php
974 ShowConsoleCursor(HANDLE hConsoleOutput
,
977 CONSOLE_API_MESSAGE ApiMessage
;
978 PCONSOLE_SHOWCURSOR ShowCursorRequest
= &ApiMessage
.Data
.ShowCursorRequest
;
980 ShowCursorRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
981 ShowCursorRequest
->OutputHandle
= hConsoleOutput
;
982 ShowCursorRequest
->Show
= bShow
;
983 ShowCursorRequest
->RefCount
= 0;
985 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
987 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepShowCursor
),
988 sizeof(*ShowCursorRequest
));
990 return ShowCursorRequest
->RefCount
;
995 * FUNCTION: Checks whether the given handle is a valid console handle.
998 * hIoHandle - Handle to be checked.
1001 * TRUE : Handle is a valid console handle.
1002 * FALSE: Handle is not a valid console handle.
1004 * STATUS: Officially undocumented
1011 VerifyConsoleIoHandle(HANDLE hIoHandle
)
1013 CONSOLE_API_MESSAGE ApiMessage
;
1014 PCONSOLE_VERIFYHANDLE VerifyHandleRequest
= &ApiMessage
.Data
.VerifyHandleRequest
;
1016 VerifyHandleRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1017 VerifyHandleRequest
->Handle
= hIoHandle
;
1018 VerifyHandleRequest
->IsValid
= FALSE
;
1020 /* If the process is not attached to a console, return invalid handle */
1021 if (VerifyHandleRequest
->ConsoleHandle
== NULL
) return FALSE
;
1023 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1025 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepVerifyIoHandle
),
1026 sizeof(*VerifyHandleRequest
));
1027 if (!NT_SUCCESS(ApiMessage
.Status
))
1029 BaseSetLastNTError(ApiMessage
.Status
);
1033 return VerifyHandleRequest
->IsValid
;
1038 * @implemented (Undocumented)
1043 CloseConsoleHandle(HANDLE hHandle
)
1045 CONSOLE_API_MESSAGE ApiMessage
;
1046 PCONSOLE_CLOSEHANDLE CloseHandleRequest
= &ApiMessage
.Data
.CloseHandleRequest
;
1048 CloseHandleRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1049 CloseHandleRequest
->Handle
= hHandle
;
1051 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1053 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepCloseHandle
),
1054 sizeof(*CloseHandleRequest
));
1055 if (!NT_SUCCESS(ApiMessage
.Status
))
1057 BaseSetLastNTError(ApiMessage
.Status
);
1071 GetStdHandle(DWORD nStdHandle
)
1073 * FUNCTION: Get a handle for the standard input, standard output
1074 * and a standard error device.
1077 * nStdHandle - Specifies the device for which to return the handle.
1079 * RETURNS: If the function succeeds, the return value is the handle
1080 * of the specified device. Otherwise the value is INVALID_HANDLE_VALUE.
1083 PRTL_USER_PROCESS_PARAMETERS Ppb
= NtCurrentPeb()->ProcessParameters
;
1084 HANDLE Handle
= INVALID_HANDLE_VALUE
;
1088 case STD_INPUT_HANDLE
:
1089 Handle
= Ppb
->StandardInput
;
1092 case STD_OUTPUT_HANDLE
:
1093 Handle
= Ppb
->StandardOutput
;
1096 case STD_ERROR_HANDLE
:
1097 Handle
= Ppb
->StandardError
;
1101 /* If the returned handle is invalid, set last error */
1102 if (Handle
== INVALID_HANDLE_VALUE
) SetLastError(ERROR_INVALID_HANDLE
);
1114 SetStdHandle(DWORD nStdHandle
,
1117 * FUNCTION: Set the handle for the standard input, standard output or
1118 * the standard error device.
1121 * nStdHandle - Specifies the handle to be set.
1122 * hHandle - The handle to set.
1124 * RETURNS: TRUE if the function succeeds, FALSE otherwise.
1127 PRTL_USER_PROCESS_PARAMETERS Ppb
= NtCurrentPeb()->ProcessParameters
;
1129 /* No need to check if hHandle == INVALID_HANDLE_VALUE */
1133 case STD_INPUT_HANDLE
:
1134 Ppb
->StandardInput
= hHandle
;
1137 case STD_OUTPUT_HANDLE
:
1138 Ppb
->StandardOutput
= hHandle
;
1141 case STD_ERROR_HANDLE
:
1142 Ppb
->StandardError
= hHandle
;
1146 /* nStdHandle was invalid, bail out */
1147 SetLastError(ERROR_INVALID_HANDLE
);
1156 IntAllocConsole(LPWSTR Title
,
1159 DWORD DesktopLength
,
1163 DWORD AppNameLength
,
1164 LPTHREAD_START_ROUTINE CtrlRoutine
,
1165 LPTHREAD_START_ROUTINE PropRoutine
,
1166 PCONSOLE_START_INFO ConsoleStartInfo
)
1168 BOOL Success
= TRUE
;
1171 CONSOLE_API_MESSAGE ApiMessage
;
1172 PCONSOLE_ALLOCCONSOLE AllocConsoleRequest
= &ApiMessage
.Data
.AllocConsoleRequest
;
1173 PCSR_CAPTURE_BUFFER CaptureBuffer
;
1175 AllocConsoleRequest
->CtrlRoutine
= CtrlRoutine
;
1176 AllocConsoleRequest
->PropRoutine
= PropRoutine
;
1178 CaptureBuffer
= CsrAllocateCaptureBuffer(5, TitleLength
+
1182 sizeof(CONSOLE_START_INFO
));
1183 if (CaptureBuffer
== NULL
)
1185 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1190 CsrCaptureMessageBuffer(CaptureBuffer
,
1192 sizeof(CONSOLE_START_INFO
),
1193 (PVOID
*)&AllocConsoleRequest
->ConsoleStartInfo
);
1195 AllocConsoleRequest
->TitleLength
= TitleLength
;
1196 CsrCaptureMessageBuffer(CaptureBuffer
,
1199 (PVOID
*)&AllocConsoleRequest
->ConsoleTitle
);
1201 AllocConsoleRequest
->DesktopLength
= DesktopLength
;
1202 CsrCaptureMessageBuffer(CaptureBuffer
,
1205 (PVOID
*)&AllocConsoleRequest
->Desktop
);
1207 AllocConsoleRequest
->CurDirLength
= CurDirLength
;
1208 CsrCaptureMessageBuffer(CaptureBuffer
,
1211 (PVOID
*)&AllocConsoleRequest
->CurDir
);
1213 AllocConsoleRequest
->AppNameLength
= AppNameLength
;
1214 CsrCaptureMessageBuffer(CaptureBuffer
,
1217 (PVOID
*)&AllocConsoleRequest
->AppName
);
1219 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1221 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepAlloc
),
1222 sizeof(*AllocConsoleRequest
));
1223 if (!NT_SUCCESS(ApiMessage
.Status
))
1225 BaseSetLastNTError(ApiMessage
.Status
);
1230 // Is AllocConsoleRequest->ConsoleStartInfo->InitEvents aligned on handle boundary ????
1231 Status
= NtWaitForMultipleObjects(MAX_INIT_EVENTS
,
1232 AllocConsoleRequest
->ConsoleStartInfo
->InitEvents
,
1233 WaitAny
, FALSE
, NULL
);
1234 if (!NT_SUCCESS(Status
))
1236 BaseSetLastNTError(Status
);
1241 NtClose(AllocConsoleRequest
->ConsoleStartInfo
->InitEvents
[INIT_SUCCESS
]);
1242 NtClose(AllocConsoleRequest
->ConsoleStartInfo
->InitEvents
[INIT_FAILURE
]);
1243 if (Status
!= INIT_SUCCESS
)
1245 NtCurrentPeb()->ProcessParameters
->ConsoleHandle
= NULL
;
1250 RtlCopyMemory(ConsoleStartInfo
,
1251 AllocConsoleRequest
->ConsoleStartInfo
,
1252 sizeof(CONSOLE_START_INFO
));
1257 if (CaptureBuffer
) CsrFreeCaptureBuffer(CaptureBuffer
);
1267 CONSOLE_START_INFO ConsoleStartInfo
;
1269 PWCHAR ConsoleTitle
;
1274 ULONG TitleLength
= (MAX_PATH
+ 1) * sizeof(WCHAR
);
1275 ULONG DesktopLength
= (MAX_PATH
+ 1) * sizeof(WCHAR
);
1276 ULONG AppNameLength
= 128 * sizeof(WCHAR
);
1277 ULONG CurDirLength
= (MAX_PATH
+ 1) * sizeof(WCHAR
);
1281 RtlEnterCriticalSection(&ConsoleLock
);
1283 if (NtCurrentPeb()->ProcessParameters
->ConsoleHandle
)
1285 DPRINT1("AllocConsole: Allocating a console to a process already having one\n");
1286 SetLastError(ERROR_ACCESS_DENIED
);
1291 /* Set up the console properties */
1292 SetUpConsoleInfo(FALSE
,
1298 DPRINT("ConsoleTitle = '%S' - Desktop = '%S'\n",
1299 ConsoleTitle
, Desktop
);
1301 /* Initialize the Input EXE name */
1308 DPRINT("CurDir = '%S' - AppName = '%S'\n",
1311 Success
= IntAllocConsole(ConsoleTitle
,
1319 ConsoleControlDispatcher
,
1324 /* Set up the handles */
1325 SetUpHandles(&ConsoleStartInfo
);
1326 InputWaitHandle
= ConsoleStartInfo
.InputWaitHandle
;
1328 /* Initialize Console Ctrl Handling */
1329 InitializeCtrlHandling();
1331 /* Sets the current console locale for this thread */
1336 RtlLeaveCriticalSection(&ConsoleLock
);
1349 CONSOLE_API_MESSAGE ApiMessage
;
1350 PCONSOLE_FREECONSOLE FreeConsoleRequest
= &ApiMessage
.Data
.FreeConsoleRequest
;
1351 HANDLE ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1353 /* We must have a non-trivial handle to close */
1354 if (ConsoleHandle
== NULL
) // IsConsoleHandle(ConsoleHandle)
1356 SetLastError(ERROR_INVALID_PARAMETER
);
1360 /* Set up the data to send to the Console Server */
1361 FreeConsoleRequest
->ConsoleHandle
= ConsoleHandle
;
1363 /* Call the server */
1364 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1366 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepFree
),
1367 sizeof(*FreeConsoleRequest
));
1369 /* Check for success */
1370 if (!NT_SUCCESS(ApiMessage
.Status
))
1372 BaseSetLastNTError(ApiMessage
.Status
);
1376 /* Reset the console handle */
1377 NtCurrentPeb()->ProcessParameters
->ConsoleHandle
= NULL
;
1379 /* Close the associated input handle */
1380 CloseHandle(InputWaitHandle
);
1381 InputWaitHandle
= INVALID_HANDLE_VALUE
;
1392 GetConsoleScreenBufferInfo(HANDLE hConsoleOutput
,
1393 PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo
)
1395 CONSOLE_API_MESSAGE ApiMessage
;
1396 PCONSOLE_GETSCREENBUFFERINFO ScreenBufferInfoRequest
= &ApiMessage
.Data
.ScreenBufferInfoRequest
;
1398 if (lpConsoleScreenBufferInfo
== NULL
)
1400 SetLastError(ERROR_INVALID_PARAMETER
);
1404 ScreenBufferInfoRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1405 ScreenBufferInfoRequest
->OutputHandle
= hConsoleOutput
;
1407 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1409 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetScreenBufferInfo
),
1410 sizeof(*ScreenBufferInfoRequest
));
1411 if (!NT_SUCCESS(ApiMessage
.Status
))
1413 BaseSetLastNTError(ApiMessage
.Status
);
1417 lpConsoleScreenBufferInfo
->dwSize
= ScreenBufferInfoRequest
->ScreenBufferSize
;
1418 lpConsoleScreenBufferInfo
->dwCursorPosition
= ScreenBufferInfoRequest
->CursorPosition
;
1419 lpConsoleScreenBufferInfo
->wAttributes
= ScreenBufferInfoRequest
->Attributes
;
1420 lpConsoleScreenBufferInfo
->srWindow
.Left
= ScreenBufferInfoRequest
->ViewOrigin
.X
;
1421 lpConsoleScreenBufferInfo
->srWindow
.Top
= ScreenBufferInfoRequest
->ViewOrigin
.Y
;
1422 lpConsoleScreenBufferInfo
->srWindow
.Right
= ScreenBufferInfoRequest
->ViewOrigin
.X
+ ScreenBufferInfoRequest
->ViewSize
.X
- 1;
1423 lpConsoleScreenBufferInfo
->srWindow
.Bottom
= ScreenBufferInfoRequest
->ViewOrigin
.Y
+ ScreenBufferInfoRequest
->ViewSize
.Y
- 1;
1424 lpConsoleScreenBufferInfo
->dwMaximumWindowSize
= ScreenBufferInfoRequest
->MaximumViewSize
;
1436 SetConsoleCursorPosition(HANDLE hConsoleOutput
,
1437 COORD dwCursorPosition
)
1439 CONSOLE_API_MESSAGE ApiMessage
;
1440 PCONSOLE_SETCURSORPOSITION SetCursorPositionRequest
= &ApiMessage
.Data
.SetCursorPositionRequest
;
1442 SetCursorPositionRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1443 SetCursorPositionRequest
->OutputHandle
= hConsoleOutput
;
1444 SetCursorPositionRequest
->Position
= dwCursorPosition
;
1446 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1448 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetCursorPosition
),
1449 sizeof(*SetCursorPositionRequest
));
1450 if (!NT_SUCCESS(ApiMessage
.Status
))
1452 BaseSetLastNTError(ApiMessage
.Status
);
1465 GetConsoleMode(HANDLE hConsoleHandle
,
1468 CONSOLE_API_MESSAGE ApiMessage
;
1469 PCONSOLE_GETSETCONSOLEMODE ConsoleModeRequest
= &ApiMessage
.Data
.ConsoleModeRequest
;
1473 SetLastError(ERROR_INVALID_PARAMETER
);
1477 ConsoleModeRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1478 ConsoleModeRequest
->Handle
= hConsoleHandle
;
1480 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1482 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetMode
),
1483 sizeof(*ConsoleModeRequest
));
1484 if (!NT_SUCCESS(ApiMessage
.Status
))
1486 BaseSetLastNTError(ApiMessage
.Status
);
1490 *lpMode
= ConsoleModeRequest
->Mode
;
1502 SetConsoleMode(HANDLE hConsoleHandle
,
1505 CONSOLE_API_MESSAGE ApiMessage
;
1506 PCONSOLE_GETSETCONSOLEMODE ConsoleModeRequest
= &ApiMessage
.Data
.ConsoleModeRequest
;
1508 ConsoleModeRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1509 ConsoleModeRequest
->Handle
= hConsoleHandle
;
1510 ConsoleModeRequest
->Mode
= dwMode
;
1512 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1514 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetMode
),
1515 sizeof(*ConsoleModeRequest
));
1516 if (!NT_SUCCESS(ApiMessage
.Status
))
1518 BaseSetLastNTError(ApiMessage
.Status
);
1531 GetNumberOfConsoleInputEvents(HANDLE hConsoleInput
,
1532 LPDWORD lpNumberOfEvents
)
1534 CONSOLE_API_MESSAGE ApiMessage
;
1535 PCONSOLE_GETNUMINPUTEVENTS GetNumInputEventsRequest
= &ApiMessage
.Data
.GetNumInputEventsRequest
;
1537 GetNumInputEventsRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1538 GetNumInputEventsRequest
->InputHandle
= hConsoleInput
;
1539 GetNumInputEventsRequest
->NumberOfEvents
= 0;
1541 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1543 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetNumberOfInputEvents
),
1544 sizeof(*GetNumInputEventsRequest
));
1545 if (!NT_SUCCESS(ApiMessage
.Status
))
1547 BaseSetLastNTError(ApiMessage
.Status
);
1551 if (lpNumberOfEvents
== NULL
)
1553 SetLastError(ERROR_INVALID_ACCESS
);
1557 *lpNumberOfEvents
= GetNumInputEventsRequest
->NumberOfEvents
;
1569 GetLargestConsoleWindowSize(HANDLE hConsoleOutput
)
1571 CONSOLE_API_MESSAGE ApiMessage
;
1572 PCONSOLE_GETLARGESTWINDOWSIZE GetLargestWindowSizeRequest
= &ApiMessage
.Data
.GetLargestWindowSizeRequest
;
1574 GetLargestWindowSizeRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1575 GetLargestWindowSizeRequest
->OutputHandle
= hConsoleOutput
;
1576 GetLargestWindowSizeRequest
->Size
.X
= 0;
1577 GetLargestWindowSizeRequest
->Size
.Y
= 0;
1579 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1581 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetLargestWindowSize
),
1582 sizeof(*GetLargestWindowSizeRequest
));
1583 if (!NT_SUCCESS(ApiMessage
.Status
))
1585 BaseSetLastNTError(ApiMessage
.Status
);
1588 DPRINT("GetLargestConsoleWindowSize, X = %d, Y = %d\n", GetLargestWindowSizeRequest
->Size
.X
, GetLargestWindowSizeRequest
->Size
.Y
);
1589 return GetLargestWindowSizeRequest
->Size
;
1598 GetConsoleCursorInfo(HANDLE hConsoleOutput
,
1599 PCONSOLE_CURSOR_INFO lpConsoleCursorInfo
)
1601 CONSOLE_API_MESSAGE ApiMessage
;
1602 PCONSOLE_GETSETCURSORINFO CursorInfoRequest
= &ApiMessage
.Data
.CursorInfoRequest
;
1604 if (!lpConsoleCursorInfo
)
1606 if (!hConsoleOutput
)
1607 SetLastError(ERROR_INVALID_HANDLE
);
1609 SetLastError(ERROR_INVALID_ACCESS
);
1614 CursorInfoRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1615 CursorInfoRequest
->OutputHandle
= hConsoleOutput
;
1617 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1619 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetCursorInfo
),
1620 sizeof(*CursorInfoRequest
));
1621 if (!NT_SUCCESS(ApiMessage
.Status
))
1623 BaseSetLastNTError(ApiMessage
.Status
);
1627 *lpConsoleCursorInfo
= CursorInfoRequest
->Info
;
1638 SetConsoleCursorInfo(HANDLE hConsoleOutput
,
1639 CONST CONSOLE_CURSOR_INFO
*lpConsoleCursorInfo
)
1641 CONSOLE_API_MESSAGE ApiMessage
;
1642 PCONSOLE_GETSETCURSORINFO CursorInfoRequest
= &ApiMessage
.Data
.CursorInfoRequest
;
1644 CursorInfoRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1645 CursorInfoRequest
->OutputHandle
= hConsoleOutput
;
1646 CursorInfoRequest
->Info
= *lpConsoleCursorInfo
;
1648 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1650 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetCursorInfo
),
1651 sizeof(*CursorInfoRequest
));
1652 if (!NT_SUCCESS(ApiMessage
.Status
))
1654 BaseSetLastNTError(ApiMessage
.Status
);
1667 GetNumberOfConsoleMouseButtons(LPDWORD lpNumberOfMouseButtons
)
1669 CONSOLE_API_MESSAGE ApiMessage
;
1670 PCONSOLE_GETMOUSEINFO GetMouseInfoRequest
= &ApiMessage
.Data
.GetMouseInfoRequest
;
1672 GetMouseInfoRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1674 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1676 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetMouseInfo
),
1677 sizeof(*GetMouseInfoRequest
));
1678 if (!NT_SUCCESS(ApiMessage
.Status
))
1680 BaseSetLastNTError(ApiMessage
.Status
);
1684 *lpNumberOfMouseButtons
= GetMouseInfoRequest
->NumButtons
;
1695 SetConsoleActiveScreenBuffer(HANDLE hConsoleOutput
)
1697 CONSOLE_API_MESSAGE ApiMessage
;
1698 PCONSOLE_SETACTIVESCREENBUFFER SetScreenBufferRequest
= &ApiMessage
.Data
.SetScreenBufferRequest
;
1700 SetScreenBufferRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1701 SetScreenBufferRequest
->OutputHandle
= hConsoleOutput
;
1703 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1705 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetActiveScreenBuffer
),
1706 sizeof(*SetScreenBufferRequest
));
1707 if (!NT_SUCCESS(ApiMessage
.Status
))
1709 BaseSetLastNTError(ApiMessage
.Status
);
1723 FlushConsoleInputBuffer(HANDLE hConsoleInput
)
1725 CONSOLE_API_MESSAGE ApiMessage
;
1726 PCONSOLE_FLUSHINPUTBUFFER FlushInputBufferRequest
= &ApiMessage
.Data
.FlushInputBufferRequest
;
1728 FlushInputBufferRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1729 FlushInputBufferRequest
->InputHandle
= hConsoleInput
;
1731 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1733 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepFlushInputBuffer
),
1734 sizeof(*FlushInputBufferRequest
));
1735 if (!NT_SUCCESS(ApiMessage
.Status
))
1737 BaseSetLastNTError(ApiMessage
.Status
);
1751 SetConsoleScreenBufferSize(HANDLE hConsoleOutput
,
1754 CONSOLE_API_MESSAGE ApiMessage
;
1755 PCONSOLE_SETSCREENBUFFERSIZE SetScreenBufferSizeRequest
= &ApiMessage
.Data
.SetScreenBufferSizeRequest
;
1757 SetScreenBufferSizeRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1758 SetScreenBufferSizeRequest
->OutputHandle
= hConsoleOutput
;
1759 SetScreenBufferSizeRequest
->Size
= dwSize
;
1761 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1763 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetScreenBufferSize
),
1764 sizeof(*SetScreenBufferSizeRequest
));
1765 if (!NT_SUCCESS(ApiMessage
.Status
))
1767 BaseSetLastNTError(ApiMessage
.Status
);
1777 IntScrollConsoleScreenBuffer(HANDLE hConsoleOutput
,
1778 CONST SMALL_RECT
* lpScrollRectangle
,
1779 CONST SMALL_RECT
* lpClipRectangle
,
1780 COORD dwDestinationOrigin
,
1781 CONST CHAR_INFO
* lpFill
,
1784 CONSOLE_API_MESSAGE ApiMessage
;
1785 PCONSOLE_SCROLLSCREENBUFFER ScrollScreenBufferRequest
= &ApiMessage
.Data
.ScrollScreenBufferRequest
;
1787 ScrollScreenBufferRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1788 ScrollScreenBufferRequest
->OutputHandle
= hConsoleOutput
;
1789 ScrollScreenBufferRequest
->ScrollRectangle
= *lpScrollRectangle
;
1791 if (lpClipRectangle
!= NULL
)
1793 ScrollScreenBufferRequest
->UseClipRectangle
= TRUE
;
1794 ScrollScreenBufferRequest
->ClipRectangle
= *lpClipRectangle
;
1798 ScrollScreenBufferRequest
->UseClipRectangle
= FALSE
;
1801 ScrollScreenBufferRequest
->DestinationOrigin
= dwDestinationOrigin
;
1802 ScrollScreenBufferRequest
->Fill
= *lpFill
;
1803 ScrollScreenBufferRequest
->Unicode
= bUnicode
;
1805 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1807 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepScrollScreenBuffer
),
1808 sizeof(*ScrollScreenBufferRequest
));
1809 if (!NT_SUCCESS(ApiMessage
.Status
))
1811 BaseSetLastNTError(ApiMessage
.Status
);
1825 ScrollConsoleScreenBufferA(HANDLE hConsoleOutput
,
1826 CONST SMALL_RECT
* lpScrollRectangle
,
1827 CONST SMALL_RECT
* lpClipRectangle
,
1828 COORD dwDestinationOrigin
,
1829 CONST CHAR_INFO
* lpFill
)
1831 return IntScrollConsoleScreenBuffer(hConsoleOutput
,
1834 dwDestinationOrigin
,
1846 ScrollConsoleScreenBufferW(HANDLE hConsoleOutput
,
1847 CONST SMALL_RECT
*lpScrollRectangle
,
1848 CONST SMALL_RECT
*lpClipRectangle
,
1849 COORD dwDestinationOrigin
,
1850 CONST CHAR_INFO
*lpFill
)
1852 return IntScrollConsoleScreenBuffer(hConsoleOutput
,
1855 dwDestinationOrigin
,
1866 SetConsoleWindowInfo(HANDLE hConsoleOutput
,
1868 CONST SMALL_RECT
*lpConsoleWindow
)
1870 CONSOLE_API_MESSAGE ApiMessage
;
1871 PCONSOLE_SETWINDOWINFO SetWindowInfoRequest
= &ApiMessage
.Data
.SetWindowInfoRequest
;
1873 if (lpConsoleWindow
== NULL
)
1875 SetLastError(ERROR_INVALID_PARAMETER
);
1879 SetWindowInfoRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1880 SetWindowInfoRequest
->OutputHandle
= hConsoleOutput
;
1881 SetWindowInfoRequest
->Absolute
= bAbsolute
;
1882 SetWindowInfoRequest
->WindowRect
= *lpConsoleWindow
;
1884 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1886 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetWindowInfo
),
1887 sizeof(*SetWindowInfoRequest
));
1888 if (!NT_SUCCESS(ApiMessage
.Status
))
1890 BaseSetLastNTError(ApiMessage
.Status
);
1904 SetConsoleTextAttribute(HANDLE hConsoleOutput
,
1907 CONSOLE_API_MESSAGE ApiMessage
;
1908 PCONSOLE_SETTEXTATTRIB SetTextAttribRequest
= &ApiMessage
.Data
.SetTextAttribRequest
;
1910 SetTextAttribRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1911 SetTextAttribRequest
->OutputHandle
= hConsoleOutput
;
1912 SetTextAttribRequest
->Attributes
= wAttributes
;
1914 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1916 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetTextAttribute
),
1917 sizeof(*SetTextAttribRequest
));
1918 if (!NT_SUCCESS(ApiMessage
.Status
))
1920 BaseSetLastNTError(ApiMessage
.Status
);
1930 AddConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine
)
1932 PHANDLER_ROUTINE
* NewCtrlHandlers
= NULL
;
1934 if (HandlerRoutine
== NULL
)
1936 NtCurrentPeb()->ProcessParameters
->ConsoleFlags
= TRUE
;
1940 if (NrCtrlHandlers
== NrAllocatedHandlers
)
1942 NewCtrlHandlers
= RtlAllocateHeap(RtlGetProcessHeap(),
1944 (NrCtrlHandlers
+ 4) * sizeof(PHANDLER_ROUTINE
));
1945 if (NewCtrlHandlers
== NULL
)
1947 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1951 memmove(NewCtrlHandlers
, CtrlHandlers
, sizeof(PHANDLER_ROUTINE
) * NrCtrlHandlers
);
1953 if (NrAllocatedHandlers
> 1) RtlFreeHeap(RtlGetProcessHeap(), 0, CtrlHandlers
);
1955 CtrlHandlers
= NewCtrlHandlers
;
1956 NrAllocatedHandlers
+= 4;
1959 ASSERT(NrCtrlHandlers
< NrAllocatedHandlers
);
1961 CtrlHandlers
[NrCtrlHandlers
++] = HandlerRoutine
;
1968 RemoveConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine
)
1972 if (HandlerRoutine
== NULL
)
1974 NtCurrentPeb()->ProcessParameters
->ConsoleFlags
= FALSE
;
1978 for (i
= 0; i
< NrCtrlHandlers
; i
++)
1980 if (CtrlHandlers
[i
] == HandlerRoutine
)
1982 if (i
< (NrCtrlHandlers
- 1))
1984 memmove(&CtrlHandlers
[i
],
1986 (NrCtrlHandlers
- i
+ 1) * sizeof(PHANDLER_ROUTINE
));
1994 SetLastError(ERROR_INVALID_PARAMETER
);
2005 SetConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine
,
2010 RtlEnterCriticalSection(&BaseDllDirectoryLock
);
2013 Ret
= AddConsoleCtrlHandler(HandlerRoutine
);
2017 Ret
= RemoveConsoleCtrlHandler(HandlerRoutine
);
2020 RtlLeaveCriticalSection(&BaseDllDirectoryLock
);
2031 GenerateConsoleCtrlEvent(DWORD dwCtrlEvent
,
2032 DWORD dwProcessGroupId
)
2034 CONSOLE_API_MESSAGE ApiMessage
;
2035 PCONSOLE_GENERATECTRLEVENT GenerateCtrlEventRequest
= &ApiMessage
.Data
.GenerateCtrlEventRequest
;
2037 if (dwCtrlEvent
!= CTRL_C_EVENT
&& dwCtrlEvent
!= CTRL_BREAK_EVENT
)
2039 SetLastError(ERROR_INVALID_PARAMETER
);
2043 GenerateCtrlEventRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
2044 GenerateCtrlEventRequest
->CtrlEvent
= dwCtrlEvent
;
2045 GenerateCtrlEventRequest
->ProcessGroupId
= dwProcessGroupId
;
2047 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2049 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGenerateCtrlEvent
),
2050 sizeof(*GenerateCtrlEventRequest
));
2051 if (!NT_SUCCESS(ApiMessage
.Status
))
2053 BaseSetLastNTError(ApiMessage
.Status
);
2062 IntGetConsoleTitle(LPVOID lpConsoleTitle
, DWORD dwNumChars
, BOOLEAN bUnicode
)
2064 CONSOLE_API_MESSAGE ApiMessage
;
2065 PCONSOLE_GETSETCONSOLETITLE TitleRequest
= &ApiMessage
.Data
.TitleRequest
;
2066 PCSR_CAPTURE_BUFFER CaptureBuffer
;
2068 if (dwNumChars
== 0) return 0;
2070 TitleRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
2071 TitleRequest
->Length
= dwNumChars
* (bUnicode
? sizeof(WCHAR
) : sizeof(CHAR
));
2072 TitleRequest
->Unicode
= bUnicode
;
2074 CaptureBuffer
= CsrAllocateCaptureBuffer(1, TitleRequest
->Length
);
2075 if (CaptureBuffer
== NULL
)
2077 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
2078 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2082 CsrAllocateMessagePointer(CaptureBuffer
,
2083 TitleRequest
->Length
,
2084 (PVOID
*)&TitleRequest
->Title
);
2086 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2088 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetTitle
),
2089 sizeof(*TitleRequest
));
2090 if (!NT_SUCCESS(ApiMessage
.Status
))
2092 CsrFreeCaptureBuffer(CaptureBuffer
);
2093 BaseSetLastNTError(ApiMessage
.Status
);
2097 dwNumChars
= TitleRequest
->Length
/ (bUnicode
? sizeof(WCHAR
) : sizeof(CHAR
));
2101 memcpy(lpConsoleTitle
, TitleRequest
->Title
, TitleRequest
->Length
);
2104 ((LPWSTR
)lpConsoleTitle
)[dwNumChars
] = UNICODE_NULL
;
2106 ((LPSTR
)lpConsoleTitle
)[dwNumChars
] = ANSI_NULL
;
2109 CsrFreeCaptureBuffer(CaptureBuffer
);
2121 GetConsoleTitleW(LPWSTR lpConsoleTitle
,
2124 return IntGetConsoleTitle(lpConsoleTitle
, nSize
, TRUE
);
2134 GetConsoleTitleA(LPSTR lpConsoleTitle
,
2137 return IntGetConsoleTitle(lpConsoleTitle
, nSize
, FALSE
);
2142 IntSetConsoleTitle(CONST VOID
*lpConsoleTitle
, BOOLEAN bUnicode
)
2144 CONSOLE_API_MESSAGE ApiMessage
;
2145 PCONSOLE_GETSETCONSOLETITLE TitleRequest
= &ApiMessage
.Data
.TitleRequest
;
2146 PCSR_CAPTURE_BUFFER CaptureBuffer
;
2148 ULONG NumChars
= (ULONG
)(lpConsoleTitle
? (bUnicode
? wcslen(lpConsoleTitle
) : strlen(lpConsoleTitle
)) : 0);
2150 TitleRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
2151 TitleRequest
->Length
= NumChars
* (bUnicode
? sizeof(WCHAR
) : sizeof(CHAR
));
2152 TitleRequest
->Unicode
= bUnicode
;
2154 CaptureBuffer
= CsrAllocateCaptureBuffer(1, TitleRequest
->Length
);
2155 if (CaptureBuffer
== NULL
)
2157 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
2158 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2162 CsrCaptureMessageBuffer(CaptureBuffer
,
2163 (PVOID
)lpConsoleTitle
,
2164 TitleRequest
->Length
,
2165 (PVOID
*)&TitleRequest
->Title
);
2167 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2169 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetTitle
),
2170 sizeof(*TitleRequest
));
2172 CsrFreeCaptureBuffer(CaptureBuffer
);
2174 if (!NT_SUCCESS(ApiMessage
.Status
))
2176 BaseSetLastNTError(ApiMessage
.Status
);
2189 SetConsoleTitleW(LPCWSTR lpConsoleTitle
)
2191 return IntSetConsoleTitle(lpConsoleTitle
, TRUE
);
2201 SetConsoleTitleA(LPCSTR lpConsoleTitle
)
2203 return IntSetConsoleTitle(lpConsoleTitle
, FALSE
);
2212 CreateConsoleScreenBuffer(DWORD dwDesiredAccess
,
2214 CONST SECURITY_ATTRIBUTES
*lpSecurityAttributes
,
2216 LPVOID lpScreenBufferData
)
2218 CONSOLE_API_MESSAGE ApiMessage
;
2219 PCONSOLE_CREATESCREENBUFFER CreateScreenBufferRequest
= &ApiMessage
.Data
.CreateScreenBufferRequest
;
2220 PCSR_CAPTURE_BUFFER CaptureBuffer
= NULL
;
2221 PCONSOLE_GRAPHICS_BUFFER_INFO GraphicsBufferInfo
= lpScreenBufferData
;
2223 if ( (dwDesiredAccess
& ~(GENERIC_READ
| GENERIC_WRITE
)) ||
2224 (dwShareMode
& ~(FILE_SHARE_READ
| FILE_SHARE_WRITE
)) ||
2225 (dwFlags
!= CONSOLE_TEXTMODE_BUFFER
&& dwFlags
!= CONSOLE_GRAPHICS_BUFFER
) )
2227 SetLastError(ERROR_INVALID_PARAMETER
);
2228 return INVALID_HANDLE_VALUE
;
2231 CreateScreenBufferRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
2232 CreateScreenBufferRequest
->DesiredAccess
= dwDesiredAccess
;
2233 CreateScreenBufferRequest
->InheritHandle
=
2234 (lpSecurityAttributes
? lpSecurityAttributes
->bInheritHandle
: FALSE
);
2235 CreateScreenBufferRequest
->ShareMode
= dwShareMode
;
2236 CreateScreenBufferRequest
->ScreenBufferType
= dwFlags
;
2238 if (dwFlags
== CONSOLE_GRAPHICS_BUFFER
)
2240 if (CreateScreenBufferRequest
->InheritHandle
|| GraphicsBufferInfo
== NULL
)
2242 SetLastError(ERROR_INVALID_PARAMETER
);
2243 return INVALID_HANDLE_VALUE
;
2246 CreateScreenBufferRequest
->GraphicsBufferInfo
= *GraphicsBufferInfo
;
2248 CaptureBuffer
= CsrAllocateCaptureBuffer(1, GraphicsBufferInfo
->dwBitMapInfoLength
);
2249 if (CaptureBuffer
== NULL
)
2251 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2252 return INVALID_HANDLE_VALUE
;
2255 CsrCaptureMessageBuffer(CaptureBuffer
,
2256 (PVOID
)GraphicsBufferInfo
->lpBitMapInfo
,
2257 GraphicsBufferInfo
->dwBitMapInfoLength
,
2258 (PVOID
*)&CreateScreenBufferRequest
->GraphicsBufferInfo
.lpBitMapInfo
);
2261 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2263 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepCreateScreenBuffer
),
2264 sizeof(*CreateScreenBufferRequest
));
2266 if (CaptureBuffer
) CsrFreeCaptureBuffer(CaptureBuffer
);
2268 if (!NT_SUCCESS(ApiMessage
.Status
))
2270 BaseSetLastNTError(ApiMessage
.Status
);
2271 return INVALID_HANDLE_VALUE
;
2274 if (dwFlags
== CONSOLE_GRAPHICS_BUFFER
&& GraphicsBufferInfo
)
2276 GraphicsBufferInfo
->hMutex
= CreateScreenBufferRequest
->hMutex
; // CreateScreenBufferRequest->GraphicsBufferInfo.hMutex ;
2277 GraphicsBufferInfo
->lpBitMap
= CreateScreenBufferRequest
->lpBitMap
; // CreateScreenBufferRequest->GraphicsBufferInfo.lpBitMap;
2280 return CreateScreenBufferRequest
->OutputHandle
;
2292 CONSOLE_API_MESSAGE ApiMessage
;
2293 PCONSOLE_GETINPUTOUTPUTCP GetConsoleCPRequest
= &ApiMessage
.Data
.GetConsoleCPRequest
;
2295 /* Get the Input Code Page */
2296 GetConsoleCPRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
2297 GetConsoleCPRequest
->OutputCP
= FALSE
;
2299 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2301 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetCP
),
2302 sizeof(*GetConsoleCPRequest
));
2303 if (!NT_SUCCESS(ApiMessage
.Status
))
2305 BaseSetLastNTError(ApiMessage
.Status
);
2309 return GetConsoleCPRequest
->CodePage
;
2319 SetConsoleCP(UINT wCodePageID
)
2321 CONSOLE_API_MESSAGE ApiMessage
;
2322 PCONSOLE_SETINPUTOUTPUTCP SetConsoleCPRequest
= &ApiMessage
.Data
.SetConsoleCPRequest
;
2324 /* Set the Input Code Page */
2325 SetConsoleCPRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
2326 SetConsoleCPRequest
->CodePage
= wCodePageID
;
2327 SetConsoleCPRequest
->OutputCP
= FALSE
;
2328 /* SetConsoleCPRequest->EventHandle; */
2330 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2332 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetCP
),
2333 sizeof(*SetConsoleCPRequest
));
2334 if (!NT_SUCCESS(ApiMessage
.Status
))
2336 BaseSetLastNTError(ApiMessage
.Status
);
2350 GetConsoleOutputCP(VOID
)
2352 CONSOLE_API_MESSAGE ApiMessage
;
2353 PCONSOLE_GETINPUTOUTPUTCP GetConsoleCPRequest
= &ApiMessage
.Data
.GetConsoleCPRequest
;
2355 /* Get the Output Code Page */
2356 GetConsoleCPRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
2357 GetConsoleCPRequest
->OutputCP
= TRUE
;
2359 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2361 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetCP
),
2362 sizeof(*GetConsoleCPRequest
));
2363 if (!NT_SUCCESS(ApiMessage
.Status
))
2365 BaseSetLastNTError(ApiMessage
.Status
);
2369 return GetConsoleCPRequest
->CodePage
;
2379 SetConsoleOutputCP(UINT wCodePageID
)
2381 CONSOLE_API_MESSAGE ApiMessage
;
2382 PCONSOLE_SETINPUTOUTPUTCP SetConsoleCPRequest
= &ApiMessage
.Data
.SetConsoleCPRequest
;
2384 /* Set the Output Code Page */
2385 SetConsoleCPRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
2386 SetConsoleCPRequest
->CodePage
= wCodePageID
;
2387 SetConsoleCPRequest
->OutputCP
= TRUE
;
2388 /* SetConsoleCPRequest->EventHandle; */
2390 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2392 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetCP
),
2393 sizeof(*SetConsoleCPRequest
));
2394 if (!NT_SUCCESS(ApiMessage
.Status
))
2396 BaseSetLastNTError(ApiMessage
.Status
);
2409 GetConsoleProcessList(LPDWORD lpdwProcessList
,
2410 DWORD dwProcessCount
)
2412 CONSOLE_API_MESSAGE ApiMessage
;
2413 PCONSOLE_GETPROCESSLIST GetProcessListRequest
= &ApiMessage
.Data
.GetProcessListRequest
;
2414 PCSR_CAPTURE_BUFFER CaptureBuffer
;
2415 ULONG nProcesses
= 0;
2417 if (lpdwProcessList
== NULL
|| dwProcessCount
== 0)
2419 SetLastError(ERROR_INVALID_PARAMETER
);
2423 CaptureBuffer
= CsrAllocateCaptureBuffer(1, dwProcessCount
* sizeof(DWORD
));
2424 if (CaptureBuffer
== NULL
)
2426 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
2427 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2431 GetProcessListRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
2432 GetProcessListRequest
->ProcessCount
= dwProcessCount
;
2434 CsrAllocateMessagePointer(CaptureBuffer
,
2435 dwProcessCount
* sizeof(DWORD
),
2436 (PVOID
*)&GetProcessListRequest
->ProcessIdsList
);
2438 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2440 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetProcessList
),
2441 sizeof(*GetProcessListRequest
));
2442 if (!NT_SUCCESS(ApiMessage
.Status
))
2444 BaseSetLastNTError(ApiMessage
.Status
);
2448 nProcesses
= GetProcessListRequest
->ProcessCount
;
2449 if (dwProcessCount
>= nProcesses
)
2451 memcpy(lpdwProcessList
, GetProcessListRequest
->ProcessIdsList
, nProcesses
* sizeof(DWORD
));
2455 CsrFreeCaptureBuffer(CaptureBuffer
);
2465 GetConsoleSelectionInfo(PCONSOLE_SELECTION_INFO lpConsoleSelectionInfo
)
2467 CONSOLE_API_MESSAGE ApiMessage
;
2468 PCONSOLE_GETSELECTIONINFO GetSelectionInfoRequest
= &ApiMessage
.Data
.GetSelectionInfoRequest
;
2470 if (lpConsoleSelectionInfo
== NULL
)
2472 SetLastError(ERROR_INVALID_PARAMETER
);
2476 GetSelectionInfoRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
2478 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2480 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetSelectionInfo
),
2481 sizeof(*GetSelectionInfoRequest
));
2482 if (!NT_SUCCESS(ApiMessage
.Status
))
2484 BaseSetLastNTError(ApiMessage
.Status
);
2488 *lpConsoleSelectionInfo
= GetSelectionInfoRequest
->Info
;
2496 * @note Strongly inspired by AllocConsole.
2499 IntAttachConsole(DWORD ProcessId
,
2500 LPTHREAD_START_ROUTINE CtrlRoutine
,
2501 LPTHREAD_START_ROUTINE PropRoutine
,
2502 PCONSOLE_START_INFO ConsoleStartInfo
)
2504 BOOL Success
= TRUE
;
2507 CONSOLE_API_MESSAGE ApiMessage
;
2508 PCONSOLE_ATTACHCONSOLE AttachConsoleRequest
= &ApiMessage
.Data
.AttachConsoleRequest
;
2509 PCSR_CAPTURE_BUFFER CaptureBuffer
;
2511 AttachConsoleRequest
->ProcessId
= ProcessId
;
2512 AttachConsoleRequest
->CtrlRoutine
= CtrlRoutine
;
2513 AttachConsoleRequest
->PropRoutine
= PropRoutine
;
2515 CaptureBuffer
= CsrAllocateCaptureBuffer(1, sizeof(CONSOLE_START_INFO
));
2516 if (CaptureBuffer
== NULL
)
2518 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2523 CsrCaptureMessageBuffer(CaptureBuffer
,
2525 sizeof(CONSOLE_START_INFO
),
2526 (PVOID
*)&AttachConsoleRequest
->ConsoleStartInfo
);
2528 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2530 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepAttach
),
2531 sizeof(*AttachConsoleRequest
));
2532 if (!NT_SUCCESS(ApiMessage
.Status
))
2534 BaseSetLastNTError(ApiMessage
.Status
);
2539 // Is AttachConsoleRequest->ConsoleStartInfo->InitEvents aligned on handle boundary ????
2540 Status
= NtWaitForMultipleObjects(MAX_INIT_EVENTS
,
2541 AttachConsoleRequest
->ConsoleStartInfo
->InitEvents
,
2542 WaitAny
, FALSE
, NULL
);
2543 if (!NT_SUCCESS(Status
))
2545 BaseSetLastNTError(Status
);
2550 NtClose(AttachConsoleRequest
->ConsoleStartInfo
->InitEvents
[INIT_SUCCESS
]);
2551 NtClose(AttachConsoleRequest
->ConsoleStartInfo
->InitEvents
[INIT_FAILURE
]);
2552 if (Status
!= INIT_SUCCESS
)
2554 NtCurrentPeb()->ProcessParameters
->ConsoleHandle
= NULL
;
2559 RtlCopyMemory(ConsoleStartInfo
,
2560 AttachConsoleRequest
->ConsoleStartInfo
,
2561 sizeof(CONSOLE_START_INFO
));
2566 if (CaptureBuffer
) CsrFreeCaptureBuffer(CaptureBuffer
);
2572 AttachConsole(DWORD dwProcessId
)
2575 CONSOLE_START_INFO ConsoleStartInfo
;
2580 RtlEnterCriticalSection(&ConsoleLock
);
2582 if (NtCurrentPeb()->ProcessParameters
->ConsoleHandle
)
2584 DPRINT1("AttachConsole: Attaching a console to a process already having one\n");
2585 SetLastError(ERROR_ACCESS_DENIED
);
2590 /* Set up the console properties */
2591 SetUpConsoleInfo(FALSE
,
2598 Success
= IntAttachConsole(dwProcessId
,
2599 ConsoleControlDispatcher
,
2604 /* Set up the handles */
2605 SetUpHandles(&ConsoleStartInfo
);
2606 InputWaitHandle
= ConsoleStartInfo
.InputWaitHandle
;
2608 /* Initialize Console Ctrl Handling */
2609 InitializeCtrlHandling();
2611 /* Sets the current console locale for this thread */
2616 RtlLeaveCriticalSection(&ConsoleLock
);
2627 GetConsoleWindow(VOID
)
2629 CONSOLE_API_MESSAGE ApiMessage
;
2630 PCONSOLE_GETWINDOW GetWindowRequest
= &ApiMessage
.Data
.GetWindowRequest
;
2632 GetWindowRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
2634 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2636 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetConsoleWindow
),
2637 sizeof(*GetWindowRequest
));
2638 if (!NT_SUCCESS(ApiMessage
.Status
))
2640 BaseSetLastNTError(ApiMessage
.Status
);
2644 return GetWindowRequest
->WindowHandle
;
2654 SetConsoleIcon(HICON hIcon
)
2656 CONSOLE_API_MESSAGE ApiMessage
;
2657 PCONSOLE_SETICON SetIconRequest
= &ApiMessage
.Data
.SetIconRequest
;
2659 SetIconRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
2660 SetIconRequest
->IconHandle
= hIcon
;
2662 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2664 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetIcon
),
2665 sizeof(*SetIconRequest
));
2666 if (!NT_SUCCESS(ApiMessage
.Status
))
2668 BaseSetLastNTError(ApiMessage
.Status
);
2676 /******************************************************************************
2677 * \name SetConsoleInputExeNameW
2678 * \brief Sets the console input file name from a unicode string.
2679 * \param lpExeName Pointer to a unicode string with the name.
2680 * \return TRUE if successful, FALSE if unsuccsedful.
2681 * \remarks If lpExeName is 0 or the string length is 0 or greater than 255,
2682 * the function fails and sets last error to ERROR_INVALID_PARAMETER.
2687 SetConsoleInputExeNameW(IN LPWSTR lpExeName
)
2691 ExeLength
= lstrlenW(lpExeName
);
2692 if ((ExeLength
== 0) || (ExeLength
>= EXENAME_LENGTH
))
2694 /* Fail if string is empty or too long */
2695 SetLastError(ERROR_INVALID_PARAMETER
);
2699 RtlEnterCriticalSection(&ExeNameLock
);
2702 /* Set the input EXE name, not NULL terminated */
2703 RtlCopyMemory(ExeNameBuffer
, lpExeName
, ExeLength
* sizeof(WCHAR
));
2704 ExeNameLength
= (USHORT
)ExeLength
;
2708 RtlLeaveCriticalSection(&ExeNameLock
);
2716 /******************************************************************************
2717 * \name SetConsoleInputExeNameA
2718 * \brief Sets the console input file name from an ansi string.
2719 * \param lpExeName Pointer to an ansi string with the name.
2720 * \return TRUE if successful, FALSE if unsuccsedful.
2721 * \remarks If lpExeName is 0 or the string length is 0 or greater than 255,
2722 * the function fails and sets last error to ERROR_INVALID_PARAMETER.
2727 SetConsoleInputExeNameA(IN LPSTR lpExeName
)
2730 #ifdef USE_TEB_STATIC_USTR
2731 PUNICODE_STRING ExeNameU
;
2733 UNICODE_STRING ExeNameU
;
2735 ANSI_STRING ExeNameA
;
2736 #ifndef USE_TEB_STATIC_USTR
2737 WCHAR Buffer
[EXENAME_LENGTH
];
2740 #ifdef USE_TEB_STATIC_USTR
2742 * Use the TEB static UNICODE string for storage. It is already
2743 * initialized at process creation time by the Memory Manager.
2745 ExeNameU
= &NtCurrentTeb()->StaticUnicodeString
;
2748 /* Initialize string for conversion */
2749 RtlInitAnsiString(&ExeNameA
, lpExeName
);
2752 if ((ExeNameA
.Length
== 0) || (ExeNameA
.Length
>= EXENAME_LENGTH
))
2754 /* Fail if string is empty or too long */
2755 SetLastError(ERROR_INVALID_PARAMETER
);
2759 #ifndef USE_TEB_STATIC_USTR
2760 ExeNameU
.Length
= 0;
2761 ExeNameU
.MaximumLength
= (USHORT
)sizeof(Buffer
);
2762 ExeNameU
.Buffer
= Buffer
;
2765 #ifdef USE_TEB_STATIC_USTR
2766 Status
= RtlAnsiStringToUnicodeString(ExeNameU
, &ExeNameA
, FALSE
);
2768 Status
= RtlAnsiStringToUnicodeString(&ExeNameU
, &ExeNameA
, FALSE
);
2770 if (!NT_SUCCESS(Status
))
2772 /* Fail if string is empty or too long */
2773 if (Status
== STATUS_BUFFER_OVERFLOW
)
2774 SetLastError(ERROR_FILENAME_EXCED_RANGE
);
2776 SetLastError(ERROR_INVALID_PARAMETER
);
2781 #ifdef USE_TEB_STATIC_USTR
2782 return SetConsoleInputExeNameW(ExeNameU
->Buffer
);
2784 return SetConsoleInputExeNameW(ExeNameU
.Buffer
);
2789 /******************************************************************************
2790 * \name GetConsoleInputExeNameW
2791 * \brief Retrieves the console input file name as unicode string.
2792 * \param nBufferLength Length of the buffer in WCHARs.
2793 * Specify 0 to receive the needed buffer length.
2794 * \param lpBuffer Pointer to a buffer that receives the string.
2795 * \return Needed buffer size if \p nBufferLength is 0.
2796 * Otherwise 1 if successful, 2 if buffer is too small.
2797 * \remarks Sets last error value to ERROR_BUFFER_OVERFLOW if the buffer
2798 * is not big enough.
2803 GetConsoleInputExeNameW(IN DWORD nBufferLength
,
2804 OUT LPWSTR lpExeName
)
2806 if (nBufferLength
<= ExeNameLength
)
2808 /* Buffer is not large enough! Return the correct size. */
2809 SetLastError(ERROR_BUFFER_OVERFLOW
);
2810 return ExeNameLength
+ 1;
2813 RtlEnterCriticalSection(&ExeNameLock
);
2816 /* Copy the input EXE name and NULL-terminate it */
2817 RtlCopyMemory(lpExeName
, ExeNameBuffer
, ExeNameLength
* sizeof(WCHAR
));
2818 lpExeName
[ExeNameLength
] = UNICODE_NULL
;
2822 RtlLeaveCriticalSection(&ExeNameLock
);
2830 /******************************************************************************
2831 * \name GetConsoleInputExeNameA
2832 * \brief Retrieves the console input file name as ansi string.
2833 * \param nBufferLength Length of the buffer in CHARs.
2834 * \param lpBuffer Pointer to a buffer that receives the string.
2835 * \return 1 if successful, 2 if buffer is too small.
2836 * \remarks Sets last error value to ERROR_BUFFER_OVERFLOW if the buffer
2837 * is not big enough. The buffer receives as much characters as fit.
2842 GetConsoleInputExeNameA(IN DWORD nBufferLength
,
2843 OUT LPSTR lpExeName
)
2847 UNICODE_STRING BufferU
;
2848 ANSI_STRING BufferA
;
2849 WCHAR Buffer
[EXENAME_LENGTH
];
2851 /* Get the UNICODE name */
2852 ExeLength
= GetConsoleInputExeNameW(EXENAME_LENGTH
, Buffer
);
2854 if ((ExeLength
== 0) || (ExeLength
>= EXENAME_LENGTH
))
2857 /* Initialize the strings for conversion */
2858 RtlInitUnicodeString(&BufferU
, Buffer
);
2860 BufferA
.MaximumLength
= (USHORT
)nBufferLength
;
2861 BufferA
.Buffer
= lpExeName
;
2863 /* Convert UNICODE name to ANSI, copying as much chars as it can fit */
2864 Status
= RtlUnicodeStringToAnsiString(&BufferA
, &BufferU
, FALSE
);
2865 if (!NT_SUCCESS(Status
))
2867 if (Status
== STATUS_BUFFER_OVERFLOW
)
2869 SetLastError(ERROR_BUFFER_OVERFLOW
);
2870 return ExeLength
+ 1;
2872 SetLastError(ERROR_INVALID_PARAMETER
);
2880 GetConsoleCharType(HANDLE hConsole
, COORD Coord
, PDWORD Type
)
2889 GetConsoleCursorMode(HANDLE hConsole
, PBOOL pUnknown1
, PBOOL pUnknown2
)
2898 SetConsoleCursorMode(HANDLE hConsole
, BOOL Unknown1
, BOOL Unknown2
)
2907 GetConsoleNlsMode(HANDLE hConsole
, LPDWORD lpMode
)
2916 SetConsoleNlsMode(HANDLE hConsole
, DWORD dwMode
)
2925 SetConsoleLocalEUDC(DWORD Unknown1
, DWORD Unknown2
, DWORD Unknown3
, DWORD Unknown4
)
2934 RegisterConsoleIME(HWND hWnd
, LPDWORD ThreadId
)
2943 RegisterConsoleOS2(BOOL bUnknown
)
2952 SetConsoleOS2OemFormat(BOOL bUnknown
)
2961 UnregisterConsoleIME(VOID
)
2970 IntGetConsoleKeyboardLayoutName(OUT PVOID pszLayoutName
,
2973 CONSOLE_API_MESSAGE ApiMessage
;
2974 PCONSOLE_GETKBDLAYOUTNAME GetKbdLayoutNameRequest
= &ApiMessage
.Data
.GetKbdLayoutNameRequest
;
2976 /* Set up the data to send to the Console Server */
2977 GetKbdLayoutNameRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
2978 GetKbdLayoutNameRequest
->Ansi
= bAnsi
;
2980 /* Call the server */
2981 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2983 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetKeyboardLayoutName
),
2984 sizeof(*GetKbdLayoutNameRequest
));
2986 /* Check for success */
2987 if (!NT_SUCCESS(ApiMessage
.Status
))
2989 BaseSetLastNTError(ApiMessage
.Status
);
2993 /* Retrieve the results */
2996 /* Copy only KL_NAMELENGTH == 9 characters, ANSI or UNICODE */
2998 strncpy(pszLayoutName
, (PCHAR
)GetKbdLayoutNameRequest
->LayoutBuffer
, KL_NAMELENGTH
);
3000 wcsncpy(pszLayoutName
, (PWCHAR
)GetKbdLayoutNameRequest
->LayoutBuffer
, KL_NAMELENGTH
);
3002 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3004 SetLastError(ERROR_INVALID_ACCESS
);
3005 _SEH2_YIELD(return FALSE
);
3013 * @implemented (undocumented)
3018 GetConsoleKeyboardLayoutNameA(OUT LPSTR pszLayoutName
)
3020 return IntGetConsoleKeyboardLayoutName(pszLayoutName
, TRUE
);
3024 * @implemented (undocumented)
3029 GetConsoleKeyboardLayoutNameW(OUT LPWSTR pszLayoutName
)
3031 return IntGetConsoleKeyboardLayoutName(pszLayoutName
, FALSE
);
3039 SetLastConsoleEventActive(VOID
)
3041 CONSOLE_API_MESSAGE ApiMessage
;
3042 PCONSOLE_NOTIFYLASTCLOSE NotifyLastCloseRequest
= &ApiMessage
.Data
.NotifyLastCloseRequest
;
3044 /* Set the flag used by the console control dispatcher */
3045 LastCloseNotify
= TRUE
;
3047 /* Set up the input arguments */
3048 NotifyLastCloseRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
3050 /* Call CSRSS; just return the NTSTATUS cast to DWORD */
3051 return CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
3053 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepNotifyLastClose
),
3054 sizeof(*NotifyLastCloseRequest
));