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
7 * <jimtabor@adsl-64-217-116-74.dsl.hstntx.swbell.net>
10 /* INCLUDES *******************************************************************/
18 /* GLOBALS ********************************************************************/
20 extern RTL_CRITICAL_SECTION ConsoleLock
;
21 extern BOOL ConsoleInitialized
;
22 extern BOOL WINAPI
IsDebuggerPresent(VOID
);
24 /* Console reserved "file" names */
25 static LPCWSTR BaseConFileName
= CONSOLE_FILE_NAME
;
26 static LPCWSTR BaseConInputFileName
= CONSOLE_INPUT_FILE_NAME
;
27 static LPCWSTR BaseConOutputFileName
= CONSOLE_OUTPUT_FILE_NAME
;
29 PHANDLER_ROUTINE InitialHandler
[1];
30 PHANDLER_ROUTINE
* CtrlHandlers
;
32 ULONG NrAllocatedHandlers
;
33 BOOL LastCloseNotify
= FALSE
;
35 HANDLE InputWaitHandle
= INVALID_HANDLE_VALUE
;
37 #define INPUTEXENAME_BUFLEN 256
38 static WCHAR InputExeName
[INPUTEXENAME_BUFLEN
];
41 /* Default Console Control Handler ********************************************/
45 DefaultConsoleCtrlHandler(DWORD Event
)
47 DPRINT("Default handler called: %lx\n", Event
);
51 DPRINT("Ctrl-C Event\n");
54 case CTRL_BREAK_EVENT
:
55 DPRINT("Ctrl-Break Event\n");
58 case CTRL_CLOSE_EVENT
:
59 DPRINT("Ctrl Close Event\n");
62 case CTRL_LAST_CLOSE_EVENT
:
63 DPRINT("Ctrl Last Close Event\n");
66 case CTRL_LOGOFF_EVENT
:
67 DPRINT("Ctrl Logoff Event\n");
70 case CTRL_SHUTDOWN_EVENT
:
71 DPRINT("Ctrl Shutdown Event\n");
75 ExitProcess(CONTROL_C_EXIT
);
81 ConsoleControlDispatcher(IN LPVOID lpThreadParameter
)
84 DWORD CodeAndFlag
= PtrToUlong(lpThreadParameter
);
85 DWORD nCode
= CodeAndFlag
& MAXLONG
;
87 EXCEPTION_RECORD erException
;
89 DPRINT1("Console Dispatcher Active: %lx %lx\n", CodeAndFlag
, nCode
);
90 SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST
);
95 case CTRL_BREAK_EVENT
:
97 if (IsDebuggerPresent())
99 erException
.ExceptionCode
= (nCode
== CTRL_C_EVENT
?
100 DBG_CONTROL_C
: DBG_CONTROL_BREAK
);
101 erException
.ExceptionFlags
= 0;
102 erException
.ExceptionRecord
= NULL
;
103 erException
.ExceptionAddress
= DefaultConsoleCtrlHandler
;
104 erException
.NumberParameters
= 0;
108 RtlRaiseException(&erException
);
110 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
112 RtlEnterCriticalSection(&ConsoleLock
);
114 if ((nCode
!= CTRL_C_EVENT
) ||
115 (NtCurrentPeb()->ProcessParameters
->ConsoleFlags
!= 1))
117 for (i
= NrCtrlHandlers
; i
> 0; i
--)
119 if (CtrlHandlers
[i
- 1](nCode
)) break;
123 RtlLeaveCriticalSection(&ConsoleLock
);
132 case CTRL_CLOSE_EVENT
:
133 case CTRL_LOGOFF_EVENT
:
134 case CTRL_SHUTDOWN_EVENT
:
137 case CTRL_LAST_CLOSE_EVENT
:
139 * In case the console app hasn't register for last close notification,
140 * just kill this console handler thread. We don't want that such apps
141 * get killed for unexpected reasons. On the contrary apps that registered
142 * can be killed because they expect to be.
144 if (!LastCloseNotify
) ExitThread(0);
148 ExitProcess(CONTROL_C_EXIT
);
156 ASSERT(ConsoleInitialized
);
158 RtlEnterCriticalSection(&ConsoleLock
);
161 if ((nCode
!= CTRL_C_EVENT
) || (NtCurrentPeb()->ProcessParameters
->ConsoleFlags
!= 1))
163 for (i
= NrCtrlHandlers
; i
> 0; i
--)
166 (CodeAndFlag
& MINLONG
) &&
167 ((nCode
== CTRL_LOGOFF_EVENT
) || (nCode
== CTRL_SHUTDOWN_EVENT
)))
169 DPRINT("Skipping system/service apps\n");
173 if (CtrlHandlers
[i
- 1](nCode
))
177 case CTRL_CLOSE_EVENT
:
178 case CTRL_LAST_CLOSE_EVENT
:
179 case CTRL_LOGOFF_EVENT
:
180 case CTRL_SHUTDOWN_EVENT
:
181 nExitCode
= CodeAndFlag
;
189 RtlLeaveCriticalSection(&ConsoleLock
);
191 ExitThread(nExitCode
);
192 return STATUS_SUCCESS
;
197 InitConsoleCtrlHandling(VOID
)
199 /* Initialize Console Ctrl Handler */
200 NrAllocatedHandlers
= NrCtrlHandlers
= 1;
201 CtrlHandlers
= InitialHandler
;
202 CtrlHandlers
[0] = DefaultConsoleCtrlHandler
;
206 /* FUNCTIONS ******************************************************************/
209 IntCheckForConsoleFileName(IN LPCWSTR pszName
,
210 IN DWORD dwDesiredAccess
)
212 LPCWSTR ConsoleName
= pszName
;
213 ULONG DeviceNameInfo
;
216 * Check whether we deal with a DOS device, and if so,
217 * strip the path till the file name.
218 * Therefore, things like \\.\CON or C:\some_path\CONIN$
219 * are transformed into CON or CONIN$, for example.
221 DeviceNameInfo
= RtlIsDosDeviceName_U(pszName
);
222 if (DeviceNameInfo
!= 0)
224 ConsoleName
= (LPCWSTR
)((ULONG_PTR
)ConsoleName
+ ((DeviceNameInfo
>> 16) & 0xFFFF));
227 /* Return a standard console "file" name according to what we passed in parameters */
228 if (_wcsicmp(ConsoleName
, BaseConInputFileName
) == 0)
230 return BaseConInputFileName
;
232 else if (_wcsicmp(ConsoleName
, BaseConOutputFileName
) == 0)
234 return BaseConOutputFileName
;
236 else if (_wcsicmp(ConsoleName
, BaseConFileName
) == 0)
238 if ((dwDesiredAccess
& (GENERIC_READ
| GENERIC_WRITE
)) == GENERIC_READ
)
240 return BaseConInputFileName
;
242 else if ((dwDesiredAccess
& (GENERIC_READ
| GENERIC_WRITE
)) == GENERIC_WRITE
)
244 return BaseConOutputFileName
;
248 /* If we are there, that means that either the file name or the desired access are wrong */
254 * @implemented (Undocumented)
255 * @note See http://undoc.airesoft.co.uk/kernel32.dll/ConsoleMenuControl.php
259 ConsoleMenuControl(HANDLE hConsoleOutput
,
263 CONSOLE_API_MESSAGE ApiMessage
;
264 PCONSOLE_MENUCONTROL MenuControlRequest
= &ApiMessage
.Data
.MenuControlRequest
;
266 MenuControlRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
267 MenuControlRequest
->OutputHandle
= hConsoleOutput
;
268 MenuControlRequest
->CmdIdLow
= dwCmdIdLow
;
269 MenuControlRequest
->CmdIdHigh
= dwCmdIdHigh
;
270 MenuControlRequest
->MenuHandle
= NULL
;
272 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
274 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepMenuControl
),
275 sizeof(*MenuControlRequest
));
277 return MenuControlRequest
->MenuHandle
;
286 DuplicateConsoleHandle(HANDLE hConsole
,
287 DWORD dwDesiredAccess
,
291 CONSOLE_API_MESSAGE ApiMessage
;
292 PCONSOLE_DUPLICATEHANDLE DuplicateHandleRequest
= &ApiMessage
.Data
.DuplicateHandleRequest
;
294 if ( (dwOptions
& ~(DUPLICATE_CLOSE_SOURCE
| DUPLICATE_SAME_ACCESS
)) ||
295 (!(dwOptions
& DUPLICATE_SAME_ACCESS
) &&
296 (dwDesiredAccess
& ~(GENERIC_READ
| GENERIC_WRITE
))) )
298 SetLastError(ERROR_INVALID_PARAMETER
);
299 return INVALID_HANDLE_VALUE
;
302 DuplicateHandleRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
303 DuplicateHandleRequest
->SourceHandle
= hConsole
;
304 DuplicateHandleRequest
->DesiredAccess
= dwDesiredAccess
;
305 DuplicateHandleRequest
->InheritHandle
= bInheritHandle
;
306 DuplicateHandleRequest
->Options
= dwOptions
;
308 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
310 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepDuplicateHandle
),
311 sizeof(*DuplicateHandleRequest
));
312 if (!NT_SUCCESS(ApiMessage
.Status
))
314 BaseSetLastNTError(ApiMessage
.Status
);
315 return INVALID_HANDLE_VALUE
;
318 return DuplicateHandleRequest
->TargetHandle
;
327 GetConsoleHandleInformation(IN HANDLE hHandle
,
328 OUT LPDWORD lpdwFlags
)
330 CONSOLE_API_MESSAGE ApiMessage
;
331 PCONSOLE_GETHANDLEINFO GetHandleInfoRequest
= &ApiMessage
.Data
.GetHandleInfoRequest
;
333 GetHandleInfoRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
334 GetHandleInfoRequest
->Handle
= hHandle
;
336 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
338 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetHandleInformation
),
339 sizeof(*GetHandleInfoRequest
));
340 if (!NT_SUCCESS(ApiMessage
.Status
))
342 BaseSetLastNTError(ApiMessage
.Status
);
346 *lpdwFlags
= GetHandleInfoRequest
->Flags
;
357 SetConsoleHandleInformation(IN HANDLE hHandle
,
361 CONSOLE_API_MESSAGE ApiMessage
;
362 PCONSOLE_SETHANDLEINFO SetHandleInfoRequest
= &ApiMessage
.Data
.SetHandleInfoRequest
;
364 SetHandleInfoRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
365 SetHandleInfoRequest
->Handle
= hHandle
;
366 SetHandleInfoRequest
->Mask
= dwMask
;
367 SetHandleInfoRequest
->Flags
= dwFlags
;
369 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
371 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetHandleInformation
),
372 sizeof(*SetHandleInfoRequest
));
373 if (!NT_SUCCESS(ApiMessage
.Status
))
375 BaseSetLastNTError(ApiMessage
.Status
);
388 GetConsoleDisplayMode(LPDWORD lpModeFlags
)
390 CONSOLE_API_MESSAGE ApiMessage
;
391 PCONSOLE_GETDISPLAYMODE GetDisplayModeRequest
= &ApiMessage
.Data
.GetDisplayModeRequest
;
393 if (lpModeFlags
== NULL
)
395 SetLastError(ERROR_INVALID_PARAMETER
);
399 GetDisplayModeRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
401 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
403 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetDisplayMode
),
404 sizeof(*GetDisplayModeRequest
));
405 if (!NT_SUCCESS(ApiMessage
.Status
))
407 BaseSetLastNTError(ApiMessage
.Status
);
411 *lpModeFlags
= GetDisplayModeRequest
->DisplayMode
; // ModeFlags
418 * @unimplemented (Undocumented)
422 GetConsoleFontInfo(HANDLE hConsoleOutput
,
425 PCONSOLE_FONT_INFO lpConsoleFontInfo
)
427 DPRINT1("GetConsoleFontInfo(0x%p, %d, %lu, 0x%p) UNIMPLEMENTED!\n", hConsoleOutput
, bMaximumWindow
, nFontCount
, lpConsoleFontInfo
);
428 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
438 GetConsoleFontSize(HANDLE hConsoleOutput
,
441 COORD Empty
= {0, 0};
442 DPRINT1("GetConsoleFontSize(0x%p, 0x%x) UNIMPLEMENTED!\n", hConsoleOutput
, nFont
);
443 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
449 * @implemented (Undocumented)
453 GetConsoleHardwareState(HANDLE hConsoleOutput
,
457 CONSOLE_API_MESSAGE ApiMessage
;
458 PCONSOLE_GETSETHWSTATE HardwareStateRequest
= &ApiMessage
.Data
.HardwareStateRequest
;
460 DPRINT1("GetConsoleHardwareState(%lu, 0x%p) UNIMPLEMENTED!\n", Flags
, State
);
462 if (Flags
== NULL
|| State
== NULL
)
464 SetLastError(ERROR_INVALID_PARAMETER
);
468 HardwareStateRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
469 HardwareStateRequest
->OutputHandle
= hConsoleOutput
;
471 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
473 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetHardwareState
),
474 sizeof(*HardwareStateRequest
));
475 if (!NT_SUCCESS(ApiMessage
.Status
))
477 BaseSetLastNTError(ApiMessage
.Status
);
481 *Flags
= HardwareStateRequest
->Flags
;
482 *State
= HardwareStateRequest
->State
;
489 * @implemented (Undocumented)
493 GetConsoleInputWaitHandle(VOID
)
495 return InputWaitHandle
;
504 GetCurrentConsoleFont(HANDLE hConsoleOutput
,
506 PCONSOLE_FONT_INFO lpConsoleCurrentFont
)
508 DPRINT1("GetCurrentConsoleFont(0x%p, 0x%x, 0x%p) UNIMPLEMENTED!\n", hConsoleOutput
, bMaximumWindow
, lpConsoleCurrentFont
);
509 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
515 * @unimplemented (Undocumented)
519 GetNumberOfConsoleFonts(VOID
)
521 DPRINT1("GetNumberOfConsoleFonts() UNIMPLEMENTED!\n");
522 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
528 * @implemented (Undocumented)
529 * @note See http://blog.airesoft.co.uk/2012/10/things-ms-can-do-that-they-dont-tell-you-about-console-graphics/
533 InvalidateConsoleDIBits(IN HANDLE hConsoleOutput
,
534 IN PSMALL_RECT lpRect
)
536 CONSOLE_API_MESSAGE ApiMessage
;
537 PCONSOLE_INVALIDATEDIBITS InvalidateDIBitsRequest
= &ApiMessage
.Data
.InvalidateDIBitsRequest
;
541 SetLastError(ERROR_INVALID_PARAMETER
);
545 InvalidateDIBitsRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
546 InvalidateDIBitsRequest
->OutputHandle
= hConsoleOutput
;
547 InvalidateDIBitsRequest
->Region
= *lpRect
;
549 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
551 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepInvalidateBitMapRect
),
552 sizeof(*InvalidateDIBitsRequest
));
553 if (!NT_SUCCESS(ApiMessage
.Status
))
555 BaseSetLastNTError(ApiMessage
.Status
);
564 * @unimplemented (Undocumented)
568 OpenConsoleW(LPCWSTR wsName
,
569 DWORD dwDesiredAccess
,
573 CONSOLE_API_MESSAGE ApiMessage
;
574 PCONSOLE_OPENCONSOLE OpenConsoleRequest
= &ApiMessage
.Data
.OpenConsoleRequest
;
575 CONSOLE_HANDLE_TYPE HandleType
;
577 if (wsName
&& (_wcsicmp(wsName
, BaseConInputFileName
) == 0))
579 HandleType
= HANDLE_INPUT
;
581 else if (wsName
&& (_wcsicmp(wsName
, BaseConOutputFileName
) == 0))
583 HandleType
= HANDLE_OUTPUT
;
587 SetLastError(ERROR_INVALID_PARAMETER
);
588 return INVALID_HANDLE_VALUE
;
591 if ( (dwDesiredAccess
& ~(GENERIC_READ
| GENERIC_WRITE
)) ||
592 (dwShareMode
& ~(FILE_SHARE_READ
| FILE_SHARE_WRITE
)) )
594 SetLastError(ERROR_INVALID_PARAMETER
);
595 return INVALID_HANDLE_VALUE
;
598 OpenConsoleRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
599 OpenConsoleRequest
->HandleType
= HandleType
;
600 OpenConsoleRequest
->DesiredAccess
= dwDesiredAccess
;
601 OpenConsoleRequest
->InheritHandle
= bInheritHandle
;
602 OpenConsoleRequest
->ShareMode
= dwShareMode
;
604 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
606 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepOpenConsole
),
607 sizeof(*OpenConsoleRequest
));
608 if (!NT_SUCCESS(ApiMessage
.Status
))
610 BaseSetLastNTError(ApiMessage
.Status
);
611 return INVALID_HANDLE_VALUE
;
614 return OpenConsoleRequest
->Handle
;
619 * @implemented (Undocumented)
620 * @note See http://undoc.airesoft.co.uk/kernel32.dll/SetConsoleCursor.php
624 SetConsoleCursor(HANDLE hConsoleOutput
,
627 CONSOLE_API_MESSAGE ApiMessage
;
628 PCONSOLE_SETCURSOR SetCursorRequest
= &ApiMessage
.Data
.SetCursorRequest
;
630 SetCursorRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
631 SetCursorRequest
->OutputHandle
= hConsoleOutput
;
632 SetCursorRequest
->CursorHandle
= hCursor
;
634 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
636 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetCursor
),
637 sizeof(*SetCursorRequest
));
638 if (!NT_SUCCESS(ApiMessage
.Status
))
640 BaseSetLastNTError(ApiMessage
.Status
);
653 SetConsoleDisplayMode(HANDLE hConsoleOutput
,
654 DWORD dwFlags
, // dwModeFlags
655 PCOORD lpNewScreenBufferDimensions
)
657 CONSOLE_API_MESSAGE ApiMessage
;
658 PCONSOLE_SETDISPLAYMODE SetDisplayModeRequest
= &ApiMessage
.Data
.SetDisplayModeRequest
;
660 SetDisplayModeRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
661 SetDisplayModeRequest
->OutputHandle
= hConsoleOutput
;
662 SetDisplayModeRequest
->DisplayMode
= dwFlags
; // ModeFlags ; dwModeFlags
663 SetDisplayModeRequest
->NewSBDim
.X
= 0;
664 SetDisplayModeRequest
->NewSBDim
.Y
= 0;
665 /* SetDisplayModeRequest->EventHandle; */
667 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
669 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetDisplayMode
),
670 sizeof(*SetDisplayModeRequest
));
671 if (!NT_SUCCESS(ApiMessage
.Status
))
673 BaseSetLastNTError(ApiMessage
.Status
);
677 if (lpNewScreenBufferDimensions
)
678 *lpNewScreenBufferDimensions
= SetDisplayModeRequest
->NewSBDim
;
685 * @unimplemented (Undocumented)
689 SetConsoleFont(HANDLE hConsoleOutput
,
692 DPRINT1("SetConsoleFont(0x%p, %lu) UNIMPLEMENTED!\n", hConsoleOutput
, nFont
);
693 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
699 * @implemented (Undocumented)
703 SetConsoleHardwareState(HANDLE hConsoleOutput
,
707 CONSOLE_API_MESSAGE ApiMessage
;
708 PCONSOLE_GETSETHWSTATE HardwareStateRequest
= &ApiMessage
.Data
.HardwareStateRequest
;
710 DPRINT1("SetConsoleHardwareState(%lu, %lu) UNIMPLEMENTED!\n", Flags
, State
);
712 HardwareStateRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
713 HardwareStateRequest
->OutputHandle
= hConsoleOutput
;
714 HardwareStateRequest
->Flags
= Flags
;
715 HardwareStateRequest
->State
= State
;
717 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
719 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetHardwareState
),
720 sizeof(*HardwareStateRequest
));
721 if (!NT_SUCCESS(ApiMessage
.Status
))
723 BaseSetLastNTError(ApiMessage
.Status
);
732 * @unimplemented (Undocumented)
736 SetConsoleKeyShortcuts(DWORD Unknown0
,
741 DPRINT1("SetConsoleKeyShortcuts(0x%x, 0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
, Unknown2
, Unknown3
);
742 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
748 * @implemented (Undocumented)
749 * @note See http://undoc.airesoft.co.uk/kernel32.dll/SetConsoleMaximumWindowSize.php
750 * Does nothing, returns TRUE only. Checked on Windows Server 2003.
754 SetConsoleMaximumWindowSize(HANDLE hConsoleOutput
,
757 DPRINT1("SetConsoleMaximumWindowSize(0x%p, {%d, %d}) does nothing\n",
758 hConsoleOutput
, dwMaximumSize
.X
, dwMaximumSize
.Y
);
764 * @implemented (Undocumented)
768 SetConsoleMenuClose(BOOL bEnable
)
770 CONSOLE_API_MESSAGE ApiMessage
;
771 PCONSOLE_SETMENUCLOSE SetMenuCloseRequest
= &ApiMessage
.Data
.SetMenuCloseRequest
;
773 SetMenuCloseRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
774 SetMenuCloseRequest
->Enable
= bEnable
;
776 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
778 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetMenuClose
),
779 sizeof(*SetMenuCloseRequest
));
780 if (!NT_SUCCESS(ApiMessage
.Status
))
782 BaseSetLastNTError(ApiMessage
.Status
);
791 * @implemented (Undocumented)
792 * @note See http://comments.gmane.org/gmane.comp.lang.harbour.devel/27844
793 * Usage example: https://github.com/harbour/core/commit/d79a1b7b812cbde6ddf718ebfd6939a24f633e52
797 SetConsolePalette(HANDLE hConsoleOutput
,
801 CONSOLE_API_MESSAGE ApiMessage
;
802 PCONSOLE_SETPALETTE SetPaletteRequest
= &ApiMessage
.Data
.SetPaletteRequest
;
804 SetPaletteRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
805 SetPaletteRequest
->OutputHandle
= hConsoleOutput
;
806 SetPaletteRequest
->PaletteHandle
= hPalette
;
807 SetPaletteRequest
->Usage
= dwUsage
;
809 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
811 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetPalette
),
812 sizeof(*SetPaletteRequest
));
813 if (!NT_SUCCESS(ApiMessage
.Status
))
815 BaseSetLastNTError(ApiMessage
.Status
);
823 * @implemented (Undocumented)
824 * @note See http://undoc.airesoft.co.uk/kernel32.dll/ShowConsoleCursor.php
828 ShowConsoleCursor(HANDLE hConsoleOutput
,
831 CONSOLE_API_MESSAGE ApiMessage
;
832 PCONSOLE_SHOWCURSOR ShowCursorRequest
= &ApiMessage
.Data
.ShowCursorRequest
;
834 ShowCursorRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
835 ShowCursorRequest
->OutputHandle
= hConsoleOutput
;
836 ShowCursorRequest
->Show
= bShow
;
837 ShowCursorRequest
->RefCount
= 0;
839 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
841 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepShowCursor
),
842 sizeof(*ShowCursorRequest
));
844 return ShowCursorRequest
->RefCount
;
849 * FUNCTION: Checks whether the given handle is a valid console handle.
852 * hIoHandle - Handle to be checked.
855 * TRUE : Handle is a valid console handle.
856 * FALSE: Handle is not a valid console handle.
858 * STATUS: Officially undocumented
864 VerifyConsoleIoHandle(HANDLE hIoHandle
)
866 CONSOLE_API_MESSAGE ApiMessage
;
867 PCONSOLE_VERIFYHANDLE VerifyHandleRequest
= &ApiMessage
.Data
.VerifyHandleRequest
;
869 VerifyHandleRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
870 VerifyHandleRequest
->Handle
= hIoHandle
;
871 VerifyHandleRequest
->IsValid
= FALSE
;
873 /* If the process is not attached to a console, return invalid handle */
874 if (VerifyHandleRequest
->ConsoleHandle
== NULL
) return FALSE
;
876 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
878 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepVerifyIoHandle
),
879 sizeof(*VerifyHandleRequest
));
880 if (!NT_SUCCESS(ApiMessage
.Status
))
882 BaseSetLastNTError(ApiMessage
.Status
);
886 return VerifyHandleRequest
->IsValid
;
891 * @implemented (Undocumented)
895 CloseConsoleHandle(HANDLE hHandle
)
897 CONSOLE_API_MESSAGE ApiMessage
;
898 PCONSOLE_CLOSEHANDLE CloseHandleRequest
= &ApiMessage
.Data
.CloseHandleRequest
;
900 CloseHandleRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
901 CloseHandleRequest
->Handle
= hHandle
;
903 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
905 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepCloseHandle
),
906 sizeof(*CloseHandleRequest
));
907 if (!NT_SUCCESS(ApiMessage
.Status
))
909 BaseSetLastNTError(ApiMessage
.Status
);
922 GetStdHandle(DWORD nStdHandle
)
924 * FUNCTION: Get a handle for the standard input, standard output
925 * and a standard error device.
928 * nStdHandle - Specifies the device for which to return the handle.
930 * RETURNS: If the function succeeds, the return value is the handle
931 * of the specified device. Otherwise the value is INVALID_HANDLE_VALUE.
934 PRTL_USER_PROCESS_PARAMETERS Ppb
= NtCurrentPeb()->ProcessParameters
;
935 HANDLE Handle
= INVALID_HANDLE_VALUE
;
939 case STD_INPUT_HANDLE
:
940 Handle
= Ppb
->StandardInput
;
943 case STD_OUTPUT_HANDLE
:
944 Handle
= Ppb
->StandardOutput
;
947 case STD_ERROR_HANDLE
:
948 Handle
= Ppb
->StandardError
;
952 /* If the returned handle is invalid, set last error */
953 if (Handle
== INVALID_HANDLE_VALUE
) SetLastError(ERROR_INVALID_HANDLE
);
964 SetStdHandle(DWORD nStdHandle
,
967 * FUNCTION: Set the handle for the standard input, standard output or
968 * the standard error device.
971 * nStdHandle - Specifies the handle to be set.
972 * hHandle - The handle to set.
974 * RETURNS: TRUE if the function succeeds, FALSE otherwise.
977 PRTL_USER_PROCESS_PARAMETERS Ppb
= NtCurrentPeb()->ProcessParameters
;
979 /* No need to check if hHandle == INVALID_HANDLE_VALUE */
983 case STD_INPUT_HANDLE
:
984 Ppb
->StandardInput
= hHandle
;
987 case STD_OUTPUT_HANDLE
:
988 Ppb
->StandardOutput
= hHandle
;
991 case STD_ERROR_HANDLE
:
992 Ppb
->StandardError
= hHandle
;
996 /* nStdHandle was invalid, bail out */
997 SetLastError(ERROR_INVALID_HANDLE
);
1002 /*--------------------------------------------------------------
1012 PRTL_USER_PROCESS_PARAMETERS Parameters
= NtCurrentPeb()->ProcessParameters
;
1013 CONSOLE_API_MESSAGE ApiMessage
;
1014 PCONSOLE_ALLOCCONSOLE AllocConsoleRequest
= &ApiMessage
.Data
.AllocConsoleRequest
;
1015 PCSR_CAPTURE_BUFFER CaptureBuffer
;
1017 if (Parameters
->ConsoleHandle
)
1019 DPRINT1("AllocConsole: Allocating a console to a process already having one\n");
1020 SetLastError(ERROR_ACCESS_DENIED
);
1024 CaptureBuffer
= CsrAllocateCaptureBuffer(1, sizeof(CONSOLE_START_INFO
));
1025 if (CaptureBuffer
== NULL
)
1027 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
1028 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1032 CsrAllocateMessagePointer(CaptureBuffer
,
1033 sizeof(CONSOLE_START_INFO
),
1034 (PVOID
*)&AllocConsoleRequest
->ConsoleStartInfo
);
1036 InitConsoleInfo(AllocConsoleRequest
->ConsoleStartInfo
,
1037 &Parameters
->ImagePathName
);
1039 AllocConsoleRequest
->ConsoleHandle
= NULL
;
1040 AllocConsoleRequest
->CtrlDispatcher
= ConsoleControlDispatcher
;
1041 AllocConsoleRequest
->PropDispatcher
= PropDialogHandler
;
1043 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1045 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepAlloc
),
1046 sizeof(CONSOLE_ALLOCCONSOLE
));
1048 CsrFreeCaptureBuffer(CaptureBuffer
);
1050 if (!NT_SUCCESS(Status
))
1052 BaseSetLastNTError(Status
);
1056 Parameters
->ConsoleHandle
= AllocConsoleRequest
->ConsoleHandle
;
1057 SetStdHandle(STD_INPUT_HANDLE
, AllocConsoleRequest
->InputHandle
);
1058 SetStdHandle(STD_OUTPUT_HANDLE
, AllocConsoleRequest
->OutputHandle
);
1059 SetStdHandle(STD_ERROR_HANDLE
, AllocConsoleRequest
->ErrorHandle
);
1061 /* Initialize Console Ctrl Handler */
1062 InitConsoleCtrlHandling();
1064 InputWaitHandle
= AllocConsoleRequest
->InputWaitHandle
;
1070 /*--------------------------------------------------------------
1079 // AG: I'm not sure if this is correct (what happens to std handles?)
1080 // but I just tried to reverse what AllocConsole() does...
1083 CONSOLE_API_MESSAGE ApiMessage
;
1085 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1087 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepFree
),
1088 sizeof(CONSOLE_FREECONSOLE
));
1089 if (!NT_SUCCESS(Status
))
1091 BaseSetLastNTError(Status
);
1095 NtCurrentPeb()->ProcessParameters
->ConsoleHandle
= NULL
;
1097 CloseHandle(InputWaitHandle
);
1098 InputWaitHandle
= INVALID_HANDLE_VALUE
;
1104 /*--------------------------------------------------------------
1105 * GetConsoleScreenBufferInfo
1111 GetConsoleScreenBufferInfo(HANDLE hConsoleOutput
,
1112 PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo
)
1114 CONSOLE_API_MESSAGE ApiMessage
;
1115 PCONSOLE_GETSCREENBUFFERINFO ScreenBufferInfoRequest
= &ApiMessage
.Data
.ScreenBufferInfoRequest
;
1117 if (lpConsoleScreenBufferInfo
== NULL
)
1119 SetLastError(ERROR_INVALID_PARAMETER
);
1123 ScreenBufferInfoRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1124 ScreenBufferInfoRequest
->OutputHandle
= hConsoleOutput
;
1126 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1128 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetScreenBufferInfo
),
1129 sizeof(*ScreenBufferInfoRequest
));
1130 if (!NT_SUCCESS(ApiMessage
.Status
))
1132 BaseSetLastNTError(ApiMessage
.Status
);
1136 lpConsoleScreenBufferInfo
->dwSize
= ScreenBufferInfoRequest
->ScreenBufferSize
;
1137 lpConsoleScreenBufferInfo
->dwCursorPosition
= ScreenBufferInfoRequest
->CursorPosition
;
1138 lpConsoleScreenBufferInfo
->wAttributes
= ScreenBufferInfoRequest
->Attributes
;
1139 lpConsoleScreenBufferInfo
->srWindow
.Left
= ScreenBufferInfoRequest
->ViewOrigin
.X
;
1140 lpConsoleScreenBufferInfo
->srWindow
.Top
= ScreenBufferInfoRequest
->ViewOrigin
.Y
;
1141 lpConsoleScreenBufferInfo
->srWindow
.Right
= ScreenBufferInfoRequest
->ViewOrigin
.X
+ ScreenBufferInfoRequest
->ViewSize
.X
- 1;
1142 lpConsoleScreenBufferInfo
->srWindow
.Bottom
= ScreenBufferInfoRequest
->ViewOrigin
.Y
+ ScreenBufferInfoRequest
->ViewSize
.Y
- 1;
1143 lpConsoleScreenBufferInfo
->dwMaximumWindowSize
= ScreenBufferInfoRequest
->MaximumViewSize
;
1149 /*--------------------------------------------------------------
1150 * SetConsoleCursorPosition
1156 SetConsoleCursorPosition(HANDLE hConsoleOutput
,
1157 COORD dwCursorPosition
)
1159 CONSOLE_API_MESSAGE ApiMessage
;
1160 PCONSOLE_SETCURSORPOSITION SetCursorPositionRequest
= &ApiMessage
.Data
.SetCursorPositionRequest
;
1162 SetCursorPositionRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1163 SetCursorPositionRequest
->OutputHandle
= hConsoleOutput
;
1164 SetCursorPositionRequest
->Position
= dwCursorPosition
;
1166 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1168 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetCursorPosition
),
1169 sizeof(*SetCursorPositionRequest
));
1170 if (!NT_SUCCESS(ApiMessage
.Status
))
1172 BaseSetLastNTError(ApiMessage
.Status
);
1180 /*--------------------------------------------------------------
1187 GetConsoleMode(HANDLE hConsoleHandle
,
1190 CONSOLE_API_MESSAGE ApiMessage
;
1191 PCONSOLE_GETSETCONSOLEMODE ConsoleModeRequest
= &ApiMessage
.Data
.ConsoleModeRequest
;
1195 SetLastError(ERROR_INVALID_PARAMETER
);
1199 ConsoleModeRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1200 ConsoleModeRequest
->Handle
= hConsoleHandle
;
1202 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1204 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetMode
),
1205 sizeof(*ConsoleModeRequest
));
1206 if (!NT_SUCCESS(ApiMessage
.Status
))
1208 BaseSetLastNTError(ApiMessage
.Status
);
1212 *lpMode
= ConsoleModeRequest
->Mode
;
1218 /*--------------------------------------------------------------
1225 SetConsoleMode(HANDLE hConsoleHandle
,
1228 CONSOLE_API_MESSAGE ApiMessage
;
1229 PCONSOLE_GETSETCONSOLEMODE ConsoleModeRequest
= &ApiMessage
.Data
.ConsoleModeRequest
;
1231 ConsoleModeRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1232 ConsoleModeRequest
->Handle
= hConsoleHandle
;
1233 ConsoleModeRequest
->Mode
= dwMode
;
1235 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1237 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetMode
),
1238 sizeof(*ConsoleModeRequest
));
1239 if (!NT_SUCCESS(ApiMessage
.Status
))
1241 BaseSetLastNTError(ApiMessage
.Status
);
1249 /*--------------------------------------------------------------
1250 * GetNumberOfConsoleInputEvents
1256 GetNumberOfConsoleInputEvents(HANDLE hConsoleInput
,
1257 LPDWORD lpNumberOfEvents
)
1259 CONSOLE_API_MESSAGE ApiMessage
;
1260 PCONSOLE_GETNUMINPUTEVENTS GetNumInputEventsRequest
= &ApiMessage
.Data
.GetNumInputEventsRequest
;
1262 GetNumInputEventsRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1263 GetNumInputEventsRequest
->InputHandle
= hConsoleInput
;
1264 GetNumInputEventsRequest
->NumberOfEvents
= 0;
1266 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1268 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetNumberOfInputEvents
),
1269 sizeof(*GetNumInputEventsRequest
));
1270 if (!NT_SUCCESS(ApiMessage
.Status
))
1272 BaseSetLastNTError(ApiMessage
.Status
);
1276 if (lpNumberOfEvents
== NULL
)
1278 SetLastError(ERROR_INVALID_ACCESS
);
1282 *lpNumberOfEvents
= GetNumInputEventsRequest
->NumberOfEvents
;
1288 /*--------------------------------------------------------------
1289 * GetLargestConsoleWindowSize
1295 GetLargestConsoleWindowSize(HANDLE hConsoleOutput
)
1297 CONSOLE_API_MESSAGE ApiMessage
;
1298 PCONSOLE_GETLARGESTWINDOWSIZE GetLargestWindowSizeRequest
= &ApiMessage
.Data
.GetLargestWindowSizeRequest
;
1300 GetLargestWindowSizeRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1301 GetLargestWindowSizeRequest
->OutputHandle
= hConsoleOutput
;
1302 GetLargestWindowSizeRequest
->Size
.X
= 0;
1303 GetLargestWindowSizeRequest
->Size
.Y
= 0;
1305 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1307 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetLargestWindowSize
),
1308 sizeof(*GetLargestWindowSizeRequest
));
1309 if (!NT_SUCCESS(ApiMessage
.Status
))
1311 BaseSetLastNTError(ApiMessage
.Status
);
1314 DPRINT1("GetLargestConsoleWindowSize, X = %d, Y = %d\n", GetLargestWindowSizeRequest
->Size
.X
, GetLargestWindowSizeRequest
->Size
.Y
);
1315 return GetLargestWindowSizeRequest
->Size
;
1319 /*--------------------------------------------------------------
1320 * GetConsoleCursorInfo
1326 GetConsoleCursorInfo(HANDLE hConsoleOutput
,
1327 PCONSOLE_CURSOR_INFO lpConsoleCursorInfo
)
1329 CONSOLE_API_MESSAGE ApiMessage
;
1330 PCONSOLE_GETSETCURSORINFO CursorInfoRequest
= &ApiMessage
.Data
.CursorInfoRequest
;
1332 if (!lpConsoleCursorInfo
)
1334 if (!hConsoleOutput
)
1335 SetLastError(ERROR_INVALID_HANDLE
);
1337 SetLastError(ERROR_INVALID_ACCESS
);
1342 CursorInfoRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1343 CursorInfoRequest
->OutputHandle
= hConsoleOutput
;
1345 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1347 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetCursorInfo
),
1348 sizeof(*CursorInfoRequest
));
1349 if (!NT_SUCCESS(ApiMessage
.Status
))
1351 BaseSetLastNTError(ApiMessage
.Status
);
1355 *lpConsoleCursorInfo
= CursorInfoRequest
->Info
;
1361 /*--------------------------------------------------------------
1362 * SetConsoleCursorInfo
1368 SetConsoleCursorInfo(HANDLE hConsoleOutput
,
1369 CONST CONSOLE_CURSOR_INFO
*lpConsoleCursorInfo
)
1371 CONSOLE_API_MESSAGE ApiMessage
;
1372 PCONSOLE_GETSETCURSORINFO CursorInfoRequest
= &ApiMessage
.Data
.CursorInfoRequest
;
1374 CursorInfoRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1375 CursorInfoRequest
->OutputHandle
= hConsoleOutput
;
1376 CursorInfoRequest
->Info
= *lpConsoleCursorInfo
;
1378 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1380 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetCursorInfo
),
1381 sizeof(*CursorInfoRequest
));
1382 if (!NT_SUCCESS(ApiMessage
.Status
))
1384 BaseSetLastNTError(ApiMessage
.Status
);
1392 /*--------------------------------------------------------------
1393 * GetNumberOfConsoleMouseButtons
1399 GetNumberOfConsoleMouseButtons(LPDWORD lpNumberOfMouseButtons
)
1401 DPRINT1("GetNumberOfConsoleMouseButtons(0x%p) UNIMPLEMENTED!\n", lpNumberOfMouseButtons
);
1402 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1407 /*--------------------------------------------------------------
1408 * SetConsoleActiveScreenBuffer
1414 SetConsoleActiveScreenBuffer(HANDLE hConsoleOutput
)
1416 CONSOLE_API_MESSAGE ApiMessage
;
1417 PCONSOLE_SETACTIVESCREENBUFFER SetScreenBufferRequest
= &ApiMessage
.Data
.SetScreenBufferRequest
;
1419 SetScreenBufferRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1420 SetScreenBufferRequest
->OutputHandle
= hConsoleOutput
;
1422 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1424 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetActiveScreenBuffer
),
1425 sizeof(*SetScreenBufferRequest
));
1426 if (!NT_SUCCESS(ApiMessage
.Status
))
1428 BaseSetLastNTError(ApiMessage
.Status
);
1436 /*--------------------------------------------------------------
1437 * FlushConsoleInputBuffer
1443 FlushConsoleInputBuffer(HANDLE hConsoleInput
)
1445 CONSOLE_API_MESSAGE ApiMessage
;
1446 PCONSOLE_FLUSHINPUTBUFFER FlushInputBufferRequest
= &ApiMessage
.Data
.FlushInputBufferRequest
;
1448 FlushInputBufferRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1449 FlushInputBufferRequest
->InputHandle
= hConsoleInput
;
1451 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1453 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepFlushInputBuffer
),
1454 sizeof(*FlushInputBufferRequest
));
1455 if (!NT_SUCCESS(ApiMessage
.Status
))
1457 BaseSetLastNTError(ApiMessage
.Status
);
1465 /*--------------------------------------------------------------
1466 * SetConsoleScreenBufferSize
1472 SetConsoleScreenBufferSize(HANDLE hConsoleOutput
,
1475 CONSOLE_API_MESSAGE ApiMessage
;
1476 PCONSOLE_SETSCREENBUFFERSIZE SetScreenBufferSizeRequest
= &ApiMessage
.Data
.SetScreenBufferSizeRequest
;
1478 SetScreenBufferSizeRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1479 SetScreenBufferSizeRequest
->OutputHandle
= hConsoleOutput
;
1480 SetScreenBufferSizeRequest
->Size
= dwSize
;
1482 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1484 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetScreenBufferSize
),
1485 sizeof(*SetScreenBufferSizeRequest
));
1486 if (!NT_SUCCESS(ApiMessage
.Status
))
1488 BaseSetLastNTError(ApiMessage
.Status
);
1498 IntScrollConsoleScreenBuffer(HANDLE hConsoleOutput
,
1499 CONST SMALL_RECT
* lpScrollRectangle
,
1500 CONST SMALL_RECT
* lpClipRectangle
,
1501 COORD dwDestinationOrigin
,
1502 CONST CHAR_INFO
* lpFill
,
1505 CONSOLE_API_MESSAGE ApiMessage
;
1506 PCONSOLE_SCROLLSCREENBUFFER ScrollScreenBufferRequest
= &ApiMessage
.Data
.ScrollScreenBufferRequest
;
1508 ScrollScreenBufferRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1509 ScrollScreenBufferRequest
->OutputHandle
= hConsoleOutput
;
1510 ScrollScreenBufferRequest
->ScrollRectangle
= *lpScrollRectangle
;
1512 if (lpClipRectangle
!= NULL
)
1514 ScrollScreenBufferRequest
->UseClipRectangle
= TRUE
;
1515 ScrollScreenBufferRequest
->ClipRectangle
= *lpClipRectangle
;
1519 ScrollScreenBufferRequest
->UseClipRectangle
= FALSE
;
1522 ScrollScreenBufferRequest
->DestinationOrigin
= dwDestinationOrigin
;
1523 ScrollScreenBufferRequest
->Fill
= *lpFill
;
1524 ScrollScreenBufferRequest
->Unicode
= bUnicode
;
1526 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1528 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepScrollScreenBuffer
),
1529 sizeof(*ScrollScreenBufferRequest
));
1530 if (!NT_SUCCESS(ApiMessage
.Status
))
1532 BaseSetLastNTError(ApiMessage
.Status
);
1540 /*--------------------------------------------------------------
1541 * ScrollConsoleScreenBufferA
1547 ScrollConsoleScreenBufferA(HANDLE hConsoleOutput
,
1548 CONST SMALL_RECT
* lpScrollRectangle
,
1549 CONST SMALL_RECT
* lpClipRectangle
,
1550 COORD dwDestinationOrigin
,
1551 CONST CHAR_INFO
* lpFill
)
1553 return IntScrollConsoleScreenBuffer(hConsoleOutput
,
1556 dwDestinationOrigin
,
1562 /*--------------------------------------------------------------
1563 * ScrollConsoleScreenBufferW
1569 ScrollConsoleScreenBufferW(HANDLE hConsoleOutput
,
1570 CONST SMALL_RECT
*lpScrollRectangle
,
1571 CONST SMALL_RECT
*lpClipRectangle
,
1572 COORD dwDestinationOrigin
,
1573 CONST CHAR_INFO
*lpFill
)
1575 return IntScrollConsoleScreenBuffer(hConsoleOutput
,
1578 dwDestinationOrigin
,
1584 /*--------------------------------------------------------------
1585 * SetConsoleWindowInfo
1591 SetConsoleWindowInfo(HANDLE hConsoleOutput
,
1593 CONST SMALL_RECT
*lpConsoleWindow
)
1595 CONSOLE_API_MESSAGE ApiMessage
;
1596 PCONSOLE_SETWINDOWINFO SetWindowInfoRequest
= &ApiMessage
.Data
.SetWindowInfoRequest
;
1598 if (lpConsoleWindow
== NULL
)
1600 SetLastError(ERROR_INVALID_PARAMETER
);
1604 SetWindowInfoRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1605 SetWindowInfoRequest
->OutputHandle
= hConsoleOutput
;
1606 SetWindowInfoRequest
->Absolute
= bAbsolute
;
1607 SetWindowInfoRequest
->WindowRect
= *lpConsoleWindow
;
1609 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1611 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetWindowInfo
),
1612 sizeof(*SetWindowInfoRequest
));
1613 if (!NT_SUCCESS(ApiMessage
.Status
))
1615 BaseSetLastNTError(ApiMessage
.Status
);
1623 /*--------------------------------------------------------------
1624 * SetConsoleTextAttribute
1630 SetConsoleTextAttribute(HANDLE hConsoleOutput
,
1633 CONSOLE_API_MESSAGE ApiMessage
;
1634 PCONSOLE_SETTEXTATTRIB SetTextAttribRequest
= &ApiMessage
.Data
.SetTextAttribRequest
;
1636 SetTextAttribRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1637 SetTextAttribRequest
->OutputHandle
= hConsoleOutput
;
1638 SetTextAttribRequest
->Attributes
= wAttributes
;
1640 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1642 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetTextAttribute
),
1643 sizeof(*SetTextAttribRequest
));
1644 if (!NT_SUCCESS(ApiMessage
.Status
))
1646 BaseSetLastNTError(ApiMessage
.Status
);
1656 AddConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine
)
1658 PHANDLER_ROUTINE
* NewCtrlHandlers
= NULL
;
1660 if (HandlerRoutine
== NULL
)
1662 NtCurrentPeb()->ProcessParameters
->ConsoleFlags
= TRUE
;
1666 if (NrCtrlHandlers
== NrAllocatedHandlers
)
1668 NewCtrlHandlers
= RtlAllocateHeap(RtlGetProcessHeap(),
1670 (NrCtrlHandlers
+ 4) * sizeof(PHANDLER_ROUTINE
));
1671 if (NewCtrlHandlers
== NULL
)
1673 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1677 memmove(NewCtrlHandlers
, CtrlHandlers
, sizeof(PHANDLER_ROUTINE
) * NrCtrlHandlers
);
1679 if (NrAllocatedHandlers
> 1) RtlFreeHeap(RtlGetProcessHeap(), 0, CtrlHandlers
);
1681 CtrlHandlers
= NewCtrlHandlers
;
1682 NrAllocatedHandlers
+= 4;
1685 ASSERT(NrCtrlHandlers
< NrAllocatedHandlers
);
1687 CtrlHandlers
[NrCtrlHandlers
++] = HandlerRoutine
;
1694 RemoveConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine
)
1698 if (HandlerRoutine
== NULL
)
1700 NtCurrentPeb()->ProcessParameters
->ConsoleFlags
= FALSE
;
1704 for (i
= 0; i
< NrCtrlHandlers
; i
++)
1706 if (CtrlHandlers
[i
] == HandlerRoutine
)
1708 if (i
< (NrCtrlHandlers
- 1))
1710 memmove(&CtrlHandlers
[i
],
1712 (NrCtrlHandlers
- i
+ 1) * sizeof(PHANDLER_ROUTINE
));
1720 SetLastError(ERROR_INVALID_PARAMETER
);
1730 SetConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine
,
1735 RtlEnterCriticalSection(&BaseDllDirectoryLock
);
1738 Ret
= AddConsoleCtrlHandler(HandlerRoutine
);
1742 Ret
= RemoveConsoleCtrlHandler(HandlerRoutine
);
1745 RtlLeaveCriticalSection(&BaseDllDirectoryLock
);
1750 /*--------------------------------------------------------------
1751 * GenerateConsoleCtrlEvent
1757 GenerateConsoleCtrlEvent(DWORD dwCtrlEvent
,
1758 DWORD dwProcessGroupId
)
1760 CONSOLE_API_MESSAGE ApiMessage
;
1761 PCONSOLE_GENERATECTRLEVENT GenerateCtrlEventRequest
= &ApiMessage
.Data
.GenerateCtrlEventRequest
;
1763 if (dwCtrlEvent
!= CTRL_C_EVENT
&& dwCtrlEvent
!= CTRL_BREAK_EVENT
)
1765 SetLastError(ERROR_INVALID_PARAMETER
);
1769 GenerateCtrlEventRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1770 GenerateCtrlEventRequest
->CtrlEvent
= dwCtrlEvent
;
1771 GenerateCtrlEventRequest
->ProcessGroupId
= dwProcessGroupId
;
1773 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1775 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGenerateCtrlEvent
),
1776 sizeof(*GenerateCtrlEventRequest
));
1777 if (!NT_SUCCESS(ApiMessage
.Status
))
1779 BaseSetLastNTError(ApiMessage
.Status
);
1788 IntGetConsoleTitle(LPVOID lpConsoleTitle
, DWORD dwNumChars
, BOOLEAN bUnicode
)
1790 CONSOLE_API_MESSAGE ApiMessage
;
1791 PCONSOLE_GETSETCONSOLETITLE TitleRequest
= &ApiMessage
.Data
.TitleRequest
;
1792 PCSR_CAPTURE_BUFFER CaptureBuffer
;
1794 if (dwNumChars
== 0) return 0;
1796 TitleRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1797 TitleRequest
->Length
= dwNumChars
* (bUnicode
? sizeof(WCHAR
) : sizeof(CHAR
));
1798 TitleRequest
->Unicode
= bUnicode
;
1800 CaptureBuffer
= CsrAllocateCaptureBuffer(1, TitleRequest
->Length
);
1801 if (CaptureBuffer
== NULL
)
1803 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
1804 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1808 CsrAllocateMessagePointer(CaptureBuffer
,
1809 TitleRequest
->Length
,
1810 (PVOID
*)&TitleRequest
->Title
);
1812 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1814 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetTitle
),
1815 sizeof(*TitleRequest
));
1816 if (!NT_SUCCESS(ApiMessage
.Status
))
1818 CsrFreeCaptureBuffer(CaptureBuffer
);
1819 BaseSetLastNTError(ApiMessage
.Status
);
1823 dwNumChars
= TitleRequest
->Length
/ (bUnicode
? sizeof(WCHAR
) : sizeof(CHAR
));
1827 memcpy(lpConsoleTitle
, TitleRequest
->Title
, TitleRequest
->Length
);
1830 ((LPWSTR
)lpConsoleTitle
)[dwNumChars
] = L
'\0';
1832 ((LPSTR
)lpConsoleTitle
)[dwNumChars
] = '\0';
1835 CsrFreeCaptureBuffer(CaptureBuffer
);
1841 /*--------------------------------------------------------------
1848 GetConsoleTitleW(LPWSTR lpConsoleTitle
,
1851 return IntGetConsoleTitle(lpConsoleTitle
, nSize
, TRUE
);
1855 /*--------------------------------------------------------------
1862 GetConsoleTitleA(LPSTR lpConsoleTitle
,
1865 return IntGetConsoleTitle(lpConsoleTitle
, nSize
, FALSE
);
1870 IntSetConsoleTitle(CONST VOID
*lpConsoleTitle
, BOOLEAN bUnicode
)
1872 CONSOLE_API_MESSAGE ApiMessage
;
1873 PCONSOLE_GETSETCONSOLETITLE TitleRequest
= &ApiMessage
.Data
.TitleRequest
;
1874 PCSR_CAPTURE_BUFFER CaptureBuffer
;
1876 DWORD dwNumChars
= (lpConsoleTitle
? (bUnicode
? wcslen(lpConsoleTitle
) : strlen(lpConsoleTitle
)) : 0);
1878 TitleRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1879 TitleRequest
->Length
= dwNumChars
* (bUnicode
? sizeof(WCHAR
) : sizeof(CHAR
));
1880 TitleRequest
->Unicode
= bUnicode
;
1882 CaptureBuffer
= CsrAllocateCaptureBuffer(1, TitleRequest
->Length
);
1883 if (CaptureBuffer
== NULL
)
1885 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
1886 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1890 CsrCaptureMessageBuffer(CaptureBuffer
,
1891 (PVOID
)lpConsoleTitle
,
1892 TitleRequest
->Length
,
1893 (PVOID
*)&TitleRequest
->Title
);
1895 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1897 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetTitle
),
1898 sizeof(*TitleRequest
));
1900 CsrFreeCaptureBuffer(CaptureBuffer
);
1902 if (!NT_SUCCESS(ApiMessage
.Status
))
1904 BaseSetLastNTError(ApiMessage
.Status
);
1911 /*--------------------------------------------------------------
1918 SetConsoleTitleW(LPCWSTR lpConsoleTitle
)
1920 return IntSetConsoleTitle(lpConsoleTitle
, TRUE
);
1924 /*--------------------------------------------------------------
1931 SetConsoleTitleA(LPCSTR lpConsoleTitle
)
1933 return IntSetConsoleTitle(lpConsoleTitle
, FALSE
);
1937 /*--------------------------------------------------------------
1938 * CreateConsoleScreenBuffer
1944 CreateConsoleScreenBuffer(DWORD dwDesiredAccess
,
1946 CONST SECURITY_ATTRIBUTES
*lpSecurityAttributes
,
1948 LPVOID lpScreenBufferData
)
1950 CONSOLE_API_MESSAGE ApiMessage
;
1951 PCONSOLE_CREATESCREENBUFFER CreateScreenBufferRequest
= &ApiMessage
.Data
.CreateScreenBufferRequest
;
1952 PCSR_CAPTURE_BUFFER CaptureBuffer
= NULL
;
1953 PCONSOLE_GRAPHICS_BUFFER_INFO GraphicsBufferInfo
= lpScreenBufferData
;
1955 if ( (dwDesiredAccess
& ~(GENERIC_READ
| GENERIC_WRITE
)) ||
1956 (dwShareMode
& ~(FILE_SHARE_READ
| FILE_SHARE_WRITE
)) ||
1957 (dwFlags
!= CONSOLE_TEXTMODE_BUFFER
&& dwFlags
!= CONSOLE_GRAPHICS_BUFFER
) )
1959 SetLastError(ERROR_INVALID_PARAMETER
);
1960 return INVALID_HANDLE_VALUE
;
1963 CreateScreenBufferRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1964 CreateScreenBufferRequest
->DesiredAccess
= dwDesiredAccess
;
1965 CreateScreenBufferRequest
->InheritHandle
=
1966 (lpSecurityAttributes
? lpSecurityAttributes
->bInheritHandle
: FALSE
);
1967 CreateScreenBufferRequest
->ShareMode
= dwShareMode
;
1968 CreateScreenBufferRequest
->ScreenBufferType
= dwFlags
;
1970 if (dwFlags
== CONSOLE_GRAPHICS_BUFFER
)
1972 if (CreateScreenBufferRequest
->InheritHandle
|| GraphicsBufferInfo
== NULL
)
1974 SetLastError(ERROR_INVALID_PARAMETER
);
1975 return INVALID_HANDLE_VALUE
;
1978 CreateScreenBufferRequest
->GraphicsBufferInfo
= *GraphicsBufferInfo
;
1980 CaptureBuffer
= CsrAllocateCaptureBuffer(1, GraphicsBufferInfo
->dwBitMapInfoLength
);
1981 if (CaptureBuffer
== NULL
)
1983 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1984 return INVALID_HANDLE_VALUE
;
1987 CsrCaptureMessageBuffer(CaptureBuffer
,
1988 (PVOID
)GraphicsBufferInfo
->lpBitMapInfo
,
1989 GraphicsBufferInfo
->dwBitMapInfoLength
,
1990 (PVOID
*)&CreateScreenBufferRequest
->GraphicsBufferInfo
.lpBitMapInfo
);
1993 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1995 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepCreateScreenBuffer
),
1996 sizeof(*CreateScreenBufferRequest
));
1998 if (CaptureBuffer
) CsrFreeCaptureBuffer(CaptureBuffer
);
2000 if (!NT_SUCCESS(ApiMessage
.Status
))
2002 BaseSetLastNTError(ApiMessage
.Status
);
2003 return INVALID_HANDLE_VALUE
;
2006 if (dwFlags
== CONSOLE_GRAPHICS_BUFFER
&& GraphicsBufferInfo
)
2008 GraphicsBufferInfo
->hMutex
= CreateScreenBufferRequest
->hMutex
; // CreateScreenBufferRequest->GraphicsBufferInfo.hMutex ;
2009 GraphicsBufferInfo
->lpBitMap
= CreateScreenBufferRequest
->lpBitMap
; // CreateScreenBufferRequest->GraphicsBufferInfo.lpBitMap;
2012 return CreateScreenBufferRequest
->OutputHandle
;
2016 /*--------------------------------------------------------------
2025 CONSOLE_API_MESSAGE ApiMessage
;
2026 PCONSOLE_GETINPUTOUTPUTCP GetConsoleCPRequest
= &ApiMessage
.Data
.GetConsoleCPRequest
;
2028 /* Get the Input Code Page */
2029 GetConsoleCPRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
2030 GetConsoleCPRequest
->OutputCP
= FALSE
;
2032 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2034 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetCP
),
2035 sizeof(*GetConsoleCPRequest
));
2036 if (!NT_SUCCESS(ApiMessage
.Status
))
2038 BaseSetLastNTError(ApiMessage
.Status
);
2042 return GetConsoleCPRequest
->CodePage
;
2046 /*--------------------------------------------------------------
2053 SetConsoleCP(UINT wCodePageID
)
2055 CONSOLE_API_MESSAGE ApiMessage
;
2056 PCONSOLE_SETINPUTOUTPUTCP SetConsoleCPRequest
= &ApiMessage
.Data
.SetConsoleCPRequest
;
2058 /* Set the Input Code Page */
2059 SetConsoleCPRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
2060 SetConsoleCPRequest
->CodePage
= wCodePageID
;
2061 SetConsoleCPRequest
->OutputCP
= FALSE
;
2062 /* SetConsoleCPRequest->EventHandle; */
2064 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2066 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetCP
),
2067 sizeof(*SetConsoleCPRequest
));
2068 if (!NT_SUCCESS(ApiMessage
.Status
))
2070 BaseSetLastNTError(ApiMessage
.Status
);
2078 /*--------------------------------------------------------------
2079 * GetConsoleOutputCP
2085 GetConsoleOutputCP(VOID
)
2087 CONSOLE_API_MESSAGE ApiMessage
;
2088 PCONSOLE_GETINPUTOUTPUTCP GetConsoleCPRequest
= &ApiMessage
.Data
.GetConsoleCPRequest
;
2090 /* Get the Output Code Page */
2091 GetConsoleCPRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
2092 GetConsoleCPRequest
->OutputCP
= TRUE
;
2094 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2096 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetCP
),
2097 sizeof(*GetConsoleCPRequest
));
2098 if (!NT_SUCCESS(ApiMessage
.Status
))
2100 BaseSetLastNTError(ApiMessage
.Status
);
2104 return GetConsoleCPRequest
->CodePage
;
2108 /*--------------------------------------------------------------
2109 * SetConsoleOutputCP
2115 SetConsoleOutputCP(UINT wCodePageID
)
2117 CONSOLE_API_MESSAGE ApiMessage
;
2118 PCONSOLE_SETINPUTOUTPUTCP SetConsoleCPRequest
= &ApiMessage
.Data
.SetConsoleCPRequest
;
2120 /* Set the Output Code Page */
2121 SetConsoleCPRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
2122 SetConsoleCPRequest
->CodePage
= wCodePageID
;
2123 SetConsoleCPRequest
->OutputCP
= TRUE
;
2124 /* SetConsoleCPRequest->EventHandle; */
2126 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2128 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetCP
),
2129 sizeof(*SetConsoleCPRequest
));
2130 if (!NT_SUCCESS(ApiMessage
.Status
))
2132 BaseSetLastNTError(ApiMessage
.Status
);
2140 /*--------------------------------------------------------------
2141 * GetConsoleProcessList
2147 GetConsoleProcessList(LPDWORD lpdwProcessList
,
2148 DWORD dwProcessCount
)
2150 CONSOLE_API_MESSAGE ApiMessage
;
2151 PCONSOLE_GETPROCESSLIST GetProcessListRequest
= &ApiMessage
.Data
.GetProcessListRequest
;
2152 PCSR_CAPTURE_BUFFER CaptureBuffer
;
2153 ULONG nProcesses
= 0;
2155 if (lpdwProcessList
== NULL
|| dwProcessCount
== 0)
2157 SetLastError(ERROR_INVALID_PARAMETER
);
2161 CaptureBuffer
= CsrAllocateCaptureBuffer(1, dwProcessCount
* sizeof(DWORD
));
2162 if (CaptureBuffer
== NULL
)
2164 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
2165 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2169 GetProcessListRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
2170 GetProcessListRequest
->ProcessCount
= dwProcessCount
;
2172 CsrAllocateMessagePointer(CaptureBuffer
,
2173 dwProcessCount
* sizeof(DWORD
),
2174 (PVOID
*)&GetProcessListRequest
->ProcessIdsList
);
2176 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2178 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetProcessList
),
2179 sizeof(*GetProcessListRequest
));
2180 if (!NT_SUCCESS(ApiMessage
.Status
))
2182 BaseSetLastNTError(ApiMessage
.Status
);
2186 nProcesses
= GetProcessListRequest
->ProcessCount
;
2187 if (dwProcessCount
>= nProcesses
)
2189 memcpy(lpdwProcessList
, GetProcessListRequest
->ProcessIdsList
, nProcesses
* sizeof(DWORD
));
2193 CsrFreeCaptureBuffer(CaptureBuffer
);
2198 /*--------------------------------------------------------------
2199 * GetConsoleSelectionInfo
2205 GetConsoleSelectionInfo(PCONSOLE_SELECTION_INFO lpConsoleSelectionInfo
)
2207 CONSOLE_API_MESSAGE ApiMessage
;
2208 PCONSOLE_GETSELECTIONINFO GetSelectionInfoRequest
= &ApiMessage
.Data
.GetSelectionInfoRequest
;
2210 if (lpConsoleSelectionInfo
== NULL
)
2212 SetLastError(ERROR_INVALID_PARAMETER
);
2216 GetSelectionInfoRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
2218 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2220 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetSelectionInfo
),
2221 sizeof(*GetSelectionInfoRequest
));
2222 if (!NT_SUCCESS(ApiMessage
.Status
))
2224 BaseSetLastNTError(ApiMessage
.Status
);
2228 *lpConsoleSelectionInfo
= GetSelectionInfoRequest
->Info
;
2234 /*--------------------------------------------------------------
2239 * @note Strongly inspired by AllocConsole.
2243 AttachConsole(DWORD dwProcessId
)
2246 PRTL_USER_PROCESS_PARAMETERS Parameters
= NtCurrentPeb()->ProcessParameters
;
2247 CONSOLE_API_MESSAGE ApiMessage
;
2248 PCONSOLE_ATTACHCONSOLE AttachConsoleRequest
= &ApiMessage
.Data
.AttachConsoleRequest
;
2250 if (Parameters
->ConsoleHandle
)
2252 DPRINT1("AttachConsole: Attaching a console to a process already having one\n");
2253 SetLastError(ERROR_ACCESS_DENIED
);
2257 AttachConsoleRequest
->ProcessId
= dwProcessId
;
2258 AttachConsoleRequest
->CtrlDispatcher
= ConsoleControlDispatcher
;
2259 AttachConsoleRequest
->PropDispatcher
= PropDialogHandler
;
2261 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2263 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepAttach
),
2264 sizeof(CONSOLE_ATTACHCONSOLE
));
2265 if (!NT_SUCCESS(Status
))
2267 BaseSetLastNTError(Status
);
2271 Parameters
->ConsoleHandle
= AttachConsoleRequest
->ConsoleHandle
;
2272 SetStdHandle(STD_INPUT_HANDLE
, AttachConsoleRequest
->InputHandle
);
2273 SetStdHandle(STD_OUTPUT_HANDLE
, AttachConsoleRequest
->OutputHandle
);
2274 SetStdHandle(STD_ERROR_HANDLE
, AttachConsoleRequest
->ErrorHandle
);
2276 /* Initialize Console Ctrl Handler */
2277 InitConsoleCtrlHandling();
2279 InputWaitHandle
= AttachConsoleRequest
->InputWaitHandle
;
2285 /*--------------------------------------------------------------
2292 GetConsoleWindow(VOID
)
2294 CONSOLE_API_MESSAGE ApiMessage
;
2295 PCONSOLE_GETWINDOW GetWindowRequest
= &ApiMessage
.Data
.GetWindowRequest
;
2297 GetWindowRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
2299 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2301 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetConsoleWindow
),
2302 sizeof(*GetWindowRequest
));
2303 if (!NT_SUCCESS(ApiMessage
.Status
))
2305 BaseSetLastNTError(ApiMessage
.Status
);
2309 return GetWindowRequest
->WindowHandle
;
2313 /*--------------------------------------------------------------
2320 SetConsoleIcon(HICON hIcon
)
2322 CONSOLE_API_MESSAGE ApiMessage
;
2323 PCONSOLE_SETICON SetIconRequest
= &ApiMessage
.Data
.SetIconRequest
;
2325 SetIconRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
2326 SetIconRequest
->IconHandle
= hIcon
;
2328 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2330 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetIcon
),
2331 sizeof(*SetIconRequest
));
2332 if (!NT_SUCCESS(ApiMessage
.Status
))
2334 BaseSetLastNTError(ApiMessage
.Status
);
2342 /******************************************************************************
2343 * \name SetConsoleInputExeNameW
2344 * \brief Sets the console input file name from a unicode string.
2345 * \param lpInputExeName Pointer to a unicode string with the name.
2346 * \return TRUE if successful, FALSE if unsuccsedful.
2347 * \remarks If lpInputExeName is 0 or the string length is 0 or greater than 255,
2348 * the function fails and sets last error to ERROR_INVALID_PARAMETER.
2352 SetConsoleInputExeNameW(LPCWSTR lpInputExeName
)
2356 if ( !lpInputExeName
||
2357 (lenName
= lstrlenW(lpInputExeName
)) == 0 ||
2358 lenName
> INPUTEXENAME_BUFLEN
- 1 )
2360 /* Fail if string is empty or too long */
2361 SetLastError(ERROR_INVALID_PARAMETER
);
2365 RtlEnterCriticalSection(&ConsoleLock
);
2368 RtlCopyMemory(InputExeName
, lpInputExeName
, lenName
* sizeof(WCHAR
));
2369 InputExeName
[lenName
] = L
'\0';
2373 RtlLeaveCriticalSection(&ConsoleLock
);
2381 /******************************************************************************
2382 * \name SetConsoleInputExeNameA
2383 * \brief Sets the console input file name from an ansi string.
2384 * \param lpInputExeName Pointer to an ansi string with the name.
2385 * \return TRUE if successful, FALSE if unsuccsedful.
2386 * \remarks If lpInputExeName is 0 or the string length is 0 or greater than 255,
2387 * the function fails and sets last error to ERROR_INVALID_PARAMETER.
2391 SetConsoleInputExeNameA(LPCSTR lpInputExeName
)
2393 WCHAR Buffer
[INPUTEXENAME_BUFLEN
];
2394 ANSI_STRING InputExeNameA
;
2395 UNICODE_STRING InputExeNameU
;
2398 RtlInitAnsiString(&InputExeNameA
, lpInputExeName
);
2400 if ( InputExeNameA
.Length
== 0 ||
2401 InputExeNameA
.Length
> INPUTEXENAME_BUFLEN
- 1 )
2403 /* Fail if string is empty or too long */
2404 SetLastError(ERROR_INVALID_PARAMETER
);
2408 InputExeNameU
.Buffer
= Buffer
;
2409 InputExeNameU
.MaximumLength
= sizeof(Buffer
);
2410 InputExeNameU
.Length
= 0;
2412 Status
= RtlAnsiStringToUnicodeString(&InputExeNameU
, &InputExeNameA
, FALSE
);
2413 if (!NT_SUCCESS(Status
))
2415 BaseSetLastNTError(Status
);
2419 return SetConsoleInputExeNameW(InputExeNameU
.Buffer
);
2423 /******************************************************************************
2424 * \name GetConsoleInputExeNameW
2425 * \brief Retrieves the console input file name as unicode string.
2426 * \param nBufferLength Length of the buffer in WCHARs.
2427 * Specify 0 to receive the needed buffer length.
2428 * \param lpBuffer Pointer to a buffer that receives the string.
2429 * \return Needed buffer size if \p nBufferLength is 0.
2430 * Otherwise 1 if successful, 2 if buffer is too small.
2431 * \remarks Sets last error value to ERROR_BUFFER_OVERFLOW if the buffer
2432 * is not big enough.
2436 GetConsoleInputExeNameW(DWORD nBufferLength
, LPWSTR lpBuffer
)
2438 ULONG lenName
= lstrlenW(InputExeName
);
2440 if (nBufferLength
== 0)
2442 /* Buffer size is requested, return it */
2446 if (lenName
+ 1 > nBufferLength
)
2448 /* Buffer is not large enough! */
2449 SetLastError(ERROR_BUFFER_OVERFLOW
);
2453 RtlEnterCriticalSection(&ConsoleLock
);
2456 RtlCopyMemory(lpBuffer
, InputExeName
, lenName
* sizeof(WCHAR
));
2457 lpBuffer
[lenName
] = '\0';
2461 RtlLeaveCriticalSection(&ConsoleLock
);
2465 /* Success, return 1 */
2470 /******************************************************************************
2471 * \name GetConsoleInputExeNameA
2472 * \brief Retrieves the console input file name as ansi string.
2473 * \param nBufferLength Length of the buffer in CHARs.
2474 * \param lpBuffer Pointer to a buffer that receives the string.
2475 * \return 1 if successful, 2 if buffer is too small.
2476 * \remarks Sets last error value to ERROR_BUFFER_OVERFLOW if the buffer
2477 * is not big enough. The buffer receives as much characters as fit.
2481 GetConsoleInputExeNameA(DWORD nBufferLength
, LPSTR lpBuffer
)
2483 WCHAR Buffer
[INPUTEXENAME_BUFLEN
];
2485 UNICODE_STRING BufferU
;
2486 ANSI_STRING BufferA
;
2488 /* Get the unicode name */
2489 Ret
= GetConsoleInputExeNameW(sizeof(Buffer
) / sizeof(Buffer
[0]), Buffer
);
2491 /* Initialize strings for conversion */
2492 RtlInitUnicodeString(&BufferU
, Buffer
);
2494 BufferA
.MaximumLength
= (USHORT
)nBufferLength
;
2495 BufferA
.Buffer
= lpBuffer
;
2497 /* Convert unicode name to ansi, copying as much chars as fit */
2498 RtlUnicodeStringToAnsiString(&BufferA
, &BufferU
, FALSE
);
2500 /* Error handling */
2501 if (nBufferLength
<= BufferU
.Length
/ sizeof(WCHAR
))
2503 SetLastError(ERROR_BUFFER_OVERFLOW
);
2512 GetConsoleCharType(HANDLE hConsole
, COORD Coord
, PDWORD Type
)
2520 GetConsoleCursorMode(HANDLE hConsole
, PBOOL pUnknown1
, PBOOL pUnknown2
)
2528 GetConsoleNlsMode(HANDLE hConsole
, LPDWORD lpMode
)
2536 SetConsoleCursorMode(HANDLE hConsole
, BOOL Unknown1
, BOOL Unknown2
)
2544 SetConsoleLocalEUDC(DWORD Unknown1
, DWORD Unknown2
, DWORD Unknown3
, DWORD Unknown4
)
2552 SetConsoleNlsMode(HANDLE hConsole
, DWORD dwMode
)
2560 RegisterConsoleIME(HWND hWnd
, LPDWORD ThreadId
)
2568 RegisterConsoleOS2(BOOL bUnknown
)
2576 SetConsoleOS2OemFormat(BOOL bUnknown
)
2584 UnregisterConsoleIME(VOID
)
2594 BOOL WINAPI
GetConsoleKeyboardLayoutNameA(LPSTR name
)
2603 BOOL WINAPI
GetConsoleKeyboardLayoutNameW(LPWSTR name
)
2614 SetLastConsoleEventActive(VOID
)
2616 CONSOLE_API_MESSAGE ApiMessage
;
2617 PCONSOLE_NOTIFYLASTCLOSE NotifyLastCloseRequest
= &ApiMessage
.Data
.NotifyLastCloseRequest
;
2619 /* Set the flag used by the console control dispatcher */
2620 LastCloseNotify
= TRUE
;
2622 /* Set up the input arguments */
2623 NotifyLastCloseRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
2625 /* Call CSRSS; just return the NTSTATUS cast to DWORD */
2626 return CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2628 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepNotifyLastClose
),
2629 sizeof(*NotifyLastCloseRequest
));