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_LOGOFF_EVENT
:
63 DPRINT("Ctrl Logoff Event\n");
66 case CTRL_SHUTDOWN_EVENT
:
67 DPRINT("Ctrl Shutdown Event\n");
71 ExitProcess(CONTROL_C_EXIT
);
77 ConsoleControlDispatcher(IN LPVOID lpThreadParameter
)
80 DWORD CodeAndFlag
= PtrToUlong(lpThreadParameter
);
81 DWORD nCode
= CodeAndFlag
& MAXLONG
;
83 EXCEPTION_RECORD erException
;
85 DPRINT1("Console Dispatcher Active: %lx %lx\n", CodeAndFlag
, nCode
);
86 SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST
);
91 case CTRL_BREAK_EVENT
:
93 if (IsDebuggerPresent())
95 erException
.ExceptionCode
= (nCode
== CTRL_C_EVENT
?
96 DBG_CONTROL_C
: DBG_CONTROL_BREAK
);
97 erException
.ExceptionFlags
= 0;
98 erException
.ExceptionRecord
= NULL
;
99 erException
.ExceptionAddress
= DefaultConsoleCtrlHandler
;
100 erException
.NumberParameters
= 0;
104 RtlRaiseException(&erException
);
106 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
108 RtlEnterCriticalSection(&ConsoleLock
);
110 if ((nCode
!= CTRL_C_EVENT
) ||
111 (NtCurrentPeb()->ProcessParameters
->ConsoleFlags
!= 1))
113 for (i
= NrCtrlHandlers
; i
> 0; i
--)
115 if (CtrlHandlers
[i
- 1](nCode
)) break;
119 RtlLeaveCriticalSection(&ConsoleLock
);
128 case CTRL_CLOSE_EVENT
:
129 case CTRL_LOGOFF_EVENT
:
130 case CTRL_SHUTDOWN_EVENT
:
133 case CTRL_LAST_CLOSE_EVENT
:
135 * In case the console app hasn't register for last close notification,
136 * just kill this console handler thread. We don't want that such apps
137 * get killed for unexpected reasons. On the contrary apps that registered
138 * can be killed because they expect to be.
140 if (!LastCloseNotify
) ExitThread(0);
144 ExitProcess(CONTROL_C_EXIT
);
152 ASSERT(ConsoleInitialized
);
154 RtlEnterCriticalSection(&ConsoleLock
);
157 if ((nCode
!= CTRL_C_EVENT
) || (NtCurrentPeb()->ProcessParameters
->ConsoleFlags
!= 1))
159 for (i
= NrCtrlHandlers
; i
> 0; i
--)
162 (CodeAndFlag
& MINLONG
) &&
163 ((nCode
== CTRL_LOGOFF_EVENT
) || (nCode
== CTRL_SHUTDOWN_EVENT
)))
165 DPRINT("Skipping system/service apps\n");
169 if (CtrlHandlers
[i
- 1](nCode
))
173 case CTRL_CLOSE_EVENT
:
174 case CTRL_LOGOFF_EVENT
:
175 case CTRL_SHUTDOWN_EVENT
:
177 nExitCode
= CodeAndFlag
;
185 RtlLeaveCriticalSection(&ConsoleLock
);
187 ExitThread(nExitCode
);
188 return STATUS_SUCCESS
;
193 InitConsoleCtrlHandling(VOID
)
195 /* Initialize Console Ctrl Handler */
196 NrAllocatedHandlers
= NrCtrlHandlers
= 1;
197 CtrlHandlers
= InitialHandler
;
198 CtrlHandlers
[0] = DefaultConsoleCtrlHandler
;
202 /* FUNCTIONS ******************************************************************/
205 IntCheckForConsoleFileName(IN LPCWSTR pszName
,
206 IN DWORD dwDesiredAccess
)
208 LPCWSTR ConsoleName
= pszName
;
209 ULONG DeviceNameInfo
;
212 * Check whether we deal with a DOS device, and if so,
213 * strip the path till the file name.
214 * Therefore, things like \\.\CON or C:\some_path\CONIN$
215 * are transformed into CON or CONIN$, for example.
217 DeviceNameInfo
= RtlIsDosDeviceName_U(pszName
);
218 if (DeviceNameInfo
!= 0)
220 ConsoleName
= (LPCWSTR
)((ULONG_PTR
)ConsoleName
+ ((DeviceNameInfo
>> 16) & 0xFFFF));
223 /* Return a standard console "file" name according to what we passed in parameters */
224 if (_wcsicmp(ConsoleName
, BaseConInputFileName
) == 0)
226 return BaseConInputFileName
;
228 else if (_wcsicmp(ConsoleName
, BaseConOutputFileName
) == 0)
230 return BaseConOutputFileName
;
232 else if (_wcsicmp(ConsoleName
, BaseConFileName
) == 0)
234 if ((dwDesiredAccess
& (GENERIC_READ
| GENERIC_WRITE
)) == GENERIC_READ
)
236 return BaseConInputFileName
;
238 else if ((dwDesiredAccess
& (GENERIC_READ
| GENERIC_WRITE
)) == GENERIC_WRITE
)
240 return BaseConOutputFileName
;
244 /* If we are there, that means that either the file name or the desired access are wrong */
250 * @implemented (Undocumented)
251 * @note See http://undoc.airesoft.co.uk/kernel32.dll/ConsoleMenuControl.php
255 ConsoleMenuControl(HANDLE hConsoleOutput
,
259 CONSOLE_API_MESSAGE ApiMessage
;
260 PCONSOLE_MENUCONTROL MenuControlRequest
= &ApiMessage
.Data
.MenuControlRequest
;
262 MenuControlRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
263 MenuControlRequest
->OutputHandle
= hConsoleOutput
;
264 MenuControlRequest
->CmdIdLow
= dwCmdIdLow
;
265 MenuControlRequest
->CmdIdHigh
= dwCmdIdHigh
;
266 MenuControlRequest
->MenuHandle
= NULL
;
268 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
270 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepMenuControl
),
271 sizeof(*MenuControlRequest
));
273 return MenuControlRequest
->MenuHandle
;
282 DuplicateConsoleHandle(HANDLE hConsole
,
283 DWORD dwDesiredAccess
,
287 CONSOLE_API_MESSAGE ApiMessage
;
288 PCONSOLE_DUPLICATEHANDLE DuplicateHandleRequest
= &ApiMessage
.Data
.DuplicateHandleRequest
;
290 if ( (dwOptions
& ~(DUPLICATE_CLOSE_SOURCE
| DUPLICATE_SAME_ACCESS
)) ||
291 (!(dwOptions
& DUPLICATE_SAME_ACCESS
) &&
292 (dwDesiredAccess
& ~(GENERIC_READ
| GENERIC_WRITE
))) )
294 SetLastError(ERROR_INVALID_PARAMETER
);
295 return INVALID_HANDLE_VALUE
;
298 DuplicateHandleRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
299 DuplicateHandleRequest
->SourceHandle
= hConsole
;
300 DuplicateHandleRequest
->DesiredAccess
= dwDesiredAccess
;
301 DuplicateHandleRequest
->InheritHandle
= bInheritHandle
;
302 DuplicateHandleRequest
->Options
= dwOptions
;
304 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
306 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepDuplicateHandle
),
307 sizeof(*DuplicateHandleRequest
));
308 if (!NT_SUCCESS(ApiMessage
.Status
))
310 BaseSetLastNTError(ApiMessage
.Status
);
311 return INVALID_HANDLE_VALUE
;
314 return DuplicateHandleRequest
->TargetHandle
;
323 GetConsoleHandleInformation(IN HANDLE hHandle
,
324 OUT LPDWORD lpdwFlags
)
326 CONSOLE_API_MESSAGE ApiMessage
;
327 PCONSOLE_GETHANDLEINFO GetHandleInfoRequest
= &ApiMessage
.Data
.GetHandleInfoRequest
;
329 GetHandleInfoRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
330 GetHandleInfoRequest
->Handle
= hHandle
;
332 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
334 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetHandleInformation
),
335 sizeof(*GetHandleInfoRequest
));
336 if (!NT_SUCCESS(ApiMessage
.Status
))
338 BaseSetLastNTError(ApiMessage
.Status
);
342 *lpdwFlags
= GetHandleInfoRequest
->Flags
;
353 SetConsoleHandleInformation(IN HANDLE hHandle
,
357 CONSOLE_API_MESSAGE ApiMessage
;
358 PCONSOLE_SETHANDLEINFO SetHandleInfoRequest
= &ApiMessage
.Data
.SetHandleInfoRequest
;
360 SetHandleInfoRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
361 SetHandleInfoRequest
->Handle
= hHandle
;
362 SetHandleInfoRequest
->Mask
= dwMask
;
363 SetHandleInfoRequest
->Flags
= dwFlags
;
365 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
367 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetHandleInformation
),
368 sizeof(*SetHandleInfoRequest
));
369 if (!NT_SUCCESS(ApiMessage
.Status
))
371 BaseSetLastNTError(ApiMessage
.Status
);
384 GetConsoleDisplayMode(LPDWORD lpModeFlags
)
386 CONSOLE_API_MESSAGE ApiMessage
;
387 PCONSOLE_GETDISPLAYMODE GetDisplayModeRequest
= &ApiMessage
.Data
.GetDisplayModeRequest
;
389 if (lpModeFlags
== NULL
)
391 SetLastError(ERROR_INVALID_PARAMETER
);
395 GetDisplayModeRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
397 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
399 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetDisplayMode
),
400 sizeof(*GetDisplayModeRequest
));
401 if (!NT_SUCCESS(ApiMessage
.Status
))
403 BaseSetLastNTError(ApiMessage
.Status
);
407 *lpModeFlags
= GetDisplayModeRequest
->DisplayMode
; // ModeFlags
414 * @unimplemented (Undocumented)
418 GetConsoleFontInfo(HANDLE hConsoleOutput
,
421 PCONSOLE_FONT_INFO lpConsoleFontInfo
)
423 DPRINT1("GetConsoleFontInfo(0x%p, %d, %lu, 0x%p) UNIMPLEMENTED!\n", hConsoleOutput
, bMaximumWindow
, nFontCount
, lpConsoleFontInfo
);
424 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
434 GetConsoleFontSize(HANDLE hConsoleOutput
,
437 COORD Empty
= {0, 0};
438 DPRINT1("GetConsoleFontSize(0x%p, 0x%x) UNIMPLEMENTED!\n", hConsoleOutput
, nFont
);
439 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
445 * @implemented (Undocumented)
449 GetConsoleHardwareState(HANDLE hConsoleOutput
,
453 CONSOLE_API_MESSAGE ApiMessage
;
454 PCONSOLE_GETSETHWSTATE HardwareStateRequest
= &ApiMessage
.Data
.HardwareStateRequest
;
456 DPRINT1("GetConsoleHardwareState(%lu, 0x%p) UNIMPLEMENTED!\n", Flags
, State
);
458 if (Flags
== NULL
|| State
== NULL
)
460 SetLastError(ERROR_INVALID_PARAMETER
);
464 HardwareStateRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
465 HardwareStateRequest
->OutputHandle
= hConsoleOutput
;
467 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
469 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetHardwareState
),
470 sizeof(*HardwareStateRequest
));
471 if (!NT_SUCCESS(ApiMessage
.Status
))
473 BaseSetLastNTError(ApiMessage
.Status
);
477 *Flags
= HardwareStateRequest
->Flags
;
478 *State
= HardwareStateRequest
->State
;
485 * @implemented (Undocumented)
489 GetConsoleInputWaitHandle(VOID
)
491 return InputWaitHandle
;
500 GetCurrentConsoleFont(HANDLE hConsoleOutput
,
502 PCONSOLE_FONT_INFO lpConsoleCurrentFont
)
504 DPRINT1("GetCurrentConsoleFont(0x%p, 0x%x, 0x%p) UNIMPLEMENTED!\n", hConsoleOutput
, bMaximumWindow
, lpConsoleCurrentFont
);
505 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
511 * @unimplemented (Undocumented)
515 GetNumberOfConsoleFonts(VOID
)
517 DPRINT1("GetNumberOfConsoleFonts() UNIMPLEMENTED!\n");
518 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
524 * @implemented (Undocumented)
525 * @note See http://blog.airesoft.co.uk/2012/10/things-ms-can-do-that-they-dont-tell-you-about-console-graphics/
529 InvalidateConsoleDIBits(IN HANDLE hConsoleOutput
,
530 IN PSMALL_RECT lpRect
)
532 CONSOLE_API_MESSAGE ApiMessage
;
533 PCONSOLE_INVALIDATEDIBITS InvalidateDIBitsRequest
= &ApiMessage
.Data
.InvalidateDIBitsRequest
;
537 SetLastError(ERROR_INVALID_PARAMETER
);
541 InvalidateDIBitsRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
542 InvalidateDIBitsRequest
->OutputHandle
= hConsoleOutput
;
543 InvalidateDIBitsRequest
->Region
= *lpRect
;
545 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
547 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepInvalidateBitMapRect
),
548 sizeof(*InvalidateDIBitsRequest
));
549 if (!NT_SUCCESS(ApiMessage
.Status
))
551 BaseSetLastNTError(ApiMessage
.Status
);
560 * @unimplemented (Undocumented)
564 OpenConsoleW(LPCWSTR wsName
,
565 DWORD dwDesiredAccess
,
569 CONSOLE_API_MESSAGE ApiMessage
;
570 PCONSOLE_OPENCONSOLE OpenConsoleRequest
= &ApiMessage
.Data
.OpenConsoleRequest
;
571 CONSOLE_HANDLE_TYPE HandleType
;
573 if (wsName
&& (_wcsicmp(wsName
, BaseConInputFileName
) == 0))
575 HandleType
= HANDLE_INPUT
;
577 else if (wsName
&& (_wcsicmp(wsName
, BaseConOutputFileName
) == 0))
579 HandleType
= HANDLE_OUTPUT
;
583 SetLastError(ERROR_INVALID_PARAMETER
);
584 return INVALID_HANDLE_VALUE
;
587 if ( (dwDesiredAccess
& ~(GENERIC_READ
| GENERIC_WRITE
)) ||
588 (dwShareMode
& ~(FILE_SHARE_READ
| FILE_SHARE_WRITE
)) )
590 SetLastError(ERROR_INVALID_PARAMETER
);
591 return INVALID_HANDLE_VALUE
;
594 OpenConsoleRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
595 OpenConsoleRequest
->HandleType
= HandleType
;
596 OpenConsoleRequest
->DesiredAccess
= dwDesiredAccess
;
597 OpenConsoleRequest
->InheritHandle
= bInheritHandle
;
598 OpenConsoleRequest
->ShareMode
= dwShareMode
;
600 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
602 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepOpenConsole
),
603 sizeof(*OpenConsoleRequest
));
604 if (!NT_SUCCESS(ApiMessage
.Status
))
606 BaseSetLastNTError(ApiMessage
.Status
);
607 return INVALID_HANDLE_VALUE
;
610 return OpenConsoleRequest
->Handle
;
615 * @implemented (Undocumented)
616 * @note See http://undoc.airesoft.co.uk/kernel32.dll/SetConsoleCursor.php
620 SetConsoleCursor(HANDLE hConsoleOutput
,
623 CONSOLE_API_MESSAGE ApiMessage
;
624 PCONSOLE_SETCURSOR SetCursorRequest
= &ApiMessage
.Data
.SetCursorRequest
;
626 SetCursorRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
627 SetCursorRequest
->OutputHandle
= hConsoleOutput
;
628 SetCursorRequest
->CursorHandle
= hCursor
;
630 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
632 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetCursor
),
633 sizeof(*SetCursorRequest
));
634 if (!NT_SUCCESS(ApiMessage
.Status
))
636 BaseSetLastNTError(ApiMessage
.Status
);
649 SetConsoleDisplayMode(HANDLE hConsoleOutput
,
650 DWORD dwFlags
, // dwModeFlags
651 PCOORD lpNewScreenBufferDimensions
)
653 CONSOLE_API_MESSAGE ApiMessage
;
654 PCONSOLE_SETDISPLAYMODE SetDisplayModeRequest
= &ApiMessage
.Data
.SetDisplayModeRequest
;
656 SetDisplayModeRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
657 SetDisplayModeRequest
->OutputHandle
= hConsoleOutput
;
658 SetDisplayModeRequest
->DisplayMode
= dwFlags
; // ModeFlags ; dwModeFlags
659 SetDisplayModeRequest
->NewSBDim
.X
= 0;
660 SetDisplayModeRequest
->NewSBDim
.Y
= 0;
661 /* SetDisplayModeRequest->EventHandle; */
663 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
665 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetDisplayMode
),
666 sizeof(*SetDisplayModeRequest
));
667 if (!NT_SUCCESS(ApiMessage
.Status
))
669 BaseSetLastNTError(ApiMessage
.Status
);
673 if (lpNewScreenBufferDimensions
)
674 *lpNewScreenBufferDimensions
= SetDisplayModeRequest
->NewSBDim
;
681 * @unimplemented (Undocumented)
685 SetConsoleFont(HANDLE hConsoleOutput
,
688 DPRINT1("SetConsoleFont(0x%p, %lu) UNIMPLEMENTED!\n", hConsoleOutput
, nFont
);
689 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
695 * @implemented (Undocumented)
699 SetConsoleHardwareState(HANDLE hConsoleOutput
,
703 CONSOLE_API_MESSAGE ApiMessage
;
704 PCONSOLE_GETSETHWSTATE HardwareStateRequest
= &ApiMessage
.Data
.HardwareStateRequest
;
706 DPRINT1("SetConsoleHardwareState(%lu, %lu) UNIMPLEMENTED!\n", Flags
, State
);
708 HardwareStateRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
709 HardwareStateRequest
->OutputHandle
= hConsoleOutput
;
710 HardwareStateRequest
->Flags
= Flags
;
711 HardwareStateRequest
->State
= State
;
713 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
715 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetHardwareState
),
716 sizeof(*HardwareStateRequest
));
717 if (!NT_SUCCESS(ApiMessage
.Status
))
719 BaseSetLastNTError(ApiMessage
.Status
);
728 * @unimplemented (Undocumented)
732 SetConsoleKeyShortcuts(DWORD Unknown0
,
737 DPRINT1("SetConsoleKeyShortcuts(0x%x, 0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
, Unknown2
, Unknown3
);
738 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
744 * @implemented (Undocumented)
745 * @note See http://undoc.airesoft.co.uk/kernel32.dll/SetConsoleMaximumWindowSize.php
746 * Does nothing, returns TRUE only. Checked on Windows Server 2003.
750 SetConsoleMaximumWindowSize(HANDLE hConsoleOutput
,
753 DPRINT1("SetConsoleMaximumWindowSize(0x%p, {%d, %d}) does nothing\n",
754 hConsoleOutput
, dwMaximumSize
.X
, dwMaximumSize
.Y
);
760 * @implemented (Undocumented)
764 SetConsoleMenuClose(BOOL bEnable
)
766 CONSOLE_API_MESSAGE ApiMessage
;
767 PCONSOLE_SETMENUCLOSE SetMenuCloseRequest
= &ApiMessage
.Data
.SetMenuCloseRequest
;
769 SetMenuCloseRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
770 SetMenuCloseRequest
->Enable
= bEnable
;
772 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
774 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetMenuClose
),
775 sizeof(*SetMenuCloseRequest
));
776 if (!NT_SUCCESS(ApiMessage
.Status
))
778 BaseSetLastNTError(ApiMessage
.Status
);
787 * @implemented (Undocumented)
788 * @note See http://comments.gmane.org/gmane.comp.lang.harbour.devel/27844
789 * Usage example: https://github.com/harbour/core/commit/d79a1b7b812cbde6ddf718ebfd6939a24f633e52
793 SetConsolePalette(HANDLE hConsoleOutput
,
797 CONSOLE_API_MESSAGE ApiMessage
;
798 PCONSOLE_SETPALETTE SetPaletteRequest
= &ApiMessage
.Data
.SetPaletteRequest
;
800 SetPaletteRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
801 SetPaletteRequest
->OutputHandle
= hConsoleOutput
;
802 SetPaletteRequest
->PaletteHandle
= hPalette
;
803 SetPaletteRequest
->Usage
= dwUsage
;
805 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
807 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetPalette
),
808 sizeof(*SetPaletteRequest
));
809 if (!NT_SUCCESS(ApiMessage
.Status
))
811 BaseSetLastNTError(ApiMessage
.Status
);
819 * @implemented (Undocumented)
820 * @note See http://undoc.airesoft.co.uk/kernel32.dll/ShowConsoleCursor.php
824 ShowConsoleCursor(HANDLE hConsoleOutput
,
827 CONSOLE_API_MESSAGE ApiMessage
;
828 PCONSOLE_SHOWCURSOR ShowCursorRequest
= &ApiMessage
.Data
.ShowCursorRequest
;
830 ShowCursorRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
831 ShowCursorRequest
->OutputHandle
= hConsoleOutput
;
832 ShowCursorRequest
->Show
= bShow
;
833 ShowCursorRequest
->RefCount
= 0;
835 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
837 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepShowCursor
),
838 sizeof(*ShowCursorRequest
));
840 return ShowCursorRequest
->RefCount
;
845 * FUNCTION: Checks whether the given handle is a valid console handle.
848 * hIoHandle - Handle to be checked.
851 * TRUE : Handle is a valid console handle.
852 * FALSE: Handle is not a valid console handle.
854 * STATUS: Officially undocumented
860 VerifyConsoleIoHandle(HANDLE hIoHandle
)
862 CONSOLE_API_MESSAGE ApiMessage
;
863 PCONSOLE_VERIFYHANDLE VerifyHandleRequest
= &ApiMessage
.Data
.VerifyHandleRequest
;
865 VerifyHandleRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
866 VerifyHandleRequest
->Handle
= hIoHandle
;
867 VerifyHandleRequest
->IsValid
= FALSE
;
869 /* If the process is not attached to a console, return invalid handle */
870 if (VerifyHandleRequest
->ConsoleHandle
== NULL
) return FALSE
;
872 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
874 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepVerifyIoHandle
),
875 sizeof(*VerifyHandleRequest
));
876 if (!NT_SUCCESS(ApiMessage
.Status
))
878 BaseSetLastNTError(ApiMessage
.Status
);
882 return VerifyHandleRequest
->IsValid
;
887 * @implemented (Undocumented)
891 CloseConsoleHandle(HANDLE hHandle
)
893 CONSOLE_API_MESSAGE ApiMessage
;
894 PCONSOLE_CLOSEHANDLE CloseHandleRequest
= &ApiMessage
.Data
.CloseHandleRequest
;
896 CloseHandleRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
897 CloseHandleRequest
->Handle
= hHandle
;
899 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
901 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepCloseHandle
),
902 sizeof(*CloseHandleRequest
));
903 if (!NT_SUCCESS(ApiMessage
.Status
))
905 BaseSetLastNTError(ApiMessage
.Status
);
918 GetStdHandle(DWORD nStdHandle
)
920 * FUNCTION: Get a handle for the standard input, standard output
921 * and a standard error device.
924 * nStdHandle - Specifies the device for which to return the handle.
926 * RETURNS: If the function succeeds, the return value is the handle
927 * of the specified device. Otherwise the value is INVALID_HANDLE_VALUE.
930 PRTL_USER_PROCESS_PARAMETERS Ppb
= NtCurrentPeb()->ProcessParameters
;
931 HANDLE Handle
= INVALID_HANDLE_VALUE
;
935 case STD_INPUT_HANDLE
:
936 Handle
= Ppb
->StandardInput
;
939 case STD_OUTPUT_HANDLE
:
940 Handle
= Ppb
->StandardOutput
;
943 case STD_ERROR_HANDLE
:
944 Handle
= Ppb
->StandardError
;
948 /* If the returned handle is invalid, set last error */
949 if (Handle
== INVALID_HANDLE_VALUE
) SetLastError(ERROR_INVALID_HANDLE
);
960 SetStdHandle(DWORD nStdHandle
,
963 * FUNCTION: Set the handle for the standard input, standard output or
964 * the standard error device.
967 * nStdHandle - Specifies the handle to be set.
968 * hHandle - The handle to set.
970 * RETURNS: TRUE if the function succeeds, FALSE otherwise.
973 PRTL_USER_PROCESS_PARAMETERS Ppb
= NtCurrentPeb()->ProcessParameters
;
975 /* No need to check if hHandle == INVALID_HANDLE_VALUE */
979 case STD_INPUT_HANDLE
:
980 Ppb
->StandardInput
= hHandle
;
983 case STD_OUTPUT_HANDLE
:
984 Ppb
->StandardOutput
= hHandle
;
987 case STD_ERROR_HANDLE
:
988 Ppb
->StandardError
= hHandle
;
992 /* nStdHandle was invalid, bail out */
993 SetLastError(ERROR_INVALID_HANDLE
);
998 /*--------------------------------------------------------------
1008 PRTL_USER_PROCESS_PARAMETERS Parameters
= NtCurrentPeb()->ProcessParameters
;
1009 CONSOLE_API_MESSAGE ApiMessage
;
1010 PCONSOLE_ALLOCCONSOLE AllocConsoleRequest
= &ApiMessage
.Data
.AllocConsoleRequest
;
1011 PCSR_CAPTURE_BUFFER CaptureBuffer
;
1013 if (Parameters
->ConsoleHandle
)
1015 DPRINT1("AllocConsole: Allocating a console to a process already having one\n");
1016 SetLastError(ERROR_ACCESS_DENIED
);
1020 CaptureBuffer
= CsrAllocateCaptureBuffer(1, sizeof(CONSOLE_START_INFO
));
1021 if (CaptureBuffer
== NULL
)
1023 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
1024 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1028 CsrAllocateMessagePointer(CaptureBuffer
,
1029 sizeof(CONSOLE_START_INFO
),
1030 (PVOID
*)&AllocConsoleRequest
->ConsoleStartInfo
);
1032 InitConsoleInfo(AllocConsoleRequest
->ConsoleStartInfo
,
1033 &Parameters
->ImagePathName
);
1035 AllocConsoleRequest
->ConsoleHandle
= NULL
;
1036 AllocConsoleRequest
->CtrlDispatcher
= ConsoleControlDispatcher
;
1037 AllocConsoleRequest
->PropDispatcher
= PropDialogHandler
;
1039 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1041 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepAlloc
),
1042 sizeof(CONSOLE_ALLOCCONSOLE
));
1044 CsrFreeCaptureBuffer(CaptureBuffer
);
1046 if (!NT_SUCCESS(Status
))
1048 BaseSetLastNTError(Status
);
1052 Parameters
->ConsoleHandle
= AllocConsoleRequest
->ConsoleHandle
;
1053 SetStdHandle(STD_INPUT_HANDLE
, AllocConsoleRequest
->InputHandle
);
1054 SetStdHandle(STD_OUTPUT_HANDLE
, AllocConsoleRequest
->OutputHandle
);
1055 SetStdHandle(STD_ERROR_HANDLE
, AllocConsoleRequest
->ErrorHandle
);
1057 /* Initialize Console Ctrl Handler */
1058 InitConsoleCtrlHandling();
1060 InputWaitHandle
= AllocConsoleRequest
->InputWaitHandle
;
1066 /*--------------------------------------------------------------
1075 // AG: I'm not sure if this is correct (what happens to std handles?)
1076 // but I just tried to reverse what AllocConsole() does...
1079 CONSOLE_API_MESSAGE ApiMessage
;
1081 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1083 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepFree
),
1084 sizeof(CONSOLE_FREECONSOLE
));
1085 if (!NT_SUCCESS(Status
))
1087 BaseSetLastNTError(Status
);
1091 NtCurrentPeb()->ProcessParameters
->ConsoleHandle
= NULL
;
1093 CloseHandle(InputWaitHandle
);
1094 InputWaitHandle
= INVALID_HANDLE_VALUE
;
1100 /*--------------------------------------------------------------
1101 * GetConsoleScreenBufferInfo
1107 GetConsoleScreenBufferInfo(HANDLE hConsoleOutput
,
1108 PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo
)
1110 CONSOLE_API_MESSAGE ApiMessage
;
1111 PCONSOLE_GETSCREENBUFFERINFO ScreenBufferInfoRequest
= &ApiMessage
.Data
.ScreenBufferInfoRequest
;
1113 if (lpConsoleScreenBufferInfo
== NULL
)
1115 SetLastError(ERROR_INVALID_PARAMETER
);
1119 ScreenBufferInfoRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1120 ScreenBufferInfoRequest
->OutputHandle
= hConsoleOutput
;
1122 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1124 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetScreenBufferInfo
),
1125 sizeof(*ScreenBufferInfoRequest
));
1126 if (!NT_SUCCESS(ApiMessage
.Status
))
1128 BaseSetLastNTError(ApiMessage
.Status
);
1132 lpConsoleScreenBufferInfo
->dwSize
= ScreenBufferInfoRequest
->ScreenBufferSize
;
1133 lpConsoleScreenBufferInfo
->dwCursorPosition
= ScreenBufferInfoRequest
->CursorPosition
;
1134 lpConsoleScreenBufferInfo
->wAttributes
= ScreenBufferInfoRequest
->Attributes
;
1135 lpConsoleScreenBufferInfo
->srWindow
.Left
= ScreenBufferInfoRequest
->ViewOrigin
.X
;
1136 lpConsoleScreenBufferInfo
->srWindow
.Top
= ScreenBufferInfoRequest
->ViewOrigin
.Y
;
1137 lpConsoleScreenBufferInfo
->srWindow
.Right
= ScreenBufferInfoRequest
->ViewOrigin
.X
+ ScreenBufferInfoRequest
->ViewSize
.X
- 1;
1138 lpConsoleScreenBufferInfo
->srWindow
.Bottom
= ScreenBufferInfoRequest
->ViewOrigin
.Y
+ ScreenBufferInfoRequest
->ViewSize
.Y
- 1;
1139 lpConsoleScreenBufferInfo
->dwMaximumWindowSize
= ScreenBufferInfoRequest
->MaximumViewSize
;
1145 /*--------------------------------------------------------------
1146 * SetConsoleCursorPosition
1152 SetConsoleCursorPosition(HANDLE hConsoleOutput
,
1153 COORD dwCursorPosition
)
1155 CONSOLE_API_MESSAGE ApiMessage
;
1156 PCONSOLE_SETCURSORPOSITION SetCursorPositionRequest
= &ApiMessage
.Data
.SetCursorPositionRequest
;
1158 SetCursorPositionRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1159 SetCursorPositionRequest
->OutputHandle
= hConsoleOutput
;
1160 SetCursorPositionRequest
->Position
= dwCursorPosition
;
1162 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1164 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetCursorPosition
),
1165 sizeof(*SetCursorPositionRequest
));
1166 if (!NT_SUCCESS(ApiMessage
.Status
))
1168 BaseSetLastNTError(ApiMessage
.Status
);
1176 /*--------------------------------------------------------------
1183 GetConsoleMode(HANDLE hConsoleHandle
,
1186 CONSOLE_API_MESSAGE ApiMessage
;
1187 PCONSOLE_GETSETCONSOLEMODE ConsoleModeRequest
= &ApiMessage
.Data
.ConsoleModeRequest
;
1191 SetLastError(ERROR_INVALID_PARAMETER
);
1195 ConsoleModeRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1196 ConsoleModeRequest
->Handle
= hConsoleHandle
;
1198 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1200 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetMode
),
1201 sizeof(*ConsoleModeRequest
));
1202 if (!NT_SUCCESS(ApiMessage
.Status
))
1204 BaseSetLastNTError(ApiMessage
.Status
);
1208 *lpMode
= ConsoleModeRequest
->Mode
;
1214 /*--------------------------------------------------------------
1221 SetConsoleMode(HANDLE hConsoleHandle
,
1224 CONSOLE_API_MESSAGE ApiMessage
;
1225 PCONSOLE_GETSETCONSOLEMODE ConsoleModeRequest
= &ApiMessage
.Data
.ConsoleModeRequest
;
1227 ConsoleModeRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1228 ConsoleModeRequest
->Handle
= hConsoleHandle
;
1229 ConsoleModeRequest
->Mode
= dwMode
;
1231 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1233 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetMode
),
1234 sizeof(*ConsoleModeRequest
));
1235 if (!NT_SUCCESS(ApiMessage
.Status
))
1237 BaseSetLastNTError(ApiMessage
.Status
);
1245 /*--------------------------------------------------------------
1246 * GetNumberOfConsoleInputEvents
1252 GetNumberOfConsoleInputEvents(HANDLE hConsoleInput
,
1253 LPDWORD lpNumberOfEvents
)
1255 CONSOLE_API_MESSAGE ApiMessage
;
1256 PCONSOLE_GETNUMINPUTEVENTS GetNumInputEventsRequest
= &ApiMessage
.Data
.GetNumInputEventsRequest
;
1258 GetNumInputEventsRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1259 GetNumInputEventsRequest
->InputHandle
= hConsoleInput
;
1260 GetNumInputEventsRequest
->NumberOfEvents
= 0;
1262 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1264 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetNumberOfInputEvents
),
1265 sizeof(*GetNumInputEventsRequest
));
1266 if (!NT_SUCCESS(ApiMessage
.Status
))
1268 BaseSetLastNTError(ApiMessage
.Status
);
1272 if (lpNumberOfEvents
== NULL
)
1274 SetLastError(ERROR_INVALID_ACCESS
);
1278 *lpNumberOfEvents
= GetNumInputEventsRequest
->NumberOfEvents
;
1284 /*--------------------------------------------------------------
1285 * GetLargestConsoleWindowSize
1291 GetLargestConsoleWindowSize(HANDLE hConsoleOutput
)
1293 CONSOLE_API_MESSAGE ApiMessage
;
1294 PCONSOLE_GETLARGESTWINDOWSIZE GetLargestWindowSizeRequest
= &ApiMessage
.Data
.GetLargestWindowSizeRequest
;
1296 GetLargestWindowSizeRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1297 GetLargestWindowSizeRequest
->OutputHandle
= hConsoleOutput
;
1298 GetLargestWindowSizeRequest
->Size
.X
= 0;
1299 GetLargestWindowSizeRequest
->Size
.Y
= 0;
1301 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1303 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetLargestWindowSize
),
1304 sizeof(*GetLargestWindowSizeRequest
));
1305 if (!NT_SUCCESS(ApiMessage
.Status
))
1307 BaseSetLastNTError(ApiMessage
.Status
);
1310 DPRINT1("GetLargestConsoleWindowSize, X = %d, Y = %d\n", GetLargestWindowSizeRequest
->Size
.X
, GetLargestWindowSizeRequest
->Size
.Y
);
1311 return GetLargestWindowSizeRequest
->Size
;
1315 /*--------------------------------------------------------------
1316 * GetConsoleCursorInfo
1322 GetConsoleCursorInfo(HANDLE hConsoleOutput
,
1323 PCONSOLE_CURSOR_INFO lpConsoleCursorInfo
)
1325 CONSOLE_API_MESSAGE ApiMessage
;
1326 PCONSOLE_GETSETCURSORINFO CursorInfoRequest
= &ApiMessage
.Data
.CursorInfoRequest
;
1328 if (!lpConsoleCursorInfo
)
1330 if (!hConsoleOutput
)
1331 SetLastError(ERROR_INVALID_HANDLE
);
1333 SetLastError(ERROR_INVALID_ACCESS
);
1338 CursorInfoRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1339 CursorInfoRequest
->OutputHandle
= hConsoleOutput
;
1341 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1343 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetCursorInfo
),
1344 sizeof(*CursorInfoRequest
));
1345 if (!NT_SUCCESS(ApiMessage
.Status
))
1347 BaseSetLastNTError(ApiMessage
.Status
);
1351 *lpConsoleCursorInfo
= CursorInfoRequest
->Info
;
1357 /*--------------------------------------------------------------
1358 * SetConsoleCursorInfo
1364 SetConsoleCursorInfo(HANDLE hConsoleOutput
,
1365 CONST CONSOLE_CURSOR_INFO
*lpConsoleCursorInfo
)
1367 CONSOLE_API_MESSAGE ApiMessage
;
1368 PCONSOLE_GETSETCURSORINFO CursorInfoRequest
= &ApiMessage
.Data
.CursorInfoRequest
;
1370 CursorInfoRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1371 CursorInfoRequest
->OutputHandle
= hConsoleOutput
;
1372 CursorInfoRequest
->Info
= *lpConsoleCursorInfo
;
1374 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1376 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetCursorInfo
),
1377 sizeof(*CursorInfoRequest
));
1378 if (!NT_SUCCESS(ApiMessage
.Status
))
1380 BaseSetLastNTError(ApiMessage
.Status
);
1388 /*--------------------------------------------------------------
1389 * GetNumberOfConsoleMouseButtons
1395 GetNumberOfConsoleMouseButtons(LPDWORD lpNumberOfMouseButtons
)
1397 DPRINT1("GetNumberOfConsoleMouseButtons(0x%p) UNIMPLEMENTED!\n", lpNumberOfMouseButtons
);
1398 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1403 /*--------------------------------------------------------------
1404 * SetConsoleActiveScreenBuffer
1410 SetConsoleActiveScreenBuffer(HANDLE hConsoleOutput
)
1412 CONSOLE_API_MESSAGE ApiMessage
;
1413 PCONSOLE_SETACTIVESCREENBUFFER SetScreenBufferRequest
= &ApiMessage
.Data
.SetScreenBufferRequest
;
1415 SetScreenBufferRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1416 SetScreenBufferRequest
->OutputHandle
= hConsoleOutput
;
1418 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1420 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetActiveScreenBuffer
),
1421 sizeof(*SetScreenBufferRequest
));
1422 if (!NT_SUCCESS(ApiMessage
.Status
))
1424 BaseSetLastNTError(ApiMessage
.Status
);
1432 /*--------------------------------------------------------------
1433 * FlushConsoleInputBuffer
1439 FlushConsoleInputBuffer(HANDLE hConsoleInput
)
1441 CONSOLE_API_MESSAGE ApiMessage
;
1442 PCONSOLE_FLUSHINPUTBUFFER FlushInputBufferRequest
= &ApiMessage
.Data
.FlushInputBufferRequest
;
1444 FlushInputBufferRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1445 FlushInputBufferRequest
->InputHandle
= hConsoleInput
;
1447 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1449 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepFlushInputBuffer
),
1450 sizeof(*FlushInputBufferRequest
));
1451 if (!NT_SUCCESS(ApiMessage
.Status
))
1453 BaseSetLastNTError(ApiMessage
.Status
);
1461 /*--------------------------------------------------------------
1462 * SetConsoleScreenBufferSize
1468 SetConsoleScreenBufferSize(HANDLE hConsoleOutput
,
1471 CONSOLE_API_MESSAGE ApiMessage
;
1472 PCONSOLE_SETSCREENBUFFERSIZE SetScreenBufferSizeRequest
= &ApiMessage
.Data
.SetScreenBufferSizeRequest
;
1474 SetScreenBufferSizeRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1475 SetScreenBufferSizeRequest
->OutputHandle
= hConsoleOutput
;
1476 SetScreenBufferSizeRequest
->Size
= dwSize
;
1478 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1480 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetScreenBufferSize
),
1481 sizeof(*SetScreenBufferSizeRequest
));
1482 if (!NT_SUCCESS(ApiMessage
.Status
))
1484 BaseSetLastNTError(ApiMessage
.Status
);
1494 IntScrollConsoleScreenBuffer(HANDLE hConsoleOutput
,
1495 const SMALL_RECT
*lpScrollRectangle
,
1496 const SMALL_RECT
*lpClipRectangle
,
1497 COORD dwDestinationOrigin
,
1498 const CHAR_INFO
*lpFill
,
1502 CONSOLE_API_MESSAGE ApiMessage
;
1503 PCONSOLE_SCROLLSCREENBUFFER ScrollScreenBufferRequest
= &ApiMessage
.Data
.ScrollScreenBufferRequest
;
1505 ScrollScreenBufferRequest
->OutputHandle
= hConsoleOutput
;
1506 ScrollScreenBufferRequest
->Unicode
= bUnicode
;
1507 ScrollScreenBufferRequest
->ScrollRectangle
= *lpScrollRectangle
;
1509 if (lpClipRectangle
!= NULL
)
1511 ScrollScreenBufferRequest
->UseClipRectangle
= TRUE
;
1512 ScrollScreenBufferRequest
->ClipRectangle
= *lpClipRectangle
;
1516 ScrollScreenBufferRequest
->UseClipRectangle
= FALSE
;
1519 ScrollScreenBufferRequest
->DestinationOrigin
= dwDestinationOrigin
;
1520 ScrollScreenBufferRequest
->Fill
= *lpFill
;
1522 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1524 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepScrollScreenBuffer
),
1525 sizeof(CONSOLE_SCROLLSCREENBUFFER
));
1527 if (!NT_SUCCESS(Status
))
1529 BaseSetLastNTError(Status
);
1537 /*--------------------------------------------------------------
1538 * ScrollConsoleScreenBufferA
1544 ScrollConsoleScreenBufferA(HANDLE hConsoleOutput
,
1545 CONST SMALL_RECT
*lpScrollRectangle
,
1546 CONST SMALL_RECT
*lpClipRectangle
,
1547 COORD dwDestinationOrigin
,
1548 CONST CHAR_INFO
*lpFill
)
1550 return IntScrollConsoleScreenBuffer(hConsoleOutput
,
1551 (PSMALL_RECT
)lpScrollRectangle
,
1552 (PSMALL_RECT
)lpClipRectangle
,
1553 dwDestinationOrigin
,
1559 /*--------------------------------------------------------------
1560 * ScrollConsoleScreenBufferW
1566 ScrollConsoleScreenBufferW(HANDLE hConsoleOutput
,
1567 CONST SMALL_RECT
*lpScrollRectangle
,
1568 CONST SMALL_RECT
*lpClipRectangle
,
1569 COORD dwDestinationOrigin
,
1570 CONST CHAR_INFO
*lpFill
)
1572 return IntScrollConsoleScreenBuffer(hConsoleOutput
,
1575 dwDestinationOrigin
,
1581 /*--------------------------------------------------------------
1582 * SetConsoleWindowInfo
1588 SetConsoleWindowInfo(HANDLE hConsoleOutput
,
1590 CONST SMALL_RECT
*lpConsoleWindow
)
1592 CONSOLE_API_MESSAGE ApiMessage
;
1593 PCONSOLE_SETWINDOWINFO SetWindowInfoRequest
= &ApiMessage
.Data
.SetWindowInfoRequest
;
1595 if (lpConsoleWindow
== NULL
)
1597 SetLastError(ERROR_INVALID_PARAMETER
);
1601 SetWindowInfoRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1602 SetWindowInfoRequest
->OutputHandle
= hConsoleOutput
;
1603 SetWindowInfoRequest
->Absolute
= bAbsolute
;
1604 SetWindowInfoRequest
->WindowRect
= *lpConsoleWindow
;
1606 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1608 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetWindowInfo
),
1609 sizeof(*SetWindowInfoRequest
));
1610 if (!NT_SUCCESS(ApiMessage
.Status
))
1612 BaseSetLastNTError(ApiMessage
.Status
);
1620 /*--------------------------------------------------------------
1621 * SetConsoleTextAttribute
1627 SetConsoleTextAttribute(HANDLE hConsoleOutput
,
1630 CONSOLE_API_MESSAGE ApiMessage
;
1631 PCONSOLE_SETTEXTATTRIB SetTextAttribRequest
= &ApiMessage
.Data
.SetTextAttribRequest
;
1633 SetTextAttribRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1634 SetTextAttribRequest
->OutputHandle
= hConsoleOutput
;
1635 SetTextAttribRequest
->Attributes
= wAttributes
;
1637 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1639 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetTextAttribute
),
1640 sizeof(*SetTextAttribRequest
));
1641 if (!NT_SUCCESS(ApiMessage
.Status
))
1643 BaseSetLastNTError(ApiMessage
.Status
);
1653 AddConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine
)
1655 PHANDLER_ROUTINE
* NewCtrlHandlers
= NULL
;
1657 if (HandlerRoutine
== NULL
)
1659 NtCurrentPeb()->ProcessParameters
->ConsoleFlags
= TRUE
;
1663 if (NrCtrlHandlers
== NrAllocatedHandlers
)
1665 NewCtrlHandlers
= RtlAllocateHeap(RtlGetProcessHeap(),
1667 (NrCtrlHandlers
+ 4) * sizeof(PHANDLER_ROUTINE
));
1668 if (NewCtrlHandlers
== NULL
)
1670 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1674 memmove(NewCtrlHandlers
, CtrlHandlers
, sizeof(PHANDLER_ROUTINE
) * NrCtrlHandlers
);
1676 if (NrAllocatedHandlers
> 1) RtlFreeHeap(RtlGetProcessHeap(), 0, CtrlHandlers
);
1678 CtrlHandlers
= NewCtrlHandlers
;
1679 NrAllocatedHandlers
+= 4;
1682 ASSERT(NrCtrlHandlers
< NrAllocatedHandlers
);
1684 CtrlHandlers
[NrCtrlHandlers
++] = HandlerRoutine
;
1691 RemoveConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine
)
1695 if (HandlerRoutine
== NULL
)
1697 NtCurrentPeb()->ProcessParameters
->ConsoleFlags
= FALSE
;
1701 for (i
= 0; i
< NrCtrlHandlers
; i
++)
1703 if (CtrlHandlers
[i
] == HandlerRoutine
)
1705 if (i
< (NrCtrlHandlers
- 1))
1707 memmove(&CtrlHandlers
[i
],
1709 (NrCtrlHandlers
- i
+ 1) * sizeof(PHANDLER_ROUTINE
));
1717 SetLastError(ERROR_INVALID_PARAMETER
);
1727 SetConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine
,
1732 RtlEnterCriticalSection(&BaseDllDirectoryLock
);
1735 Ret
= AddConsoleCtrlHandler(HandlerRoutine
);
1739 Ret
= RemoveConsoleCtrlHandler(HandlerRoutine
);
1742 RtlLeaveCriticalSection(&BaseDllDirectoryLock
);
1747 /*--------------------------------------------------------------
1748 * GenerateConsoleCtrlEvent
1754 GenerateConsoleCtrlEvent(DWORD dwCtrlEvent
,
1755 DWORD dwProcessGroupId
)
1757 CONSOLE_API_MESSAGE ApiMessage
;
1758 PCONSOLE_GENERATECTRLEVENT GenerateCtrlEventRequest
= &ApiMessage
.Data
.GenerateCtrlEventRequest
;
1760 if (dwCtrlEvent
!= CTRL_C_EVENT
&& dwCtrlEvent
!= CTRL_BREAK_EVENT
)
1762 SetLastError(ERROR_INVALID_PARAMETER
);
1766 GenerateCtrlEventRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1767 GenerateCtrlEventRequest
->CtrlEvent
= dwCtrlEvent
;
1768 GenerateCtrlEventRequest
->ProcessGroupId
= dwProcessGroupId
;
1770 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1772 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGenerateCtrlEvent
),
1773 sizeof(*GenerateCtrlEventRequest
));
1774 if (!NT_SUCCESS(ApiMessage
.Status
))
1776 BaseSetLastNTError(ApiMessage
.Status
);
1785 IntGetConsoleTitle(LPVOID lpConsoleTitle
, DWORD dwNumChars
, BOOLEAN bUnicode
)
1787 CONSOLE_API_MESSAGE ApiMessage
;
1788 PCONSOLE_GETSETCONSOLETITLE TitleRequest
= &ApiMessage
.Data
.TitleRequest
;
1789 PCSR_CAPTURE_BUFFER CaptureBuffer
;
1791 if (dwNumChars
== 0) return 0;
1793 TitleRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1794 TitleRequest
->Length
= dwNumChars
* (bUnicode
? sizeof(WCHAR
) : sizeof(CHAR
));
1795 TitleRequest
->Unicode
= bUnicode
;
1797 CaptureBuffer
= CsrAllocateCaptureBuffer(1, TitleRequest
->Length
);
1798 if (CaptureBuffer
== NULL
)
1800 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
1801 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1805 CsrAllocateMessagePointer(CaptureBuffer
,
1806 TitleRequest
->Length
,
1807 (PVOID
*)&TitleRequest
->Title
);
1809 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1811 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetTitle
),
1812 sizeof(*TitleRequest
));
1813 if (!NT_SUCCESS(ApiMessage
.Status
))
1815 CsrFreeCaptureBuffer(CaptureBuffer
);
1816 BaseSetLastNTError(ApiMessage
.Status
);
1820 dwNumChars
= TitleRequest
->Length
/ (bUnicode
? sizeof(WCHAR
) : sizeof(CHAR
));
1824 memcpy(lpConsoleTitle
, TitleRequest
->Title
, TitleRequest
->Length
);
1827 ((LPWSTR
)lpConsoleTitle
)[dwNumChars
] = L
'\0';
1829 ((LPSTR
)lpConsoleTitle
)[dwNumChars
] = '\0';
1832 CsrFreeCaptureBuffer(CaptureBuffer
);
1838 /*--------------------------------------------------------------
1845 GetConsoleTitleW(LPWSTR lpConsoleTitle
,
1848 return IntGetConsoleTitle(lpConsoleTitle
, nSize
, TRUE
);
1852 /*--------------------------------------------------------------
1859 GetConsoleTitleA(LPSTR lpConsoleTitle
,
1862 return IntGetConsoleTitle(lpConsoleTitle
, nSize
, FALSE
);
1867 IntSetConsoleTitle(CONST VOID
*lpConsoleTitle
, DWORD dwNumChars
, BOOLEAN bUnicode
)
1869 CONSOLE_API_MESSAGE ApiMessage
;
1870 PCONSOLE_GETSETCONSOLETITLE TitleRequest
= &ApiMessage
.Data
.TitleRequest
;
1871 PCSR_CAPTURE_BUFFER CaptureBuffer
;
1873 TitleRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1874 TitleRequest
->Length
= dwNumChars
* (bUnicode
? sizeof(WCHAR
) : sizeof(CHAR
));
1875 TitleRequest
->Unicode
= bUnicode
;
1877 CaptureBuffer
= CsrAllocateCaptureBuffer(1, TitleRequest
->Length
);
1878 if (CaptureBuffer
== NULL
)
1880 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
1881 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1885 CsrCaptureMessageBuffer(CaptureBuffer
,
1886 (PVOID
)lpConsoleTitle
,
1887 TitleRequest
->Length
,
1888 (PVOID
*)&TitleRequest
->Title
);
1890 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1892 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetTitle
),
1893 sizeof(*TitleRequest
));
1895 CsrFreeCaptureBuffer(CaptureBuffer
);
1897 if (!NT_SUCCESS(ApiMessage
.Status
))
1899 BaseSetLastNTError(ApiMessage
.Status
);
1906 /*--------------------------------------------------------------
1913 SetConsoleTitleW(LPCWSTR lpConsoleTitle
)
1915 return IntSetConsoleTitle(lpConsoleTitle
, wcslen(lpConsoleTitle
), TRUE
);
1919 /*--------------------------------------------------------------
1926 SetConsoleTitleA(LPCSTR lpConsoleTitle
)
1928 return IntSetConsoleTitle(lpConsoleTitle
, strlen(lpConsoleTitle
), FALSE
);
1932 /*--------------------------------------------------------------
1933 * CreateConsoleScreenBuffer
1939 CreateConsoleScreenBuffer(DWORD dwDesiredAccess
,
1941 CONST SECURITY_ATTRIBUTES
*lpSecurityAttributes
,
1943 LPVOID lpScreenBufferData
)
1945 CONSOLE_API_MESSAGE ApiMessage
;
1946 PCONSOLE_CREATESCREENBUFFER CreateScreenBufferRequest
= &ApiMessage
.Data
.CreateScreenBufferRequest
;
1947 PCSR_CAPTURE_BUFFER CaptureBuffer
= NULL
;
1948 PCONSOLE_GRAPHICS_BUFFER_INFO GraphicsBufferInfo
= lpScreenBufferData
;
1950 if ( (dwDesiredAccess
& ~(GENERIC_READ
| GENERIC_WRITE
)) ||
1951 (dwShareMode
& ~(FILE_SHARE_READ
| FILE_SHARE_WRITE
)) ||
1952 (dwFlags
!= CONSOLE_TEXTMODE_BUFFER
&& dwFlags
!= CONSOLE_GRAPHICS_BUFFER
) )
1954 SetLastError(ERROR_INVALID_PARAMETER
);
1955 return INVALID_HANDLE_VALUE
;
1958 CreateScreenBufferRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1959 CreateScreenBufferRequest
->DesiredAccess
= dwDesiredAccess
;
1960 CreateScreenBufferRequest
->InheritHandle
=
1961 (lpSecurityAttributes
? lpSecurityAttributes
->bInheritHandle
: FALSE
);
1962 CreateScreenBufferRequest
->ShareMode
= dwShareMode
;
1963 CreateScreenBufferRequest
->ScreenBufferType
= dwFlags
;
1965 if (dwFlags
== CONSOLE_GRAPHICS_BUFFER
)
1967 if (CreateScreenBufferRequest
->InheritHandle
|| GraphicsBufferInfo
== NULL
)
1969 SetLastError(ERROR_INVALID_PARAMETER
);
1970 return INVALID_HANDLE_VALUE
;
1973 CreateScreenBufferRequest
->GraphicsBufferInfo
= *GraphicsBufferInfo
;
1975 CaptureBuffer
= CsrAllocateCaptureBuffer(1, GraphicsBufferInfo
->dwBitMapInfoLength
);
1976 if (CaptureBuffer
== NULL
)
1978 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1979 return INVALID_HANDLE_VALUE
;
1982 CsrCaptureMessageBuffer(CaptureBuffer
,
1983 (PVOID
)GraphicsBufferInfo
->lpBitMapInfo
,
1984 GraphicsBufferInfo
->dwBitMapInfoLength
,
1985 (PVOID
*)&CreateScreenBufferRequest
->GraphicsBufferInfo
.lpBitMapInfo
);
1988 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1990 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepCreateScreenBuffer
),
1991 sizeof(*CreateScreenBufferRequest
));
1993 if (CaptureBuffer
) CsrFreeCaptureBuffer(CaptureBuffer
);
1995 if (!NT_SUCCESS(ApiMessage
.Status
))
1997 BaseSetLastNTError(ApiMessage
.Status
);
1998 return INVALID_HANDLE_VALUE
;
2001 if (dwFlags
== CONSOLE_GRAPHICS_BUFFER
&& GraphicsBufferInfo
)
2003 GraphicsBufferInfo
->hMutex
= CreateScreenBufferRequest
->hMutex
; // CreateScreenBufferRequest->GraphicsBufferInfo.hMutex ;
2004 GraphicsBufferInfo
->lpBitMap
= CreateScreenBufferRequest
->lpBitMap
; // CreateScreenBufferRequest->GraphicsBufferInfo.lpBitMap;
2007 return CreateScreenBufferRequest
->OutputHandle
;
2011 /*--------------------------------------------------------------
2020 CONSOLE_API_MESSAGE ApiMessage
;
2021 PCONSOLE_GETINPUTOUTPUTCP GetConsoleCPRequest
= &ApiMessage
.Data
.GetConsoleCPRequest
;
2023 /* Get the Input Code Page */
2024 GetConsoleCPRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
2025 GetConsoleCPRequest
->OutputCP
= FALSE
;
2027 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2029 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetCP
),
2030 sizeof(*GetConsoleCPRequest
));
2031 if (!NT_SUCCESS(ApiMessage
.Status
))
2033 BaseSetLastNTError(ApiMessage
.Status
);
2037 return GetConsoleCPRequest
->CodePage
;
2041 /*--------------------------------------------------------------
2048 SetConsoleCP(UINT wCodePageID
)
2050 CONSOLE_API_MESSAGE ApiMessage
;
2051 PCONSOLE_SETINPUTOUTPUTCP SetConsoleCPRequest
= &ApiMessage
.Data
.SetConsoleCPRequest
;
2053 /* Set the Input Code Page */
2054 SetConsoleCPRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
2055 SetConsoleCPRequest
->CodePage
= wCodePageID
;
2056 SetConsoleCPRequest
->OutputCP
= FALSE
;
2057 /* SetConsoleCPRequest->EventHandle; */
2059 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2061 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetCP
),
2062 sizeof(*SetConsoleCPRequest
));
2063 if (!NT_SUCCESS(ApiMessage
.Status
))
2065 BaseSetLastNTError(ApiMessage
.Status
);
2073 /*--------------------------------------------------------------
2074 * GetConsoleOutputCP
2080 GetConsoleOutputCP(VOID
)
2082 CONSOLE_API_MESSAGE ApiMessage
;
2083 PCONSOLE_GETINPUTOUTPUTCP GetConsoleCPRequest
= &ApiMessage
.Data
.GetConsoleCPRequest
;
2085 /* Get the Output Code Page */
2086 GetConsoleCPRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
2087 GetConsoleCPRequest
->OutputCP
= TRUE
;
2089 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2091 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetCP
),
2092 sizeof(*GetConsoleCPRequest
));
2093 if (!NT_SUCCESS(ApiMessage
.Status
))
2095 BaseSetLastNTError(ApiMessage
.Status
);
2099 return GetConsoleCPRequest
->CodePage
;
2103 /*--------------------------------------------------------------
2104 * SetConsoleOutputCP
2110 SetConsoleOutputCP(UINT wCodePageID
)
2112 CONSOLE_API_MESSAGE ApiMessage
;
2113 PCONSOLE_SETINPUTOUTPUTCP SetConsoleCPRequest
= &ApiMessage
.Data
.SetConsoleCPRequest
;
2115 /* Set the Output Code Page */
2116 SetConsoleCPRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
2117 SetConsoleCPRequest
->CodePage
= wCodePageID
;
2118 SetConsoleCPRequest
->OutputCP
= TRUE
;
2119 /* SetConsoleCPRequest->EventHandle; */
2121 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2123 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetCP
),
2124 sizeof(*SetConsoleCPRequest
));
2125 if (!NT_SUCCESS(ApiMessage
.Status
))
2127 BaseSetLastNTError(ApiMessage
.Status
);
2135 /*--------------------------------------------------------------
2136 * GetConsoleProcessList
2142 GetConsoleProcessList(LPDWORD lpdwProcessList
,
2143 DWORD dwProcessCount
)
2145 CONSOLE_API_MESSAGE ApiMessage
;
2146 PCONSOLE_GETPROCESSLIST GetProcessListRequest
= &ApiMessage
.Data
.GetProcessListRequest
;
2147 PCSR_CAPTURE_BUFFER CaptureBuffer
;
2148 ULONG nProcesses
= 0;
2150 if (lpdwProcessList
== NULL
|| dwProcessCount
== 0)
2152 SetLastError(ERROR_INVALID_PARAMETER
);
2156 CaptureBuffer
= CsrAllocateCaptureBuffer(1, dwProcessCount
* sizeof(DWORD
));
2157 if (CaptureBuffer
== NULL
)
2159 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
2160 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2164 GetProcessListRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
2165 GetProcessListRequest
->ProcessCount
= dwProcessCount
;
2167 CsrAllocateMessagePointer(CaptureBuffer
,
2168 dwProcessCount
* sizeof(DWORD
),
2169 (PVOID
*)&GetProcessListRequest
->ProcessIdsList
);
2171 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2173 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetProcessList
),
2174 sizeof(*GetProcessListRequest
));
2175 if (!NT_SUCCESS(ApiMessage
.Status
))
2177 BaseSetLastNTError(ApiMessage
.Status
);
2181 nProcesses
= GetProcessListRequest
->ProcessCount
;
2182 if (dwProcessCount
>= nProcesses
)
2184 memcpy(lpdwProcessList
, GetProcessListRequest
->ProcessIdsList
, nProcesses
* sizeof(DWORD
));
2188 CsrFreeCaptureBuffer(CaptureBuffer
);
2193 /*--------------------------------------------------------------
2194 * GetConsoleSelectionInfo
2200 GetConsoleSelectionInfo(PCONSOLE_SELECTION_INFO lpConsoleSelectionInfo
)
2202 CONSOLE_API_MESSAGE ApiMessage
;
2203 PCONSOLE_GETSELECTIONINFO GetSelectionInfoRequest
= &ApiMessage
.Data
.GetSelectionInfoRequest
;
2205 if (lpConsoleSelectionInfo
== NULL
)
2207 SetLastError(ERROR_INVALID_PARAMETER
);
2211 GetSelectionInfoRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
2213 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2215 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetSelectionInfo
),
2216 sizeof(*GetSelectionInfoRequest
));
2217 if (!NT_SUCCESS(ApiMessage
.Status
))
2219 BaseSetLastNTError(ApiMessage
.Status
);
2223 *lpConsoleSelectionInfo
= GetSelectionInfoRequest
->Info
;
2229 /*--------------------------------------------------------------
2234 * @note Strongly inspired by AllocConsole.
2238 AttachConsole(DWORD dwProcessId
)
2241 PRTL_USER_PROCESS_PARAMETERS Parameters
= NtCurrentPeb()->ProcessParameters
;
2242 CONSOLE_API_MESSAGE ApiMessage
;
2243 PCONSOLE_ATTACHCONSOLE AttachConsoleRequest
= &ApiMessage
.Data
.AttachConsoleRequest
;
2245 if (Parameters
->ConsoleHandle
)
2247 DPRINT1("AttachConsole: Attaching a console to a process already having one\n");
2248 SetLastError(ERROR_ACCESS_DENIED
);
2252 AttachConsoleRequest
->ProcessId
= dwProcessId
;
2253 AttachConsoleRequest
->CtrlDispatcher
= ConsoleControlDispatcher
;
2254 AttachConsoleRequest
->PropDispatcher
= PropDialogHandler
;
2256 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2258 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepAttach
),
2259 sizeof(CONSOLE_ATTACHCONSOLE
));
2260 if (!NT_SUCCESS(Status
))
2262 BaseSetLastNTError(Status
);
2266 Parameters
->ConsoleHandle
= AttachConsoleRequest
->ConsoleHandle
;
2267 SetStdHandle(STD_INPUT_HANDLE
, AttachConsoleRequest
->InputHandle
);
2268 SetStdHandle(STD_OUTPUT_HANDLE
, AttachConsoleRequest
->OutputHandle
);
2269 SetStdHandle(STD_ERROR_HANDLE
, AttachConsoleRequest
->ErrorHandle
);
2271 /* Initialize Console Ctrl Handler */
2272 InitConsoleCtrlHandling();
2274 InputWaitHandle
= AttachConsoleRequest
->InputWaitHandle
;
2280 /*--------------------------------------------------------------
2287 GetConsoleWindow(VOID
)
2289 CONSOLE_API_MESSAGE ApiMessage
;
2290 PCONSOLE_GETWINDOW GetWindowRequest
= &ApiMessage
.Data
.GetWindowRequest
;
2292 GetWindowRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
2294 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2296 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetConsoleWindow
),
2297 sizeof(*GetWindowRequest
));
2298 if (!NT_SUCCESS(ApiMessage
.Status
))
2300 BaseSetLastNTError(ApiMessage
.Status
);
2304 return GetWindowRequest
->WindowHandle
;
2308 /*--------------------------------------------------------------
2315 SetConsoleIcon(HICON hIcon
)
2317 CONSOLE_API_MESSAGE ApiMessage
;
2318 PCONSOLE_SETICON SetIconRequest
= &ApiMessage
.Data
.SetIconRequest
;
2320 SetIconRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
2321 SetIconRequest
->IconHandle
= hIcon
;
2323 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2325 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetIcon
),
2326 sizeof(*SetIconRequest
));
2327 if (!NT_SUCCESS(ApiMessage
.Status
))
2329 BaseSetLastNTError(ApiMessage
.Status
);
2337 /******************************************************************************
2338 * \name SetConsoleInputExeNameW
2339 * \brief Sets the console input file name from a unicode string.
2340 * \param lpInputExeName Pointer to a unicode string with the name.
2341 * \return TRUE if successful, FALSE if unsuccsedful.
2342 * \remarks If lpInputExeName is 0 or the string length is 0 or greater than 255,
2343 * the function fails and sets last error to ERROR_INVALID_PARAMETER.
2347 SetConsoleInputExeNameW(LPCWSTR lpInputExeName
)
2351 if ( !lpInputExeName
||
2352 (lenName
= lstrlenW(lpInputExeName
)) == 0 ||
2353 lenName
> INPUTEXENAME_BUFLEN
- 1 )
2355 /* Fail if string is empty or too long */
2356 SetLastError(ERROR_INVALID_PARAMETER
);
2360 RtlEnterCriticalSection(&ConsoleLock
);
2363 RtlCopyMemory(InputExeName
, lpInputExeName
, lenName
* sizeof(WCHAR
));
2364 InputExeName
[lenName
] = L
'\0';
2368 RtlLeaveCriticalSection(&ConsoleLock
);
2376 /******************************************************************************
2377 * \name SetConsoleInputExeNameA
2378 * \brief Sets the console input file name from an ansi string.
2379 * \param lpInputExeName Pointer to an ansi string with the name.
2380 * \return TRUE if successful, FALSE if unsuccsedful.
2381 * \remarks If lpInputExeName is 0 or the string length is 0 or greater than 255,
2382 * the function fails and sets last error to ERROR_INVALID_PARAMETER.
2386 SetConsoleInputExeNameA(LPCSTR lpInputExeName
)
2388 WCHAR Buffer
[INPUTEXENAME_BUFLEN
];
2389 ANSI_STRING InputExeNameA
;
2390 UNICODE_STRING InputExeNameU
;
2393 RtlInitAnsiString(&InputExeNameA
, lpInputExeName
);
2395 if ( InputExeNameA
.Length
== 0 ||
2396 InputExeNameA
.Length
> INPUTEXENAME_BUFLEN
- 1 )
2398 /* Fail if string is empty or too long */
2399 SetLastError(ERROR_INVALID_PARAMETER
);
2403 InputExeNameU
.Buffer
= Buffer
;
2404 InputExeNameU
.MaximumLength
= sizeof(Buffer
);
2405 InputExeNameU
.Length
= 0;
2407 Status
= RtlAnsiStringToUnicodeString(&InputExeNameU
, &InputExeNameA
, FALSE
);
2408 if (!NT_SUCCESS(Status
))
2410 BaseSetLastNTError(Status
);
2414 return SetConsoleInputExeNameW(InputExeNameU
.Buffer
);
2418 /******************************************************************************
2419 * \name GetConsoleInputExeNameW
2420 * \brief Retrieves the console input file name as unicode string.
2421 * \param nBufferLength Length of the buffer in WCHARs.
2422 * Specify 0 to receive the needed buffer length.
2423 * \param lpBuffer Pointer to a buffer that receives the string.
2424 * \return Needed buffer size if \p nBufferLength is 0.
2425 * Otherwise 1 if successful, 2 if buffer is too small.
2426 * \remarks Sets last error value to ERROR_BUFFER_OVERFLOW if the buffer
2427 * is not big enough.
2431 GetConsoleInputExeNameW(DWORD nBufferLength
, LPWSTR lpBuffer
)
2433 ULONG lenName
= lstrlenW(InputExeName
);
2435 if (nBufferLength
== 0)
2437 /* Buffer size is requested, return it */
2441 if (lenName
+ 1 > nBufferLength
)
2443 /* Buffer is not large enough! */
2444 SetLastError(ERROR_BUFFER_OVERFLOW
);
2448 RtlEnterCriticalSection(&ConsoleLock
);
2451 RtlCopyMemory(lpBuffer
, InputExeName
, lenName
* sizeof(WCHAR
));
2452 lpBuffer
[lenName
] = '\0';
2456 RtlLeaveCriticalSection(&ConsoleLock
);
2460 /* Success, return 1 */
2465 /******************************************************************************
2466 * \name GetConsoleInputExeNameA
2467 * \brief Retrieves the console input file name as ansi string.
2468 * \param nBufferLength Length of the buffer in CHARs.
2469 * \param lpBuffer Pointer to a buffer that receives the string.
2470 * \return 1 if successful, 2 if buffer is too small.
2471 * \remarks Sets last error value to ERROR_BUFFER_OVERFLOW if the buffer
2472 * is not big enough. The buffer receives as much characters as fit.
2476 GetConsoleInputExeNameA(DWORD nBufferLength
, LPSTR lpBuffer
)
2478 WCHAR Buffer
[INPUTEXENAME_BUFLEN
];
2480 UNICODE_STRING BufferU
;
2481 ANSI_STRING BufferA
;
2483 /* Get the unicode name */
2484 Ret
= GetConsoleInputExeNameW(sizeof(Buffer
) / sizeof(Buffer
[0]), Buffer
);
2486 /* Initialize strings for conversion */
2487 RtlInitUnicodeString(&BufferU
, Buffer
);
2489 BufferA
.MaximumLength
= (USHORT
)nBufferLength
;
2490 BufferA
.Buffer
= lpBuffer
;
2492 /* Convert unicode name to ansi, copying as much chars as fit */
2493 RtlUnicodeStringToAnsiString(&BufferA
, &BufferU
, FALSE
);
2495 /* Error handling */
2496 if (nBufferLength
<= BufferU
.Length
/ sizeof(WCHAR
))
2498 SetLastError(ERROR_BUFFER_OVERFLOW
);
2507 GetConsoleCharType(HANDLE hConsole
, COORD Coord
, PDWORD Type
)
2515 GetConsoleCursorMode(HANDLE hConsole
, PBOOL pUnknown1
, PBOOL pUnknown2
)
2523 GetConsoleNlsMode(HANDLE hConsole
, LPDWORD lpMode
)
2531 SetConsoleCursorMode(HANDLE hConsole
, BOOL Unknown1
, BOOL Unknown2
)
2539 SetConsoleLocalEUDC(DWORD Unknown1
, DWORD Unknown2
, DWORD Unknown3
, DWORD Unknown4
)
2547 SetConsoleNlsMode(HANDLE hConsole
, DWORD dwMode
)
2555 RegisterConsoleIME(HWND hWnd
, LPDWORD ThreadId
)
2563 RegisterConsoleOS2(BOOL bUnknown
)
2571 SetConsoleOS2OemFormat(BOOL bUnknown
)
2579 UnregisterConsoleIME(VOID
)
2589 BOOL WINAPI
GetConsoleKeyboardLayoutNameA(LPSTR name
)
2598 BOOL WINAPI
GetConsoleKeyboardLayoutNameW(LPWSTR name
)
2609 SetLastConsoleEventActive(VOID
)
2611 CONSOLE_API_MESSAGE ApiMessage
;
2612 PCONSOLE_NOTIFYLASTCLOSE NotifyLastCloseRequest
= &ApiMessage
.Data
.NotifyLastCloseRequest
;
2614 /* Set the flag used by the console control dispatcher */
2615 LastCloseNotify
= TRUE
;
2617 /* Set up the input arguments */
2618 NotifyLastCloseRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
2620 /* Call CSRSS; just return the NTSTATUS cast to DWORD */
2621 return CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2623 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepNotifyLastClose
),
2624 sizeof(*NotifyLastCloseRequest
));