2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: dll/win32/kernel32/client/console/console.c
5 * PURPOSE: Win32 server console functions
6 * PROGRAMMERS: James Tabor <jimtabor@adsl-64-217-116-74.dsl.hstntx.swbell.net>
7 * Hermes Belusca-Maito (hermes.belusca@sfr.fr)
10 /* INCLUDES *******************************************************************/
18 /* GLOBALS ********************************************************************/
20 extern RTL_CRITICAL_SECTION ConsoleLock
;
21 extern BOOLEAN ConsoleInitialized
;
23 /* Console reserved "file" names */
24 static LPCWSTR BaseConFileName
= CONSOLE_FILE_NAME
;
25 static LPCWSTR BaseConInputFileName
= CONSOLE_INPUT_FILE_NAME
;
26 static LPCWSTR BaseConOutputFileName
= CONSOLE_OUTPUT_FILE_NAME
;
28 /* Console Control handling */
29 static PHANDLER_ROUTINE InitialHandler
[1];
30 static PHANDLER_ROUTINE
* CtrlHandlers
;
31 static ULONG NrCtrlHandlers
;
32 static ULONG NrAllocatedHandlers
;
33 static BOOLEAN LastCloseNotify
= FALSE
;
35 extern BOOL WINAPI
IsDebuggerPresent(VOID
);
37 /* Console Input facilities */
38 HANDLE InputWaitHandle
= INVALID_HANDLE_VALUE
;
40 #define EXENAME_LENGTH 255 + 1
41 static RTL_CRITICAL_SECTION ExeNameLock
;
42 static BOOLEAN ExeNameInitialized
;
43 static WCHAR ExeNameBuffer
[EXENAME_LENGTH
]; // NULL-terminated
44 static USHORT ExeNameLength
; // Count in number of characters without NULL
45 static WCHAR StartDirBuffer
[MAX_PATH
+ 1]; // NULL-terminated
46 static USHORT StartDirLength
; // Count in number of characters without NULL
49 /* Default Console Control Handler ********************************************/
53 DefaultConsoleCtrlHandler(DWORD Event
)
55 DPRINT("Default handler called: %lx\n", Event
);
59 DPRINT("Ctrl-C Event\n");
62 case CTRL_BREAK_EVENT
:
63 DPRINT("Ctrl-Break Event\n");
66 case CTRL_CLOSE_EVENT
:
67 DPRINT("Ctrl Close Event\n");
70 case CTRL_LAST_CLOSE_EVENT
:
71 DPRINT("Ctrl Last Close Event\n");
74 case CTRL_LOGOFF_EVENT
:
75 DPRINT("Ctrl Logoff Event\n");
78 case CTRL_SHUTDOWN_EVENT
:
79 DPRINT("Ctrl Shutdown Event\n");
83 ExitProcess(CONTROL_C_EXIT
);
89 ConsoleControlDispatcher(IN LPVOID lpThreadParameter
)
92 DWORD CodeAndFlag
= PtrToUlong(lpThreadParameter
);
93 DWORD nCode
= CodeAndFlag
& MAXLONG
;
95 EXCEPTION_RECORD erException
;
97 DPRINT1("Console Dispatcher Active: %lx %lx\n", CodeAndFlag
, nCode
);
98 SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST
);
103 case CTRL_BREAK_EVENT
:
105 if (IsDebuggerPresent())
107 erException
.ExceptionCode
= (nCode
== CTRL_C_EVENT
?
108 DBG_CONTROL_C
: DBG_CONTROL_BREAK
);
109 erException
.ExceptionFlags
= 0;
110 erException
.ExceptionRecord
= NULL
;
111 erException
.ExceptionAddress
= DefaultConsoleCtrlHandler
;
112 erException
.NumberParameters
= 0;
116 RtlRaiseException(&erException
);
118 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
120 RtlEnterCriticalSection(&ConsoleLock
);
122 if ((nCode
!= CTRL_C_EVENT
) ||
123 (NtCurrentPeb()->ProcessParameters
->ConsoleFlags
!= 1))
125 for (i
= NrCtrlHandlers
; i
> 0; i
--)
127 if (CtrlHandlers
[i
- 1](nCode
)) break;
131 RtlLeaveCriticalSection(&ConsoleLock
);
140 case CTRL_CLOSE_EVENT
:
141 case CTRL_LOGOFF_EVENT
:
142 case CTRL_SHUTDOWN_EVENT
:
145 case CTRL_LAST_CLOSE_EVENT
:
147 * In case the console app hasn't register for last close notification,
148 * just kill this console handler thread. We don't want that such apps
149 * get killed for unexpected reasons. On the contrary apps that registered
150 * can be killed because they expect to be.
152 if (!LastCloseNotify
) ExitThread(0);
156 ExitProcess(CONTROL_C_EXIT
);
164 ASSERT(ConsoleInitialized
);
166 RtlEnterCriticalSection(&ConsoleLock
);
169 if ((nCode
!= CTRL_C_EVENT
) || (NtCurrentPeb()->ProcessParameters
->ConsoleFlags
!= 1))
171 for (i
= NrCtrlHandlers
; i
> 0; i
--)
174 (CodeAndFlag
& MINLONG
) &&
175 ((nCode
== CTRL_LOGOFF_EVENT
) || (nCode
== CTRL_SHUTDOWN_EVENT
)))
177 DPRINT("Skipping system/service apps\n");
181 if (CtrlHandlers
[i
- 1](nCode
))
185 case CTRL_CLOSE_EVENT
:
186 case CTRL_LAST_CLOSE_EVENT
:
187 case CTRL_LOGOFF_EVENT
:
188 case CTRL_SHUTDOWN_EVENT
:
189 nExitCode
= CodeAndFlag
;
197 RtlLeaveCriticalSection(&ConsoleLock
);
199 ExitThread(nExitCode
);
200 return STATUS_SUCCESS
;
204 InitializeCtrlHandling(VOID
)
206 /* Initialize Console Ctrl Handler */
207 NrAllocatedHandlers
= NrCtrlHandlers
= 1;
208 CtrlHandlers
= InitialHandler
;
209 CtrlHandlers
[0] = DefaultConsoleCtrlHandler
;
213 /* Input EXE Name Support *****************************************************/
219 PPEB Peb
= NtCurrentPeb();
220 PCURDIR CurrentDirectory
= &Peb
->ProcessParameters
->CurrentDirectory
;
221 PLDR_DATA_TABLE_ENTRY ImageEntry
;
223 if (ExeNameInitialized
) return;
225 /* Initialize the EXE name lock */
226 Status
= RtlInitializeCriticalSection(&ExeNameLock
);
227 if (!NT_SUCCESS(Status
)) return;
228 ExeNameInitialized
= TRUE
;
230 ImageEntry
= CONTAINING_RECORD(Peb
->Ldr
->InLoadOrderModuleList
.Flink
,
231 LDR_DATA_TABLE_ENTRY
,
234 /* Retrieve the EXE name, NULL-terminate it... */
235 ExeNameLength
= min(sizeof(ExeNameBuffer
)/sizeof(ExeNameBuffer
[0]),
236 ImageEntry
->BaseDllName
.Length
/ sizeof(WCHAR
));
237 RtlCopyMemory(ExeNameBuffer
,
238 ImageEntry
->BaseDllName
.Buffer
,
239 ImageEntry
->BaseDllName
.Length
);
240 ExeNameBuffer
[ExeNameLength
] = UNICODE_NULL
;
242 /* ... and retrieve the current directory path and NULL-terminate it. */
243 StartDirLength
= min(sizeof(StartDirBuffer
)/sizeof(StartDirBuffer
[0]),
244 CurrentDirectory
->DosPath
.Length
/ sizeof(WCHAR
));
245 RtlCopyMemory(StartDirBuffer
,
246 CurrentDirectory
->DosPath
.Buffer
,
247 CurrentDirectory
->DosPath
.Length
);
248 StartDirBuffer
[StartDirLength
] = UNICODE_NULL
;
253 * The "LPDWORD Length" parameters point on input to the maximum size of
254 * the buffers that can hold data (if != 0), and on output they hold the
255 * real size of the data. If "Length" are == 0 on input, then on output
256 * they receive the full size of the data.
257 * The "LPWSTR* String" parameters have a double meaning:
258 * - when "CaptureStrings" is TRUE, data is copied to the buffers pointed
259 * by the pointers (*String).
260 * - when "CaptureStrings" is FALSE, "*String" are set to the addresses of
264 SetUpAppName(IN BOOLEAN CaptureStrings
,
265 IN OUT LPDWORD CurDirLength
,
266 IN OUT LPWSTR
* CurDir
,
267 IN OUT LPDWORD AppNameLength
,
268 IN OUT LPWSTR
* AppName
)
272 /* Retrieve the needed buffer size */
273 Length
= (StartDirLength
+ 1) * sizeof(WCHAR
);
274 if (*CurDirLength
> 0) Length
= min(Length
, *CurDirLength
);
275 *CurDirLength
= Length
;
277 /* Capture the data if needed, or, return a pointer to it */
281 * Length is always >= sizeof(WCHAR). Copy everything but the
282 * possible trailing NULL character, and then NULL-terminate.
284 Length
-= sizeof(WCHAR
);
285 RtlCopyMemory(*CurDir
, StartDirBuffer
, Length
);
286 (*CurDir
)[Length
/ sizeof(WCHAR
)] = UNICODE_NULL
;
290 *CurDir
= StartDirBuffer
;
293 /* Retrieve the needed buffer size */
294 Length
= (ExeNameLength
+ 1) * sizeof(WCHAR
);
295 if (*AppNameLength
> 0) Length
= min(Length
, *AppNameLength
);
296 *AppNameLength
= Length
;
298 /* Capture the data if needed, or, return a pointer to it */
302 * Length is always >= sizeof(WCHAR). Copy everything but the
303 * possible trailing NULL character, and then NULL-terminate.
305 Length
-= sizeof(WCHAR
);
306 RtlCopyMemory(*AppName
, ExeNameBuffer
, Length
);
307 (*AppName
)[Length
/ sizeof(WCHAR
)] = UNICODE_NULL
;
311 *AppName
= ExeNameBuffer
;
316 GetCurrentExeName(OUT PWCHAR ExeName
,
317 IN USHORT BufferSize
)
321 if (ExeNameInitialized
)
323 RtlEnterCriticalSection(&ExeNameLock
);
325 if (BufferSize
> ExeNameLength
* sizeof(WCHAR
))
326 BufferSize
= ExeNameLength
* sizeof(WCHAR
);
328 RtlCopyMemory(ExeName
, ExeNameBuffer
, BufferSize
);
330 RtlLeaveCriticalSection(&ExeNameLock
);
331 ExeLength
= BufferSize
;
335 *ExeName
= UNICODE_NULL
;
342 /* FUNCTIONS ******************************************************************/
345 IntCheckForConsoleFileName(IN LPCWSTR pszName
,
346 IN DWORD dwDesiredAccess
)
348 LPCWSTR ConsoleName
= pszName
;
349 ULONG DeviceNameInfo
;
352 * Check whether we deal with a DOS device, and if so,
353 * strip the path till the file name.
354 * Therefore, things like \\.\CON or C:\some_path\CONIN$
355 * are transformed into CON or CONIN$, for example.
357 DeviceNameInfo
= RtlIsDosDeviceName_U(pszName
);
358 if (DeviceNameInfo
!= 0)
360 ConsoleName
= (LPCWSTR
)((ULONG_PTR
)ConsoleName
+ ((DeviceNameInfo
>> 16) & 0xFFFF));
363 /* Return a standard console "file" name according to what we passed in parameters */
364 if (_wcsicmp(ConsoleName
, BaseConInputFileName
) == 0)
366 return BaseConInputFileName
;
368 else if (_wcsicmp(ConsoleName
, BaseConOutputFileName
) == 0)
370 return BaseConOutputFileName
;
372 else if (_wcsicmp(ConsoleName
, BaseConFileName
) == 0)
374 if ((dwDesiredAccess
& (GENERIC_READ
| GENERIC_WRITE
)) == GENERIC_READ
)
376 return BaseConInputFileName
;
378 else if ((dwDesiredAccess
& (GENERIC_READ
| GENERIC_WRITE
)) == GENERIC_WRITE
)
380 return BaseConOutputFileName
;
384 /* If we are there, that means that either the file name or the desired access are wrong */
390 * @implemented (Undocumented)
391 * @note See http://undoc.airesoft.co.uk/kernel32.dll/ConsoleMenuControl.php
396 ConsoleMenuControl(HANDLE hConsoleOutput
,
400 CONSOLE_API_MESSAGE ApiMessage
;
401 PCONSOLE_MENUCONTROL MenuControlRequest
= &ApiMessage
.Data
.MenuControlRequest
;
403 MenuControlRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
404 MenuControlRequest
->OutputHandle
= hConsoleOutput
;
405 MenuControlRequest
->CmdIdLow
= dwCmdIdLow
;
406 MenuControlRequest
->CmdIdHigh
= dwCmdIdHigh
;
407 MenuControlRequest
->MenuHandle
= NULL
;
409 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
411 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepMenuControl
),
412 sizeof(*MenuControlRequest
));
414 return MenuControlRequest
->MenuHandle
;
424 DuplicateConsoleHandle(HANDLE hConsole
,
425 DWORD dwDesiredAccess
,
429 CONSOLE_API_MESSAGE ApiMessage
;
430 PCONSOLE_DUPLICATEHANDLE DuplicateHandleRequest
= &ApiMessage
.Data
.DuplicateHandleRequest
;
432 if ( (dwOptions
& ~(DUPLICATE_CLOSE_SOURCE
| DUPLICATE_SAME_ACCESS
)) ||
433 (!(dwOptions
& DUPLICATE_SAME_ACCESS
) &&
434 (dwDesiredAccess
& ~(GENERIC_READ
| GENERIC_WRITE
))) )
436 SetLastError(ERROR_INVALID_PARAMETER
);
437 return INVALID_HANDLE_VALUE
;
440 DuplicateHandleRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
441 DuplicateHandleRequest
->SourceHandle
= hConsole
;
442 DuplicateHandleRequest
->DesiredAccess
= dwDesiredAccess
;
443 DuplicateHandleRequest
->InheritHandle
= bInheritHandle
;
444 DuplicateHandleRequest
->Options
= dwOptions
;
446 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
448 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepDuplicateHandle
),
449 sizeof(*DuplicateHandleRequest
));
450 if (!NT_SUCCESS(ApiMessage
.Status
))
452 BaseSetLastNTError(ApiMessage
.Status
);
453 return INVALID_HANDLE_VALUE
;
456 return DuplicateHandleRequest
->TargetHandle
;
465 GetConsoleHandleInformation(IN HANDLE hHandle
,
466 OUT LPDWORD lpdwFlags
)
468 CONSOLE_API_MESSAGE ApiMessage
;
469 PCONSOLE_GETHANDLEINFO GetHandleInfoRequest
= &ApiMessage
.Data
.GetHandleInfoRequest
;
471 GetHandleInfoRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
472 GetHandleInfoRequest
->Handle
= hHandle
;
474 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
476 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetHandleInformation
),
477 sizeof(*GetHandleInfoRequest
));
478 if (!NT_SUCCESS(ApiMessage
.Status
))
480 BaseSetLastNTError(ApiMessage
.Status
);
484 *lpdwFlags
= GetHandleInfoRequest
->Flags
;
495 SetConsoleHandleInformation(IN HANDLE hHandle
,
499 CONSOLE_API_MESSAGE ApiMessage
;
500 PCONSOLE_SETHANDLEINFO SetHandleInfoRequest
= &ApiMessage
.Data
.SetHandleInfoRequest
;
502 SetHandleInfoRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
503 SetHandleInfoRequest
->Handle
= hHandle
;
504 SetHandleInfoRequest
->Mask
= dwMask
;
505 SetHandleInfoRequest
->Flags
= dwFlags
;
507 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
509 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetHandleInformation
),
510 sizeof(*SetHandleInfoRequest
));
511 if (!NT_SUCCESS(ApiMessage
.Status
))
513 BaseSetLastNTError(ApiMessage
.Status
);
526 GetConsoleDisplayMode(LPDWORD lpModeFlags
)
528 CONSOLE_API_MESSAGE ApiMessage
;
529 PCONSOLE_GETDISPLAYMODE GetDisplayModeRequest
= &ApiMessage
.Data
.GetDisplayModeRequest
;
531 if (lpModeFlags
== NULL
)
533 SetLastError(ERROR_INVALID_PARAMETER
);
537 GetDisplayModeRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
539 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
541 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetDisplayMode
),
542 sizeof(*GetDisplayModeRequest
));
543 if (!NT_SUCCESS(ApiMessage
.Status
))
545 BaseSetLastNTError(ApiMessage
.Status
);
549 *lpModeFlags
= GetDisplayModeRequest
->DisplayMode
; // ModeFlags
556 * @implemented (Undocumented)
557 * @note See http://cboard.cprogramming.com/windows-programming/102187-console-font-size.html
561 GetConsoleFontInfo(IN HANDLE hConsoleOutput
,
562 IN BOOL bMaximumWindow
,
564 OUT PCONSOLE_FONT_INFO lpConsoleFontInfo
)
566 CONSOLE_API_MESSAGE ApiMessage
;
567 PCONSOLE_GETFONTINFO GetFontInfoRequest
= &ApiMessage
.Data
.GetFontInfoRequest
;
568 PCSR_CAPTURE_BUFFER CaptureBuffer
;
570 GetFontInfoRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
571 GetFontInfoRequest
->OutputHandle
= hConsoleOutput
;
572 GetFontInfoRequest
->MaximumWindow
= bMaximumWindow
;
573 GetFontInfoRequest
->NumFonts
= nFontCount
;
575 CaptureBuffer
= CsrAllocateCaptureBuffer(1, nFontCount
* sizeof(CONSOLE_FONT_INFO
));
576 if (CaptureBuffer
== NULL
)
578 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
579 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
583 CsrAllocateMessagePointer(CaptureBuffer
,
584 nFontCount
* sizeof(CONSOLE_FONT_INFO
),
585 (PVOID
*)&GetFontInfoRequest
->FontInfo
);
587 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
589 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetFontInfo
),
590 sizeof(*GetFontInfoRequest
));
591 if (!NT_SUCCESS(ApiMessage
.Status
))
593 BaseSetLastNTError(ApiMessage
.Status
);
597 RtlCopyMemory(lpConsoleFontInfo
,
598 GetFontInfoRequest
->FontInfo
,
599 GetFontInfoRequest
->NumFonts
* sizeof(CONSOLE_FONT_INFO
));
602 CsrFreeCaptureBuffer(CaptureBuffer
);
603 return GetFontInfoRequest
->NumFonts
;
613 GetConsoleFontSize(IN HANDLE hConsoleOutput
,
616 CONSOLE_API_MESSAGE ApiMessage
;
617 PCONSOLE_GETFONTSIZE GetFontSizeRequest
= &ApiMessage
.Data
.GetFontSizeRequest
;
618 COORD Empty
= {0, 0};
620 GetFontSizeRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
621 GetFontSizeRequest
->OutputHandle
= hConsoleOutput
;
622 GetFontSizeRequest
->FontIndex
= nFont
;
624 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
626 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetFontSize
),
627 sizeof(*GetFontSizeRequest
));
628 if (!NT_SUCCESS(ApiMessage
.Status
))
630 BaseSetLastNTError(ApiMessage
.Status
);
634 return GetFontSizeRequest
->FontSize
;
639 * @implemented (Undocumented)
643 GetConsoleHardwareState(HANDLE hConsoleOutput
,
647 CONSOLE_API_MESSAGE ApiMessage
;
648 PCONSOLE_GETSETHWSTATE HardwareStateRequest
= &ApiMessage
.Data
.HardwareStateRequest
;
650 DPRINT1("GetConsoleHardwareState(%lu, 0x%p) UNIMPLEMENTED!\n", Flags
, State
);
652 if (Flags
== NULL
|| State
== NULL
)
654 SetLastError(ERROR_INVALID_PARAMETER
);
658 HardwareStateRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
659 HardwareStateRequest
->OutputHandle
= hConsoleOutput
;
661 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
663 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetHardwareState
),
664 sizeof(*HardwareStateRequest
));
665 if (!NT_SUCCESS(ApiMessage
.Status
))
667 BaseSetLastNTError(ApiMessage
.Status
);
671 *Flags
= HardwareStateRequest
->Flags
;
672 *State
= HardwareStateRequest
->State
;
679 * @implemented (Undocumented)
683 GetConsoleInputWaitHandle(VOID
)
685 return InputWaitHandle
;
694 GetCurrentConsoleFont(IN HANDLE hConsoleOutput
,
695 IN BOOL bMaximumWindow
,
696 OUT PCONSOLE_FONT_INFO lpConsoleCurrentFont
)
698 CONSOLE_API_MESSAGE ApiMessage
;
699 PCONSOLE_GETCURRENTFONT GetCurrentFontRequest
= &ApiMessage
.Data
.GetCurrentFontRequest
;
701 GetCurrentFontRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
702 GetCurrentFontRequest
->OutputHandle
= hConsoleOutput
;
703 GetCurrentFontRequest
->MaximumWindow
= bMaximumWindow
;
705 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
707 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetCurrentFont
),
708 sizeof(*GetCurrentFontRequest
));
709 if (!NT_SUCCESS(ApiMessage
.Status
))
711 BaseSetLastNTError(ApiMessage
.Status
);
715 lpConsoleCurrentFont
->dwFontSize
= GetCurrentFontRequest
->FontSize
;
716 lpConsoleCurrentFont
->nFont
= GetCurrentFontRequest
->FontIndex
;
723 * @implemented (Undocumented)
724 * @note See http://cboard.cprogramming.com/windows-programming/102187-console-font-size.html
729 GetNumberOfConsoleFonts(VOID
)
731 CONSOLE_API_MESSAGE ApiMessage
;
732 PCONSOLE_GETNUMFONTS GetNumFontsRequest
= &ApiMessage
.Data
.GetNumFontsRequest
;
734 GetNumFontsRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
736 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
738 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetNumberOfFonts
),
739 sizeof(*GetNumFontsRequest
));
740 if (!NT_SUCCESS(ApiMessage
.Status
))
742 BaseSetLastNTError(ApiMessage
.Status
);
746 return GetNumFontsRequest
->NumFonts
;
751 * @implemented (Undocumented)
752 * @note See http://blog.airesoft.co.uk/2012/10/things-ms-can-do-that-they-dont-tell-you-about-console-graphics/
756 InvalidateConsoleDIBits(IN HANDLE hConsoleOutput
,
757 IN PSMALL_RECT lpRect
)
759 CONSOLE_API_MESSAGE ApiMessage
;
760 PCONSOLE_INVALIDATEDIBITS InvalidateDIBitsRequest
= &ApiMessage
.Data
.InvalidateDIBitsRequest
;
764 SetLastError(ERROR_INVALID_PARAMETER
);
768 InvalidateDIBitsRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
769 InvalidateDIBitsRequest
->OutputHandle
= hConsoleOutput
;
770 InvalidateDIBitsRequest
->Region
= *lpRect
;
772 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
774 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepInvalidateBitMapRect
),
775 sizeof(*InvalidateDIBitsRequest
));
776 if (!NT_SUCCESS(ApiMessage
.Status
))
778 BaseSetLastNTError(ApiMessage
.Status
);
787 * @implemented (Undocumented)
791 OpenConsoleW(LPCWSTR wsName
,
792 DWORD dwDesiredAccess
,
796 CONSOLE_API_MESSAGE ApiMessage
;
797 PCONSOLE_OPENCONSOLE OpenConsoleRequest
= &ApiMessage
.Data
.OpenConsoleRequest
;
798 CONSOLE_HANDLE_TYPE HandleType
;
800 if (wsName
&& (_wcsicmp(wsName
, BaseConInputFileName
) == 0))
802 HandleType
= HANDLE_INPUT
;
804 else if (wsName
&& (_wcsicmp(wsName
, BaseConOutputFileName
) == 0))
806 HandleType
= HANDLE_OUTPUT
;
810 SetLastError(ERROR_INVALID_PARAMETER
);
811 return INVALID_HANDLE_VALUE
;
814 if ( (dwDesiredAccess
& ~(GENERIC_READ
| GENERIC_WRITE
)) ||
815 (dwShareMode
& ~(FILE_SHARE_READ
| FILE_SHARE_WRITE
)) )
817 SetLastError(ERROR_INVALID_PARAMETER
);
818 return INVALID_HANDLE_VALUE
;
821 OpenConsoleRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
822 OpenConsoleRequest
->HandleType
= HandleType
;
823 OpenConsoleRequest
->DesiredAccess
= dwDesiredAccess
;
824 OpenConsoleRequest
->InheritHandle
= bInheritHandle
;
825 OpenConsoleRequest
->ShareMode
= dwShareMode
;
827 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
829 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepOpenConsole
),
830 sizeof(*OpenConsoleRequest
));
831 if (!NT_SUCCESS(ApiMessage
.Status
))
833 BaseSetLastNTError(ApiMessage
.Status
);
834 return INVALID_HANDLE_VALUE
;
837 return OpenConsoleRequest
->Handle
;
842 * @implemented (Undocumented)
843 * @note See http://undoc.airesoft.co.uk/kernel32.dll/SetConsoleCursor.php
848 SetConsoleCursor(HANDLE hConsoleOutput
,
851 CONSOLE_API_MESSAGE ApiMessage
;
852 PCONSOLE_SETCURSOR SetCursorRequest
= &ApiMessage
.Data
.SetCursorRequest
;
854 SetCursorRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
855 SetCursorRequest
->OutputHandle
= hConsoleOutput
;
856 SetCursorRequest
->CursorHandle
= hCursor
;
858 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
860 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetCursor
),
861 sizeof(*SetCursorRequest
));
862 if (!NT_SUCCESS(ApiMessage
.Status
))
864 BaseSetLastNTError(ApiMessage
.Status
);
877 SetConsoleDisplayMode(HANDLE hConsoleOutput
,
878 DWORD dwFlags
, // dwModeFlags
879 PCOORD lpNewScreenBufferDimensions
)
881 CONSOLE_API_MESSAGE ApiMessage
;
882 PCONSOLE_SETDISPLAYMODE SetDisplayModeRequest
= &ApiMessage
.Data
.SetDisplayModeRequest
;
884 SetDisplayModeRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
885 SetDisplayModeRequest
->OutputHandle
= hConsoleOutput
;
886 SetDisplayModeRequest
->DisplayMode
= dwFlags
; // ModeFlags ; dwModeFlags
887 SetDisplayModeRequest
->NewSBDim
.X
= 0;
888 SetDisplayModeRequest
->NewSBDim
.Y
= 0;
889 /* SetDisplayModeRequest->EventHandle; */
891 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
893 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetDisplayMode
),
894 sizeof(*SetDisplayModeRequest
));
895 if (!NT_SUCCESS(ApiMessage
.Status
))
897 BaseSetLastNTError(ApiMessage
.Status
);
901 if (lpNewScreenBufferDimensions
)
902 *lpNewScreenBufferDimensions
= SetDisplayModeRequest
->NewSBDim
;
909 * @implemented (Undocumented)
910 * @note See http://cboard.cprogramming.com/windows-programming/102187-console-font-size.html
915 SetConsoleFont(IN HANDLE hConsoleOutput
,
918 CONSOLE_API_MESSAGE ApiMessage
;
919 PCONSOLE_SETFONT SetFontRequest
= &ApiMessage
.Data
.SetFontRequest
;
921 SetFontRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
922 SetFontRequest
->OutputHandle
= hConsoleOutput
;
923 SetFontRequest
->FontIndex
= nFont
;
925 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
927 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetFont
),
928 sizeof(*SetFontRequest
));
929 if (!NT_SUCCESS(ApiMessage
.Status
))
931 BaseSetLastNTError(ApiMessage
.Status
);
940 * @implemented (Undocumented)
944 SetConsoleHardwareState(HANDLE hConsoleOutput
,
948 CONSOLE_API_MESSAGE ApiMessage
;
949 PCONSOLE_GETSETHWSTATE HardwareStateRequest
= &ApiMessage
.Data
.HardwareStateRequest
;
951 DPRINT1("SetConsoleHardwareState(%lu, %lu) UNIMPLEMENTED!\n", Flags
, State
);
953 HardwareStateRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
954 HardwareStateRequest
->OutputHandle
= hConsoleOutput
;
955 HardwareStateRequest
->Flags
= Flags
;
956 HardwareStateRequest
->State
= State
;
958 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
960 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetHardwareState
),
961 sizeof(*HardwareStateRequest
));
962 if (!NT_SUCCESS(ApiMessage
.Status
))
964 BaseSetLastNTError(ApiMessage
.Status
);
973 * @unimplemented (Undocumented)
978 SetConsoleKeyShortcuts(DWORD Unknown0
,
983 DPRINT1("SetConsoleKeyShortcuts(0x%x, 0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
, Unknown2
, Unknown3
);
984 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
990 * @implemented (Undocumented)
991 * @note See http://undoc.airesoft.co.uk/kernel32.dll/SetConsoleMaximumWindowSize.php
992 * Does nothing, returns TRUE only. Checked on Windows Server 2003.
996 SetConsoleMaximumWindowSize(HANDLE hConsoleOutput
,
999 DPRINT1("SetConsoleMaximumWindowSize(0x%p, {%d, %d}) does nothing\n",
1000 hConsoleOutput
, dwMaximumSize
.X
, dwMaximumSize
.Y
);
1006 * @implemented (Undocumented)
1011 SetConsoleMenuClose(BOOL bEnable
)
1013 CONSOLE_API_MESSAGE ApiMessage
;
1014 PCONSOLE_SETMENUCLOSE SetMenuCloseRequest
= &ApiMessage
.Data
.SetMenuCloseRequest
;
1016 SetMenuCloseRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1017 SetMenuCloseRequest
->Enable
= bEnable
;
1019 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1021 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetMenuClose
),
1022 sizeof(*SetMenuCloseRequest
));
1023 if (!NT_SUCCESS(ApiMessage
.Status
))
1025 BaseSetLastNTError(ApiMessage
.Status
);
1034 * @implemented (Undocumented)
1035 * @note See http://comments.gmane.org/gmane.comp.lang.harbour.devel/27844
1036 * Usage example: https://github.com/harbour/core/commit/d79a1b7b812cbde6ddf718ebfd6939a24f633e52
1041 SetConsolePalette(HANDLE hConsoleOutput
,
1045 CONSOLE_API_MESSAGE ApiMessage
;
1046 PCONSOLE_SETPALETTE SetPaletteRequest
= &ApiMessage
.Data
.SetPaletteRequest
;
1048 SetPaletteRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1049 SetPaletteRequest
->OutputHandle
= hConsoleOutput
;
1050 SetPaletteRequest
->PaletteHandle
= hPalette
;
1051 SetPaletteRequest
->Usage
= dwUsage
;
1053 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1055 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetPalette
),
1056 sizeof(*SetPaletteRequest
));
1057 if (!NT_SUCCESS(ApiMessage
.Status
))
1059 BaseSetLastNTError(ApiMessage
.Status
);
1067 * @implemented (Undocumented)
1068 * @note See http://undoc.airesoft.co.uk/kernel32.dll/ShowConsoleCursor.php
1073 ShowConsoleCursor(HANDLE hConsoleOutput
,
1076 CONSOLE_API_MESSAGE ApiMessage
;
1077 PCONSOLE_SHOWCURSOR ShowCursorRequest
= &ApiMessage
.Data
.ShowCursorRequest
;
1079 ShowCursorRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1080 ShowCursorRequest
->OutputHandle
= hConsoleOutput
;
1081 ShowCursorRequest
->Show
= bShow
;
1082 ShowCursorRequest
->RefCount
= 0;
1084 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1086 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepShowCursor
),
1087 sizeof(*ShowCursorRequest
));
1089 return ShowCursorRequest
->RefCount
;
1094 * FUNCTION: Checks whether the given handle is a valid console handle.
1097 * hIoHandle - Handle to be checked.
1100 * TRUE : Handle is a valid console handle.
1101 * FALSE: Handle is not a valid console handle.
1103 * STATUS: Officially undocumented
1110 VerifyConsoleIoHandle(HANDLE hIoHandle
)
1112 CONSOLE_API_MESSAGE ApiMessage
;
1113 PCONSOLE_VERIFYHANDLE VerifyHandleRequest
= &ApiMessage
.Data
.VerifyHandleRequest
;
1115 VerifyHandleRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1116 VerifyHandleRequest
->Handle
= hIoHandle
;
1117 VerifyHandleRequest
->IsValid
= FALSE
;
1119 /* If the process is not attached to a console, return invalid handle */
1120 if (VerifyHandleRequest
->ConsoleHandle
== NULL
) return FALSE
;
1122 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1124 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepVerifyIoHandle
),
1125 sizeof(*VerifyHandleRequest
));
1126 if (!NT_SUCCESS(ApiMessage
.Status
))
1128 BaseSetLastNTError(ApiMessage
.Status
);
1132 return VerifyHandleRequest
->IsValid
;
1137 * @implemented (Undocumented)
1142 CloseConsoleHandle(HANDLE hHandle
)
1144 CONSOLE_API_MESSAGE ApiMessage
;
1145 PCONSOLE_CLOSEHANDLE CloseHandleRequest
= &ApiMessage
.Data
.CloseHandleRequest
;
1147 CloseHandleRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1148 CloseHandleRequest
->Handle
= hHandle
;
1150 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1152 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepCloseHandle
),
1153 sizeof(*CloseHandleRequest
));
1154 if (!NT_SUCCESS(ApiMessage
.Status
))
1156 BaseSetLastNTError(ApiMessage
.Status
);
1170 GetStdHandle(DWORD nStdHandle
)
1172 * FUNCTION: Get a handle for the standard input, standard output
1173 * and a standard error device.
1176 * nStdHandle - Specifies the device for which to return the handle.
1178 * RETURNS: If the function succeeds, the return value is the handle
1179 * of the specified device. Otherwise the value is INVALID_HANDLE_VALUE.
1182 PRTL_USER_PROCESS_PARAMETERS Ppb
= NtCurrentPeb()->ProcessParameters
;
1183 HANDLE Handle
= INVALID_HANDLE_VALUE
;
1187 case STD_INPUT_HANDLE
:
1188 Handle
= Ppb
->StandardInput
;
1191 case STD_OUTPUT_HANDLE
:
1192 Handle
= Ppb
->StandardOutput
;
1195 case STD_ERROR_HANDLE
:
1196 Handle
= Ppb
->StandardError
;
1200 /* If the returned handle is invalid, set last error */
1201 if (Handle
== INVALID_HANDLE_VALUE
) SetLastError(ERROR_INVALID_HANDLE
);
1213 SetStdHandle(DWORD nStdHandle
,
1216 * FUNCTION: Set the handle for the standard input, standard output or
1217 * the standard error device.
1220 * nStdHandle - Specifies the handle to be set.
1221 * hHandle - The handle to set.
1223 * RETURNS: TRUE if the function succeeds, FALSE otherwise.
1226 PRTL_USER_PROCESS_PARAMETERS Ppb
= NtCurrentPeb()->ProcessParameters
;
1228 /* No need to check if hHandle == INVALID_HANDLE_VALUE */
1232 case STD_INPUT_HANDLE
:
1233 Ppb
->StandardInput
= hHandle
;
1236 case STD_OUTPUT_HANDLE
:
1237 Ppb
->StandardOutput
= hHandle
;
1240 case STD_ERROR_HANDLE
:
1241 Ppb
->StandardError
= hHandle
;
1245 /* nStdHandle was invalid, bail out */
1246 SetLastError(ERROR_INVALID_HANDLE
);
1255 IntAllocConsole(LPWSTR Title
,
1258 DWORD DesktopLength
,
1262 DWORD AppNameLength
,
1263 LPTHREAD_START_ROUTINE CtrlRoutine
,
1264 LPTHREAD_START_ROUTINE PropRoutine
,
1265 PCONSOLE_START_INFO ConsoleStartInfo
)
1267 BOOL Success
= TRUE
;
1270 CONSOLE_API_MESSAGE ApiMessage
;
1271 PCONSOLE_ALLOCCONSOLE AllocConsoleRequest
= &ApiMessage
.Data
.AllocConsoleRequest
;
1272 PCSR_CAPTURE_BUFFER CaptureBuffer
;
1274 AllocConsoleRequest
->CtrlRoutine
= CtrlRoutine
;
1275 AllocConsoleRequest
->PropRoutine
= PropRoutine
;
1277 CaptureBuffer
= CsrAllocateCaptureBuffer(5, TitleLength
+
1281 sizeof(CONSOLE_START_INFO
));
1282 if (CaptureBuffer
== NULL
)
1284 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1289 CsrCaptureMessageBuffer(CaptureBuffer
,
1291 sizeof(CONSOLE_START_INFO
),
1292 (PVOID
*)&AllocConsoleRequest
->ConsoleStartInfo
);
1294 AllocConsoleRequest
->TitleLength
= TitleLength
;
1295 CsrCaptureMessageBuffer(CaptureBuffer
,
1298 (PVOID
*)&AllocConsoleRequest
->ConsoleTitle
);
1300 AllocConsoleRequest
->DesktopLength
= DesktopLength
;
1301 CsrCaptureMessageBuffer(CaptureBuffer
,
1304 (PVOID
*)&AllocConsoleRequest
->Desktop
);
1306 AllocConsoleRequest
->CurDirLength
= CurDirLength
;
1307 CsrCaptureMessageBuffer(CaptureBuffer
,
1310 (PVOID
*)&AllocConsoleRequest
->CurDir
);
1312 AllocConsoleRequest
->AppNameLength
= AppNameLength
;
1313 CsrCaptureMessageBuffer(CaptureBuffer
,
1316 (PVOID
*)&AllocConsoleRequest
->AppName
);
1318 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1320 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepAlloc
),
1321 sizeof(*AllocConsoleRequest
));
1322 if (!NT_SUCCESS(ApiMessage
.Status
))
1324 BaseSetLastNTError(ApiMessage
.Status
);
1329 // Is AllocConsoleRequest->ConsoleStartInfo->InitEvents aligned on handle boundary ????
1330 Status
= NtWaitForMultipleObjects(MAX_INIT_EVENTS
,
1331 AllocConsoleRequest
->ConsoleStartInfo
->InitEvents
,
1332 WaitAny
, FALSE
, NULL
);
1333 if (!NT_SUCCESS(Status
))
1335 BaseSetLastNTError(Status
);
1340 NtClose(AllocConsoleRequest
->ConsoleStartInfo
->InitEvents
[INIT_SUCCESS
]);
1341 NtClose(AllocConsoleRequest
->ConsoleStartInfo
->InitEvents
[INIT_FAILURE
]);
1342 if (Status
!= INIT_SUCCESS
)
1344 NtCurrentPeb()->ProcessParameters
->ConsoleHandle
= NULL
;
1349 RtlCopyMemory(ConsoleStartInfo
,
1350 AllocConsoleRequest
->ConsoleStartInfo
,
1351 sizeof(CONSOLE_START_INFO
));
1356 if (CaptureBuffer
) CsrFreeCaptureBuffer(CaptureBuffer
);
1366 CONSOLE_START_INFO ConsoleStartInfo
;
1368 PWCHAR ConsoleTitle
;
1373 ULONG TitleLength
= (MAX_PATH
+ 1) * sizeof(WCHAR
);
1374 ULONG DesktopLength
= (MAX_PATH
+ 1) * sizeof(WCHAR
);
1375 ULONG AppNameLength
= 128 * sizeof(WCHAR
);
1376 ULONG CurDirLength
= (MAX_PATH
+ 1) * sizeof(WCHAR
);
1380 RtlEnterCriticalSection(&ConsoleLock
);
1382 if (NtCurrentPeb()->ProcessParameters
->ConsoleHandle
)
1384 DPRINT1("AllocConsole: Allocating a console to a process already having one\n");
1385 SetLastError(ERROR_ACCESS_DENIED
);
1390 /* Set up the console properties */
1391 SetUpConsoleInfo(FALSE
,
1397 DPRINT("ConsoleTitle = '%S' - Desktop = '%S'\n",
1398 ConsoleTitle
, Desktop
);
1400 /* Initialize the Input EXE name */
1407 DPRINT("CurDir = '%S' - AppName = '%S'\n",
1410 Success
= IntAllocConsole(ConsoleTitle
,
1418 ConsoleControlDispatcher
,
1423 /* Set up the handles */
1424 SetUpHandles(&ConsoleStartInfo
);
1425 InputWaitHandle
= ConsoleStartInfo
.InputWaitHandle
;
1427 /* Initialize Console Ctrl Handling */
1428 InitializeCtrlHandling();
1430 /* Sets the current console locale for this thread */
1435 RtlLeaveCriticalSection(&ConsoleLock
);
1448 BOOL Success
= TRUE
;
1449 CONSOLE_API_MESSAGE ApiMessage
;
1450 PCONSOLE_FREECONSOLE FreeConsoleRequest
= &ApiMessage
.Data
.FreeConsoleRequest
;
1451 HANDLE ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1453 RtlEnterCriticalSection(&ConsoleLock
);
1455 /* We must have a non-trivial handle to close */
1456 if (ConsoleHandle
== NULL
) // IsConsoleHandle(ConsoleHandle)
1458 SetLastError(ERROR_INVALID_PARAMETER
);
1463 /* Set up the data to send to the Console Server */
1464 FreeConsoleRequest
->ConsoleHandle
= ConsoleHandle
;
1466 /* Call the server */
1467 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1469 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepFree
),
1470 sizeof(*FreeConsoleRequest
));
1472 /* Check for success */
1473 if (!NT_SUCCESS(ApiMessage
.Status
))
1475 BaseSetLastNTError(ApiMessage
.Status
);
1480 /* Reset the console handle */
1481 NtCurrentPeb()->ProcessParameters
->ConsoleHandle
= NULL
;
1483 /* Close the associated input handle */
1484 CloseHandle(InputWaitHandle
);
1485 InputWaitHandle
= INVALID_HANDLE_VALUE
;
1488 RtlLeaveCriticalSection(&ConsoleLock
);
1498 GetConsoleScreenBufferInfo(HANDLE hConsoleOutput
,
1499 PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo
)
1501 CONSOLE_API_MESSAGE ApiMessage
;
1502 PCONSOLE_GETSCREENBUFFERINFO ScreenBufferInfoRequest
= &ApiMessage
.Data
.ScreenBufferInfoRequest
;
1504 if (lpConsoleScreenBufferInfo
== NULL
)
1506 SetLastError(ERROR_INVALID_PARAMETER
);
1510 ScreenBufferInfoRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1511 ScreenBufferInfoRequest
->OutputHandle
= hConsoleOutput
;
1513 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1515 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetScreenBufferInfo
),
1516 sizeof(*ScreenBufferInfoRequest
));
1517 if (!NT_SUCCESS(ApiMessage
.Status
))
1519 BaseSetLastNTError(ApiMessage
.Status
);
1523 lpConsoleScreenBufferInfo
->dwSize
= ScreenBufferInfoRequest
->ScreenBufferSize
;
1524 lpConsoleScreenBufferInfo
->dwCursorPosition
= ScreenBufferInfoRequest
->CursorPosition
;
1525 lpConsoleScreenBufferInfo
->wAttributes
= ScreenBufferInfoRequest
->Attributes
;
1526 lpConsoleScreenBufferInfo
->srWindow
.Left
= ScreenBufferInfoRequest
->ViewOrigin
.X
;
1527 lpConsoleScreenBufferInfo
->srWindow
.Top
= ScreenBufferInfoRequest
->ViewOrigin
.Y
;
1528 lpConsoleScreenBufferInfo
->srWindow
.Right
= ScreenBufferInfoRequest
->ViewOrigin
.X
+ ScreenBufferInfoRequest
->ViewSize
.X
- 1;
1529 lpConsoleScreenBufferInfo
->srWindow
.Bottom
= ScreenBufferInfoRequest
->ViewOrigin
.Y
+ ScreenBufferInfoRequest
->ViewSize
.Y
- 1;
1530 lpConsoleScreenBufferInfo
->dwMaximumWindowSize
= ScreenBufferInfoRequest
->MaximumViewSize
;
1542 SetConsoleCursorPosition(HANDLE hConsoleOutput
,
1543 COORD dwCursorPosition
)
1545 CONSOLE_API_MESSAGE ApiMessage
;
1546 PCONSOLE_SETCURSORPOSITION SetCursorPositionRequest
= &ApiMessage
.Data
.SetCursorPositionRequest
;
1548 SetCursorPositionRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1549 SetCursorPositionRequest
->OutputHandle
= hConsoleOutput
;
1550 SetCursorPositionRequest
->Position
= dwCursorPosition
;
1552 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1554 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetCursorPosition
),
1555 sizeof(*SetCursorPositionRequest
));
1556 if (!NT_SUCCESS(ApiMessage
.Status
))
1558 BaseSetLastNTError(ApiMessage
.Status
);
1571 GetConsoleMode(HANDLE hConsoleHandle
,
1574 CONSOLE_API_MESSAGE ApiMessage
;
1575 PCONSOLE_GETSETCONSOLEMODE ConsoleModeRequest
= &ApiMessage
.Data
.ConsoleModeRequest
;
1579 SetLastError(ERROR_INVALID_PARAMETER
);
1583 ConsoleModeRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1584 ConsoleModeRequest
->Handle
= hConsoleHandle
;
1586 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1588 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetMode
),
1589 sizeof(*ConsoleModeRequest
));
1590 if (!NT_SUCCESS(ApiMessage
.Status
))
1592 BaseSetLastNTError(ApiMessage
.Status
);
1596 *lpMode
= ConsoleModeRequest
->Mode
;
1608 SetConsoleMode(HANDLE hConsoleHandle
,
1611 CONSOLE_API_MESSAGE ApiMessage
;
1612 PCONSOLE_GETSETCONSOLEMODE ConsoleModeRequest
= &ApiMessage
.Data
.ConsoleModeRequest
;
1614 ConsoleModeRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1615 ConsoleModeRequest
->Handle
= hConsoleHandle
;
1616 ConsoleModeRequest
->Mode
= dwMode
;
1618 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1620 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetMode
),
1621 sizeof(*ConsoleModeRequest
));
1622 if (!NT_SUCCESS(ApiMessage
.Status
))
1624 BaseSetLastNTError(ApiMessage
.Status
);
1637 GetNumberOfConsoleInputEvents(HANDLE hConsoleInput
,
1638 LPDWORD lpNumberOfEvents
)
1640 CONSOLE_API_MESSAGE ApiMessage
;
1641 PCONSOLE_GETNUMINPUTEVENTS GetNumInputEventsRequest
= &ApiMessage
.Data
.GetNumInputEventsRequest
;
1643 GetNumInputEventsRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1644 GetNumInputEventsRequest
->InputHandle
= hConsoleInput
;
1645 GetNumInputEventsRequest
->NumberOfEvents
= 0;
1647 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1649 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetNumberOfInputEvents
),
1650 sizeof(*GetNumInputEventsRequest
));
1651 if (!NT_SUCCESS(ApiMessage
.Status
))
1653 BaseSetLastNTError(ApiMessage
.Status
);
1657 if (lpNumberOfEvents
== NULL
)
1659 SetLastError(ERROR_INVALID_ACCESS
);
1663 *lpNumberOfEvents
= GetNumInputEventsRequest
->NumberOfEvents
;
1675 GetLargestConsoleWindowSize(HANDLE hConsoleOutput
)
1677 CONSOLE_API_MESSAGE ApiMessage
;
1678 PCONSOLE_GETLARGESTWINDOWSIZE GetLargestWindowSizeRequest
= &ApiMessage
.Data
.GetLargestWindowSizeRequest
;
1680 GetLargestWindowSizeRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1681 GetLargestWindowSizeRequest
->OutputHandle
= hConsoleOutput
;
1682 GetLargestWindowSizeRequest
->Size
.X
= 0;
1683 GetLargestWindowSizeRequest
->Size
.Y
= 0;
1685 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1687 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetLargestWindowSize
),
1688 sizeof(*GetLargestWindowSizeRequest
));
1689 if (!NT_SUCCESS(ApiMessage
.Status
))
1691 BaseSetLastNTError(ApiMessage
.Status
);
1694 DPRINT("GetLargestConsoleWindowSize, X = %d, Y = %d\n", GetLargestWindowSizeRequest
->Size
.X
, GetLargestWindowSizeRequest
->Size
.Y
);
1695 return GetLargestWindowSizeRequest
->Size
;
1704 GetConsoleCursorInfo(HANDLE hConsoleOutput
,
1705 PCONSOLE_CURSOR_INFO lpConsoleCursorInfo
)
1707 CONSOLE_API_MESSAGE ApiMessage
;
1708 PCONSOLE_GETSETCURSORINFO CursorInfoRequest
= &ApiMessage
.Data
.CursorInfoRequest
;
1710 if (!lpConsoleCursorInfo
)
1712 if (!hConsoleOutput
)
1713 SetLastError(ERROR_INVALID_HANDLE
);
1715 SetLastError(ERROR_INVALID_ACCESS
);
1720 CursorInfoRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1721 CursorInfoRequest
->OutputHandle
= hConsoleOutput
;
1723 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1725 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetCursorInfo
),
1726 sizeof(*CursorInfoRequest
));
1727 if (!NT_SUCCESS(ApiMessage
.Status
))
1729 BaseSetLastNTError(ApiMessage
.Status
);
1733 *lpConsoleCursorInfo
= CursorInfoRequest
->Info
;
1744 SetConsoleCursorInfo(HANDLE hConsoleOutput
,
1745 CONST CONSOLE_CURSOR_INFO
*lpConsoleCursorInfo
)
1747 CONSOLE_API_MESSAGE ApiMessage
;
1748 PCONSOLE_GETSETCURSORINFO CursorInfoRequest
= &ApiMessage
.Data
.CursorInfoRequest
;
1750 CursorInfoRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1751 CursorInfoRequest
->OutputHandle
= hConsoleOutput
;
1752 CursorInfoRequest
->Info
= *lpConsoleCursorInfo
;
1754 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1756 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetCursorInfo
),
1757 sizeof(*CursorInfoRequest
));
1758 if (!NT_SUCCESS(ApiMessage
.Status
))
1760 BaseSetLastNTError(ApiMessage
.Status
);
1773 GetNumberOfConsoleMouseButtons(LPDWORD lpNumberOfMouseButtons
)
1775 CONSOLE_API_MESSAGE ApiMessage
;
1776 PCONSOLE_GETMOUSEINFO GetMouseInfoRequest
= &ApiMessage
.Data
.GetMouseInfoRequest
;
1778 GetMouseInfoRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1780 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1782 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetMouseInfo
),
1783 sizeof(*GetMouseInfoRequest
));
1784 if (!NT_SUCCESS(ApiMessage
.Status
))
1786 BaseSetLastNTError(ApiMessage
.Status
);
1790 *lpNumberOfMouseButtons
= GetMouseInfoRequest
->NumButtons
;
1801 SetConsoleActiveScreenBuffer(HANDLE hConsoleOutput
)
1803 CONSOLE_API_MESSAGE ApiMessage
;
1804 PCONSOLE_SETACTIVESCREENBUFFER SetScreenBufferRequest
= &ApiMessage
.Data
.SetScreenBufferRequest
;
1806 SetScreenBufferRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1807 SetScreenBufferRequest
->OutputHandle
= hConsoleOutput
;
1809 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1811 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetActiveScreenBuffer
),
1812 sizeof(*SetScreenBufferRequest
));
1813 if (!NT_SUCCESS(ApiMessage
.Status
))
1815 BaseSetLastNTError(ApiMessage
.Status
);
1829 FlushConsoleInputBuffer(HANDLE hConsoleInput
)
1831 CONSOLE_API_MESSAGE ApiMessage
;
1832 PCONSOLE_FLUSHINPUTBUFFER FlushInputBufferRequest
= &ApiMessage
.Data
.FlushInputBufferRequest
;
1834 FlushInputBufferRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1835 FlushInputBufferRequest
->InputHandle
= hConsoleInput
;
1837 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1839 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepFlushInputBuffer
),
1840 sizeof(*FlushInputBufferRequest
));
1841 if (!NT_SUCCESS(ApiMessage
.Status
))
1843 BaseSetLastNTError(ApiMessage
.Status
);
1857 SetConsoleScreenBufferSize(HANDLE hConsoleOutput
,
1860 CONSOLE_API_MESSAGE ApiMessage
;
1861 PCONSOLE_SETSCREENBUFFERSIZE SetScreenBufferSizeRequest
= &ApiMessage
.Data
.SetScreenBufferSizeRequest
;
1863 SetScreenBufferSizeRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1864 SetScreenBufferSizeRequest
->OutputHandle
= hConsoleOutput
;
1865 SetScreenBufferSizeRequest
->Size
= dwSize
;
1867 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1869 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetScreenBufferSize
),
1870 sizeof(*SetScreenBufferSizeRequest
));
1871 if (!NT_SUCCESS(ApiMessage
.Status
))
1873 BaseSetLastNTError(ApiMessage
.Status
);
1883 IntScrollConsoleScreenBuffer(HANDLE hConsoleOutput
,
1884 CONST SMALL_RECT
* lpScrollRectangle
,
1885 CONST SMALL_RECT
* lpClipRectangle
,
1886 COORD dwDestinationOrigin
,
1887 CONST CHAR_INFO
* lpFill
,
1890 CONSOLE_API_MESSAGE ApiMessage
;
1891 PCONSOLE_SCROLLSCREENBUFFER ScrollScreenBufferRequest
= &ApiMessage
.Data
.ScrollScreenBufferRequest
;
1893 ScrollScreenBufferRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1894 ScrollScreenBufferRequest
->OutputHandle
= hConsoleOutput
;
1895 ScrollScreenBufferRequest
->ScrollRectangle
= *lpScrollRectangle
;
1897 if (lpClipRectangle
!= NULL
)
1899 ScrollScreenBufferRequest
->UseClipRectangle
= TRUE
;
1900 ScrollScreenBufferRequest
->ClipRectangle
= *lpClipRectangle
;
1904 ScrollScreenBufferRequest
->UseClipRectangle
= FALSE
;
1907 ScrollScreenBufferRequest
->DestinationOrigin
= dwDestinationOrigin
;
1908 ScrollScreenBufferRequest
->Fill
= *lpFill
;
1909 ScrollScreenBufferRequest
->Unicode
= bUnicode
;
1911 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1913 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepScrollScreenBuffer
),
1914 sizeof(*ScrollScreenBufferRequest
));
1915 if (!NT_SUCCESS(ApiMessage
.Status
))
1917 BaseSetLastNTError(ApiMessage
.Status
);
1931 ScrollConsoleScreenBufferA(HANDLE hConsoleOutput
,
1932 CONST SMALL_RECT
* lpScrollRectangle
,
1933 CONST SMALL_RECT
* lpClipRectangle
,
1934 COORD dwDestinationOrigin
,
1935 CONST CHAR_INFO
* lpFill
)
1937 return IntScrollConsoleScreenBuffer(hConsoleOutput
,
1940 dwDestinationOrigin
,
1952 ScrollConsoleScreenBufferW(HANDLE hConsoleOutput
,
1953 CONST SMALL_RECT
*lpScrollRectangle
,
1954 CONST SMALL_RECT
*lpClipRectangle
,
1955 COORD dwDestinationOrigin
,
1956 CONST CHAR_INFO
*lpFill
)
1958 return IntScrollConsoleScreenBuffer(hConsoleOutput
,
1961 dwDestinationOrigin
,
1972 SetConsoleWindowInfo(HANDLE hConsoleOutput
,
1974 CONST SMALL_RECT
*lpConsoleWindow
)
1976 CONSOLE_API_MESSAGE ApiMessage
;
1977 PCONSOLE_SETWINDOWINFO SetWindowInfoRequest
= &ApiMessage
.Data
.SetWindowInfoRequest
;
1979 if (lpConsoleWindow
== NULL
)
1981 SetLastError(ERROR_INVALID_PARAMETER
);
1985 SetWindowInfoRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1986 SetWindowInfoRequest
->OutputHandle
= hConsoleOutput
;
1987 SetWindowInfoRequest
->Absolute
= bAbsolute
;
1988 SetWindowInfoRequest
->WindowRect
= *lpConsoleWindow
;
1990 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1992 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetWindowInfo
),
1993 sizeof(*SetWindowInfoRequest
));
1994 if (!NT_SUCCESS(ApiMessage
.Status
))
1996 BaseSetLastNTError(ApiMessage
.Status
);
2010 SetConsoleTextAttribute(HANDLE hConsoleOutput
,
2013 CONSOLE_API_MESSAGE ApiMessage
;
2014 PCONSOLE_SETTEXTATTRIB SetTextAttribRequest
= &ApiMessage
.Data
.SetTextAttribRequest
;
2016 SetTextAttribRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
2017 SetTextAttribRequest
->OutputHandle
= hConsoleOutput
;
2018 SetTextAttribRequest
->Attributes
= wAttributes
;
2020 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2022 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetTextAttribute
),
2023 sizeof(*SetTextAttribRequest
));
2024 if (!NT_SUCCESS(ApiMessage
.Status
))
2026 BaseSetLastNTError(ApiMessage
.Status
);
2036 AddConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine
)
2038 PHANDLER_ROUTINE
* NewCtrlHandlers
= NULL
;
2040 if (HandlerRoutine
== NULL
)
2042 NtCurrentPeb()->ProcessParameters
->ConsoleFlags
= TRUE
;
2046 if (NrCtrlHandlers
== NrAllocatedHandlers
)
2048 NewCtrlHandlers
= RtlAllocateHeap(RtlGetProcessHeap(),
2050 (NrCtrlHandlers
+ 4) * sizeof(PHANDLER_ROUTINE
));
2051 if (NewCtrlHandlers
== NULL
)
2053 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2057 memmove(NewCtrlHandlers
, CtrlHandlers
, sizeof(PHANDLER_ROUTINE
) * NrCtrlHandlers
);
2059 if (NrAllocatedHandlers
> 1) RtlFreeHeap(RtlGetProcessHeap(), 0, CtrlHandlers
);
2061 CtrlHandlers
= NewCtrlHandlers
;
2062 NrAllocatedHandlers
+= 4;
2065 ASSERT(NrCtrlHandlers
< NrAllocatedHandlers
);
2067 CtrlHandlers
[NrCtrlHandlers
++] = HandlerRoutine
;
2074 RemoveConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine
)
2078 if (HandlerRoutine
== NULL
)
2080 NtCurrentPeb()->ProcessParameters
->ConsoleFlags
= FALSE
;
2084 for (i
= 0; i
< NrCtrlHandlers
; i
++)
2086 if (CtrlHandlers
[i
] == HandlerRoutine
)
2088 if (i
< (NrCtrlHandlers
- 1))
2090 memmove(&CtrlHandlers
[i
],
2092 (NrCtrlHandlers
- i
+ 1) * sizeof(PHANDLER_ROUTINE
));
2100 SetLastError(ERROR_INVALID_PARAMETER
);
2111 SetConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine
,
2116 RtlEnterCriticalSection(&ConsoleLock
);
2119 Ret
= AddConsoleCtrlHandler(HandlerRoutine
);
2121 Ret
= RemoveConsoleCtrlHandler(HandlerRoutine
);
2123 RtlLeaveCriticalSection(&ConsoleLock
);
2134 GenerateConsoleCtrlEvent(DWORD dwCtrlEvent
,
2135 DWORD dwProcessGroupId
)
2137 CONSOLE_API_MESSAGE ApiMessage
;
2138 PCONSOLE_GENERATECTRLEVENT GenerateCtrlEventRequest
= &ApiMessage
.Data
.GenerateCtrlEventRequest
;
2140 if (dwCtrlEvent
!= CTRL_C_EVENT
&& dwCtrlEvent
!= CTRL_BREAK_EVENT
)
2142 SetLastError(ERROR_INVALID_PARAMETER
);
2146 GenerateCtrlEventRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
2147 GenerateCtrlEventRequest
->CtrlEvent
= dwCtrlEvent
;
2148 GenerateCtrlEventRequest
->ProcessGroupId
= dwProcessGroupId
;
2150 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2152 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGenerateCtrlEvent
),
2153 sizeof(*GenerateCtrlEventRequest
));
2154 if (!NT_SUCCESS(ApiMessage
.Status
))
2156 BaseSetLastNTError(ApiMessage
.Status
);
2165 IntGetConsoleTitle(LPVOID lpConsoleTitle
, DWORD dwNumChars
, BOOLEAN bUnicode
)
2167 CONSOLE_API_MESSAGE ApiMessage
;
2168 PCONSOLE_GETSETCONSOLETITLE TitleRequest
= &ApiMessage
.Data
.TitleRequest
;
2169 PCSR_CAPTURE_BUFFER CaptureBuffer
;
2171 if (dwNumChars
== 0) return 0;
2173 TitleRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
2174 TitleRequest
->Length
= dwNumChars
* (bUnicode
? sizeof(WCHAR
) : sizeof(CHAR
));
2175 TitleRequest
->Unicode
= bUnicode
;
2177 CaptureBuffer
= CsrAllocateCaptureBuffer(1, TitleRequest
->Length
);
2178 if (CaptureBuffer
== NULL
)
2180 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
2181 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2185 CsrAllocateMessagePointer(CaptureBuffer
,
2186 TitleRequest
->Length
,
2187 (PVOID
*)&TitleRequest
->Title
);
2189 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2191 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetTitle
),
2192 sizeof(*TitleRequest
));
2193 if (!NT_SUCCESS(ApiMessage
.Status
))
2195 CsrFreeCaptureBuffer(CaptureBuffer
);
2196 BaseSetLastNTError(ApiMessage
.Status
);
2200 dwNumChars
= TitleRequest
->Length
/ (bUnicode
? sizeof(WCHAR
) : sizeof(CHAR
));
2204 RtlCopyMemory(lpConsoleTitle
, TitleRequest
->Title
, TitleRequest
->Length
);
2207 ((LPWSTR
)lpConsoleTitle
)[dwNumChars
] = UNICODE_NULL
;
2209 ((LPSTR
)lpConsoleTitle
)[dwNumChars
] = ANSI_NULL
;
2212 CsrFreeCaptureBuffer(CaptureBuffer
);
2224 GetConsoleTitleW(LPWSTR lpConsoleTitle
,
2227 return IntGetConsoleTitle(lpConsoleTitle
, nSize
, TRUE
);
2237 GetConsoleTitleA(LPSTR lpConsoleTitle
,
2240 return IntGetConsoleTitle(lpConsoleTitle
, nSize
, FALSE
);
2245 IntSetConsoleTitle(CONST VOID
*lpConsoleTitle
, BOOLEAN bUnicode
)
2247 CONSOLE_API_MESSAGE ApiMessage
;
2248 PCONSOLE_GETSETCONSOLETITLE TitleRequest
= &ApiMessage
.Data
.TitleRequest
;
2249 PCSR_CAPTURE_BUFFER CaptureBuffer
;
2251 ULONG NumChars
= (ULONG
)(lpConsoleTitle
? (bUnicode
? wcslen(lpConsoleTitle
) : strlen(lpConsoleTitle
)) : 0);
2253 TitleRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
2254 TitleRequest
->Length
= NumChars
* (bUnicode
? sizeof(WCHAR
) : sizeof(CHAR
));
2255 TitleRequest
->Unicode
= bUnicode
;
2257 CaptureBuffer
= CsrAllocateCaptureBuffer(1, TitleRequest
->Length
);
2258 if (CaptureBuffer
== NULL
)
2260 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
2261 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2265 CsrCaptureMessageBuffer(CaptureBuffer
,
2266 (PVOID
)lpConsoleTitle
,
2267 TitleRequest
->Length
,
2268 (PVOID
*)&TitleRequest
->Title
);
2270 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2272 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetTitle
),
2273 sizeof(*TitleRequest
));
2275 CsrFreeCaptureBuffer(CaptureBuffer
);
2277 if (!NT_SUCCESS(ApiMessage
.Status
))
2279 BaseSetLastNTError(ApiMessage
.Status
);
2292 SetConsoleTitleW(LPCWSTR lpConsoleTitle
)
2294 return IntSetConsoleTitle(lpConsoleTitle
, TRUE
);
2304 SetConsoleTitleA(LPCSTR lpConsoleTitle
)
2306 return IntSetConsoleTitle(lpConsoleTitle
, FALSE
);
2315 CreateConsoleScreenBuffer(DWORD dwDesiredAccess
,
2317 CONST SECURITY_ATTRIBUTES
*lpSecurityAttributes
,
2319 LPVOID lpScreenBufferData
)
2321 CONSOLE_API_MESSAGE ApiMessage
;
2322 PCONSOLE_CREATESCREENBUFFER CreateScreenBufferRequest
= &ApiMessage
.Data
.CreateScreenBufferRequest
;
2323 PCSR_CAPTURE_BUFFER CaptureBuffer
= NULL
;
2324 PCONSOLE_GRAPHICS_BUFFER_INFO GraphicsBufferInfo
= lpScreenBufferData
;
2326 if ( (dwDesiredAccess
& ~(GENERIC_READ
| GENERIC_WRITE
)) ||
2327 (dwShareMode
& ~(FILE_SHARE_READ
| FILE_SHARE_WRITE
)) ||
2328 (dwFlags
!= CONSOLE_TEXTMODE_BUFFER
&& dwFlags
!= CONSOLE_GRAPHICS_BUFFER
) )
2330 SetLastError(ERROR_INVALID_PARAMETER
);
2331 return INVALID_HANDLE_VALUE
;
2334 CreateScreenBufferRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
2335 CreateScreenBufferRequest
->DesiredAccess
= dwDesiredAccess
;
2336 CreateScreenBufferRequest
->InheritHandle
=
2337 (lpSecurityAttributes
? lpSecurityAttributes
->bInheritHandle
: FALSE
);
2338 CreateScreenBufferRequest
->ShareMode
= dwShareMode
;
2339 CreateScreenBufferRequest
->ScreenBufferType
= dwFlags
;
2341 if (dwFlags
== CONSOLE_GRAPHICS_BUFFER
)
2343 if (CreateScreenBufferRequest
->InheritHandle
|| GraphicsBufferInfo
== NULL
)
2345 SetLastError(ERROR_INVALID_PARAMETER
);
2346 return INVALID_HANDLE_VALUE
;
2349 CreateScreenBufferRequest
->GraphicsBufferInfo
= *GraphicsBufferInfo
;
2351 CaptureBuffer
= CsrAllocateCaptureBuffer(1, GraphicsBufferInfo
->dwBitMapInfoLength
);
2352 if (CaptureBuffer
== NULL
)
2354 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2355 return INVALID_HANDLE_VALUE
;
2358 CsrCaptureMessageBuffer(CaptureBuffer
,
2359 (PVOID
)GraphicsBufferInfo
->lpBitMapInfo
,
2360 GraphicsBufferInfo
->dwBitMapInfoLength
,
2361 (PVOID
*)&CreateScreenBufferRequest
->GraphicsBufferInfo
.lpBitMapInfo
);
2364 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2366 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepCreateScreenBuffer
),
2367 sizeof(*CreateScreenBufferRequest
));
2369 if (CaptureBuffer
) CsrFreeCaptureBuffer(CaptureBuffer
);
2371 if (!NT_SUCCESS(ApiMessage
.Status
))
2373 BaseSetLastNTError(ApiMessage
.Status
);
2374 return INVALID_HANDLE_VALUE
;
2377 if (dwFlags
== CONSOLE_GRAPHICS_BUFFER
&& GraphicsBufferInfo
)
2379 GraphicsBufferInfo
->hMutex
= CreateScreenBufferRequest
->hMutex
; // CreateScreenBufferRequest->GraphicsBufferInfo.hMutex ;
2380 GraphicsBufferInfo
->lpBitMap
= CreateScreenBufferRequest
->lpBitMap
; // CreateScreenBufferRequest->GraphicsBufferInfo.lpBitMap;
2383 return CreateScreenBufferRequest
->OutputHandle
;
2395 CONSOLE_API_MESSAGE ApiMessage
;
2396 PCONSOLE_GETINPUTOUTPUTCP GetConsoleCPRequest
= &ApiMessage
.Data
.GetConsoleCPRequest
;
2398 /* Get the Input Code Page */
2399 GetConsoleCPRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
2400 GetConsoleCPRequest
->OutputCP
= FALSE
;
2402 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2404 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetCP
),
2405 sizeof(*GetConsoleCPRequest
));
2406 if (!NT_SUCCESS(ApiMessage
.Status
))
2408 BaseSetLastNTError(ApiMessage
.Status
);
2412 return GetConsoleCPRequest
->CodePage
;
2422 SetConsoleCP(UINT wCodePageID
)
2424 CONSOLE_API_MESSAGE ApiMessage
;
2425 PCONSOLE_SETINPUTOUTPUTCP SetConsoleCPRequest
= &ApiMessage
.Data
.SetConsoleCPRequest
;
2427 /* Set the Input Code Page */
2428 SetConsoleCPRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
2429 SetConsoleCPRequest
->CodePage
= wCodePageID
;
2430 SetConsoleCPRequest
->OutputCP
= FALSE
;
2431 /* SetConsoleCPRequest->EventHandle; */
2433 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2435 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetCP
),
2436 sizeof(*SetConsoleCPRequest
));
2437 if (!NT_SUCCESS(ApiMessage
.Status
))
2439 BaseSetLastNTError(ApiMessage
.Status
);
2453 GetConsoleOutputCP(VOID
)
2455 CONSOLE_API_MESSAGE ApiMessage
;
2456 PCONSOLE_GETINPUTOUTPUTCP GetConsoleCPRequest
= &ApiMessage
.Data
.GetConsoleCPRequest
;
2458 /* Get the Output Code Page */
2459 GetConsoleCPRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
2460 GetConsoleCPRequest
->OutputCP
= TRUE
;
2462 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2464 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetCP
),
2465 sizeof(*GetConsoleCPRequest
));
2466 if (!NT_SUCCESS(ApiMessage
.Status
))
2468 BaseSetLastNTError(ApiMessage
.Status
);
2472 return GetConsoleCPRequest
->CodePage
;
2482 SetConsoleOutputCP(UINT wCodePageID
)
2484 CONSOLE_API_MESSAGE ApiMessage
;
2485 PCONSOLE_SETINPUTOUTPUTCP SetConsoleCPRequest
= &ApiMessage
.Data
.SetConsoleCPRequest
;
2487 /* Set the Output Code Page */
2488 SetConsoleCPRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
2489 SetConsoleCPRequest
->CodePage
= wCodePageID
;
2490 SetConsoleCPRequest
->OutputCP
= TRUE
;
2491 /* SetConsoleCPRequest->EventHandle; */
2493 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2495 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetCP
),
2496 sizeof(*SetConsoleCPRequest
));
2497 if (!NT_SUCCESS(ApiMessage
.Status
))
2499 BaseSetLastNTError(ApiMessage
.Status
);
2512 GetConsoleProcessList(LPDWORD lpdwProcessList
,
2513 DWORD dwProcessCount
)
2515 CONSOLE_API_MESSAGE ApiMessage
;
2516 PCONSOLE_GETPROCESSLIST GetProcessListRequest
= &ApiMessage
.Data
.GetProcessListRequest
;
2517 PCSR_CAPTURE_BUFFER CaptureBuffer
;
2518 ULONG nProcesses
= 0;
2520 if (lpdwProcessList
== NULL
|| dwProcessCount
== 0)
2522 SetLastError(ERROR_INVALID_PARAMETER
);
2526 CaptureBuffer
= CsrAllocateCaptureBuffer(1, dwProcessCount
* sizeof(DWORD
));
2527 if (CaptureBuffer
== NULL
)
2529 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
2530 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2534 GetProcessListRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
2535 GetProcessListRequest
->ProcessCount
= dwProcessCount
;
2537 CsrAllocateMessagePointer(CaptureBuffer
,
2538 dwProcessCount
* sizeof(DWORD
),
2539 (PVOID
*)&GetProcessListRequest
->ProcessIdsList
);
2541 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2543 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetProcessList
),
2544 sizeof(*GetProcessListRequest
));
2545 if (!NT_SUCCESS(ApiMessage
.Status
))
2547 BaseSetLastNTError(ApiMessage
.Status
);
2551 nProcesses
= GetProcessListRequest
->ProcessCount
;
2552 if (dwProcessCount
>= nProcesses
)
2554 RtlCopyMemory(lpdwProcessList
, GetProcessListRequest
->ProcessIdsList
, nProcesses
* sizeof(DWORD
));
2558 CsrFreeCaptureBuffer(CaptureBuffer
);
2568 GetConsoleSelectionInfo(PCONSOLE_SELECTION_INFO lpConsoleSelectionInfo
)
2570 CONSOLE_API_MESSAGE ApiMessage
;
2571 PCONSOLE_GETSELECTIONINFO GetSelectionInfoRequest
= &ApiMessage
.Data
.GetSelectionInfoRequest
;
2573 if (lpConsoleSelectionInfo
== NULL
)
2575 SetLastError(ERROR_INVALID_PARAMETER
);
2579 GetSelectionInfoRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
2581 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2583 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetSelectionInfo
),
2584 sizeof(*GetSelectionInfoRequest
));
2585 if (!NT_SUCCESS(ApiMessage
.Status
))
2587 BaseSetLastNTError(ApiMessage
.Status
);
2591 *lpConsoleSelectionInfo
= GetSelectionInfoRequest
->Info
;
2599 * @note Strongly inspired by AllocConsole.
2602 IntAttachConsole(DWORD ProcessId
,
2603 LPTHREAD_START_ROUTINE CtrlRoutine
,
2604 LPTHREAD_START_ROUTINE PropRoutine
,
2605 PCONSOLE_START_INFO ConsoleStartInfo
)
2607 BOOL Success
= TRUE
;
2610 CONSOLE_API_MESSAGE ApiMessage
;
2611 PCONSOLE_ATTACHCONSOLE AttachConsoleRequest
= &ApiMessage
.Data
.AttachConsoleRequest
;
2612 PCSR_CAPTURE_BUFFER CaptureBuffer
;
2614 AttachConsoleRequest
->ProcessId
= ProcessId
;
2615 AttachConsoleRequest
->CtrlRoutine
= CtrlRoutine
;
2616 AttachConsoleRequest
->PropRoutine
= PropRoutine
;
2618 CaptureBuffer
= CsrAllocateCaptureBuffer(1, sizeof(CONSOLE_START_INFO
));
2619 if (CaptureBuffer
== NULL
)
2621 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2626 CsrCaptureMessageBuffer(CaptureBuffer
,
2628 sizeof(CONSOLE_START_INFO
),
2629 (PVOID
*)&AttachConsoleRequest
->ConsoleStartInfo
);
2631 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2633 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepAttach
),
2634 sizeof(*AttachConsoleRequest
));
2635 if (!NT_SUCCESS(ApiMessage
.Status
))
2637 BaseSetLastNTError(ApiMessage
.Status
);
2642 // Is AttachConsoleRequest->ConsoleStartInfo->InitEvents aligned on handle boundary ????
2643 Status
= NtWaitForMultipleObjects(MAX_INIT_EVENTS
,
2644 AttachConsoleRequest
->ConsoleStartInfo
->InitEvents
,
2645 WaitAny
, FALSE
, NULL
);
2646 if (!NT_SUCCESS(Status
))
2648 BaseSetLastNTError(Status
);
2653 NtClose(AttachConsoleRequest
->ConsoleStartInfo
->InitEvents
[INIT_SUCCESS
]);
2654 NtClose(AttachConsoleRequest
->ConsoleStartInfo
->InitEvents
[INIT_FAILURE
]);
2655 if (Status
!= INIT_SUCCESS
)
2657 NtCurrentPeb()->ProcessParameters
->ConsoleHandle
= NULL
;
2662 RtlCopyMemory(ConsoleStartInfo
,
2663 AttachConsoleRequest
->ConsoleStartInfo
,
2664 sizeof(CONSOLE_START_INFO
));
2669 if (CaptureBuffer
) CsrFreeCaptureBuffer(CaptureBuffer
);
2675 AttachConsole(DWORD dwProcessId
)
2678 CONSOLE_START_INFO ConsoleStartInfo
;
2683 RtlEnterCriticalSection(&ConsoleLock
);
2685 if (NtCurrentPeb()->ProcessParameters
->ConsoleHandle
)
2687 DPRINT1("AttachConsole: Attaching a console to a process already having one\n");
2688 SetLastError(ERROR_ACCESS_DENIED
);
2693 /* Set up the console properties */
2694 SetUpConsoleInfo(FALSE
,
2701 Success
= IntAttachConsole(dwProcessId
,
2702 ConsoleControlDispatcher
,
2707 /* Set up the handles */
2708 SetUpHandles(&ConsoleStartInfo
);
2709 InputWaitHandle
= ConsoleStartInfo
.InputWaitHandle
;
2711 /* Initialize Console Ctrl Handling */
2712 InitializeCtrlHandling();
2714 /* Sets the current console locale for this thread */
2719 RtlLeaveCriticalSection(&ConsoleLock
);
2730 GetConsoleWindow(VOID
)
2732 CONSOLE_API_MESSAGE ApiMessage
;
2733 PCONSOLE_GETWINDOW GetWindowRequest
= &ApiMessage
.Data
.GetWindowRequest
;
2735 GetWindowRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
2737 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2739 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetConsoleWindow
),
2740 sizeof(*GetWindowRequest
));
2741 if (!NT_SUCCESS(ApiMessage
.Status
))
2743 BaseSetLastNTError(ApiMessage
.Status
);
2747 return GetWindowRequest
->WindowHandle
;
2757 SetConsoleIcon(HICON hIcon
)
2759 CONSOLE_API_MESSAGE ApiMessage
;
2760 PCONSOLE_SETICON SetIconRequest
= &ApiMessage
.Data
.SetIconRequest
;
2762 SetIconRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
2763 SetIconRequest
->IconHandle
= hIcon
;
2765 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2767 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetIcon
),
2768 sizeof(*SetIconRequest
));
2769 if (!NT_SUCCESS(ApiMessage
.Status
))
2771 BaseSetLastNTError(ApiMessage
.Status
);
2779 /******************************************************************************
2780 * \name SetConsoleInputExeNameW
2781 * \brief Sets the console input file name from a unicode string.
2782 * \param lpExeName Pointer to a unicode string with the name.
2783 * \return TRUE if successful, FALSE if unsuccessful.
2784 * \remarks If lpExeName is 0 or the string length is 0 or greater than 255,
2785 * the function fails and sets last error to ERROR_INVALID_PARAMETER.
2790 SetConsoleInputExeNameW(IN LPCWSTR lpExeName
)
2794 ExeLength
= lstrlenW(lpExeName
);
2795 if ((ExeLength
== 0) || (ExeLength
>= EXENAME_LENGTH
))
2797 /* Fail if string is empty or too long */
2798 SetLastError(ERROR_INVALID_PARAMETER
);
2802 RtlEnterCriticalSection(&ExeNameLock
);
2805 /* Set the input EXE name, not NULL terminated */
2806 RtlCopyMemory(ExeNameBuffer
, lpExeName
, ExeLength
* sizeof(WCHAR
));
2807 ExeNameLength
= (USHORT
)ExeLength
;
2811 RtlLeaveCriticalSection(&ExeNameLock
);
2819 /******************************************************************************
2820 * \name SetConsoleInputExeNameA
2821 * \brief Sets the console input file name from an ansi string.
2822 * \param lpExeName Pointer to an ansi string with the name.
2823 * \return TRUE if successful, FALSE if unsuccessful.
2824 * \remarks If lpExeName is 0 or the string length is 0 or greater than 255,
2825 * the function fails and sets last error to ERROR_INVALID_PARAMETER.
2830 SetConsoleInputExeNameA(IN LPCSTR lpExeName
)
2833 #ifdef USE_TEB_STATIC_USTR
2834 PUNICODE_STRING ExeNameU
;
2836 UNICODE_STRING ExeNameU
;
2838 ANSI_STRING ExeNameA
;
2839 #ifndef USE_TEB_STATIC_USTR
2840 WCHAR Buffer
[EXENAME_LENGTH
];
2843 #ifdef USE_TEB_STATIC_USTR
2845 * Use the TEB static UNICODE string for storage. It is already
2846 * initialized at process creation time by the Memory Manager.
2848 ExeNameU
= &NtCurrentTeb()->StaticUnicodeString
;
2851 /* Initialize string for conversion */
2852 RtlInitAnsiString(&ExeNameA
, lpExeName
);
2855 if ((ExeNameA
.Length
== 0) || (ExeNameA
.Length
>= EXENAME_LENGTH
))
2857 /* Fail if string is empty or too long */
2858 SetLastError(ERROR_INVALID_PARAMETER
);
2862 #ifndef USE_TEB_STATIC_USTR
2863 ExeNameU
.Length
= 0;
2864 ExeNameU
.MaximumLength
= (USHORT
)sizeof(Buffer
);
2865 ExeNameU
.Buffer
= Buffer
;
2868 #ifdef USE_TEB_STATIC_USTR
2869 Status
= RtlAnsiStringToUnicodeString(ExeNameU
, &ExeNameA
, FALSE
);
2871 Status
= RtlAnsiStringToUnicodeString(&ExeNameU
, &ExeNameA
, FALSE
);
2873 if (!NT_SUCCESS(Status
))
2875 /* Fail if string is empty or too long */
2876 if (Status
== STATUS_BUFFER_OVERFLOW
)
2877 SetLastError(ERROR_FILENAME_EXCED_RANGE
);
2879 SetLastError(ERROR_INVALID_PARAMETER
);
2884 #ifdef USE_TEB_STATIC_USTR
2885 return SetConsoleInputExeNameW(ExeNameU
->Buffer
);
2887 return SetConsoleInputExeNameW(ExeNameU
.Buffer
);
2892 /******************************************************************************
2893 * \name GetConsoleInputExeNameW
2894 * \brief Retrieves the console input file name as unicode string.
2895 * \param nBufferLength Length of the buffer in WCHARs.
2896 * Specify 0 to receive the needed buffer length.
2897 * \param lpBuffer Pointer to a buffer that receives the string.
2898 * \return Needed buffer size if \p nBufferLength is 0.
2899 * Otherwise 1 if successful, 2 if buffer is too small.
2900 * \remarks Sets last error value to ERROR_BUFFER_OVERFLOW if the buffer
2901 * is not big enough.
2906 GetConsoleInputExeNameW(IN DWORD nBufferLength
,
2907 OUT LPWSTR lpExeName
)
2909 if (nBufferLength
<= ExeNameLength
)
2911 /* Buffer is not large enough! Return the correct size. */
2912 SetLastError(ERROR_BUFFER_OVERFLOW
);
2913 return ExeNameLength
+ 1;
2916 RtlEnterCriticalSection(&ExeNameLock
);
2919 /* Copy the input EXE name and NULL-terminate it */
2920 RtlCopyMemory(lpExeName
, ExeNameBuffer
, ExeNameLength
* sizeof(WCHAR
));
2921 lpExeName
[ExeNameLength
] = UNICODE_NULL
;
2925 RtlLeaveCriticalSection(&ExeNameLock
);
2933 /******************************************************************************
2934 * \name GetConsoleInputExeNameA
2935 * \brief Retrieves the console input file name as ansi string.
2936 * \param nBufferLength Length of the buffer in CHARs.
2937 * \param lpBuffer Pointer to a buffer that receives the string.
2938 * \return 1 if successful, 2 if buffer is too small.
2939 * \remarks Sets last error value to ERROR_BUFFER_OVERFLOW if the buffer
2940 * is not big enough. The buffer receives as much characters as fit.
2945 GetConsoleInputExeNameA(IN DWORD nBufferLength
,
2946 OUT LPSTR lpExeName
)
2950 UNICODE_STRING BufferU
;
2951 ANSI_STRING BufferA
;
2952 WCHAR Buffer
[EXENAME_LENGTH
];
2954 /* Get the UNICODE name */
2955 ExeLength
= GetConsoleInputExeNameW(EXENAME_LENGTH
, Buffer
);
2957 if ((ExeLength
== 0) || (ExeLength
>= EXENAME_LENGTH
))
2960 /* Initialize the strings for conversion */
2961 RtlInitUnicodeString(&BufferU
, Buffer
);
2963 BufferA
.MaximumLength
= (USHORT
)nBufferLength
;
2964 BufferA
.Buffer
= lpExeName
;
2966 /* Convert UNICODE name to ANSI, copying as much chars as it can fit */
2967 Status
= RtlUnicodeStringToAnsiString(&BufferA
, &BufferU
, FALSE
);
2968 if (!NT_SUCCESS(Status
))
2970 if (Status
== STATUS_BUFFER_OVERFLOW
)
2972 SetLastError(ERROR_BUFFER_OVERFLOW
);
2973 return ExeLength
+ 1;
2975 SetLastError(ERROR_INVALID_PARAMETER
);
2983 GetConsoleCharType(HANDLE hConsole
, COORD Coord
, PDWORD Type
)
2992 GetConsoleCursorMode(HANDLE hConsole
, PBOOL pUnknown1
, PBOOL pUnknown2
)
3001 SetConsoleCursorMode(HANDLE hConsole
, BOOL Unknown1
, BOOL Unknown2
)
3010 GetConsoleNlsMode(HANDLE hConsole
, LPDWORD lpMode
)
3019 SetConsoleNlsMode(HANDLE hConsole
, DWORD dwMode
)
3028 SetConsoleLocalEUDC(DWORD Unknown1
, DWORD Unknown2
, DWORD Unknown3
, DWORD Unknown4
)
3037 RegisterConsoleIME(HWND hWnd
, LPDWORD ThreadId
)
3046 RegisterConsoleOS2(BOOL bUnknown
)
3055 SetConsoleOS2OemFormat(BOOL bUnknown
)
3064 UnregisterConsoleIME(VOID
)
3073 IntGetConsoleKeyboardLayoutName(OUT PVOID pszLayoutName
,
3076 CONSOLE_API_MESSAGE ApiMessage
;
3077 PCONSOLE_GETKBDLAYOUTNAME GetKbdLayoutNameRequest
= &ApiMessage
.Data
.GetKbdLayoutNameRequest
;
3079 /* Set up the data to send to the Console Server */
3080 GetKbdLayoutNameRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
3081 GetKbdLayoutNameRequest
->Ansi
= bAnsi
;
3083 /* Call the server */
3084 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
3086 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetKeyboardLayoutName
),
3087 sizeof(*GetKbdLayoutNameRequest
));
3089 /* Check for success */
3090 if (!NT_SUCCESS(ApiMessage
.Status
))
3092 BaseSetLastNTError(ApiMessage
.Status
);
3096 /* Retrieve the results */
3099 /* Copy only KL_NAMELENGTH == 9 characters, ANSI or UNICODE */
3101 strncpy(pszLayoutName
, (PCHAR
)GetKbdLayoutNameRequest
->LayoutBuffer
, KL_NAMELENGTH
);
3103 wcsncpy(pszLayoutName
, (PWCHAR
)GetKbdLayoutNameRequest
->LayoutBuffer
, KL_NAMELENGTH
);
3105 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3107 SetLastError(ERROR_INVALID_ACCESS
);
3108 _SEH2_YIELD(return FALSE
);
3116 * @implemented (undocumented)
3121 GetConsoleKeyboardLayoutNameA(OUT LPSTR pszLayoutName
)
3123 return IntGetConsoleKeyboardLayoutName(pszLayoutName
, TRUE
);
3127 * @implemented (undocumented)
3132 GetConsoleKeyboardLayoutNameW(OUT LPWSTR pszLayoutName
)
3134 return IntGetConsoleKeyboardLayoutName(pszLayoutName
, FALSE
);
3142 SetLastConsoleEventActive(VOID
)
3144 CONSOLE_API_MESSAGE ApiMessage
;
3145 PCONSOLE_NOTIFYLASTCLOSE NotifyLastCloseRequest
= &ApiMessage
.Data
.NotifyLastCloseRequest
;
3147 /* Set the flag used by the console control dispatcher */
3148 LastCloseNotify
= TRUE
;
3150 /* Set up the input arguments */
3151 NotifyLastCloseRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
3153 /* Call CSRSS; just return the NTSTATUS cast to DWORD */
3154 return CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
3156 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepNotifyLastClose
),
3157 sizeof(*NotifyLastCloseRequest
));