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
;
34 HANDLE InputWaitHandle
= INVALID_HANDLE_VALUE
;
36 #define INPUTEXENAME_BUFLEN 256
37 static WCHAR InputExeName
[INPUTEXENAME_BUFLEN
];
40 /* Default Console Control Handler ********************************************/
44 DefaultConsoleCtrlHandler(DWORD Event
)
46 DPRINT("Default handler called: %lx\n", Event
);
50 DPRINT("Ctrl-C Event\n");
53 case CTRL_BREAK_EVENT
:
54 DPRINT("Ctrl-Break Event\n");
57 case CTRL_CLOSE_EVENT
:
58 DPRINT("Ctrl Close Event\n");
61 case CTRL_LOGOFF_EVENT
:
62 DPRINT("Ctrl Logoff Event\n");
65 case CTRL_SHUTDOWN_EVENT
:
66 DPRINT("Ctrl Shutdown Event\n");
70 ExitProcess(CONTROL_C_EXIT
);
76 ConsoleControlDispatcher(IN LPVOID lpThreadParameter
)
79 DWORD CodeAndFlag
= PtrToUlong(lpThreadParameter
);
80 DWORD nCode
= CodeAndFlag
& MAXLONG
;
82 EXCEPTION_RECORD erException
;
84 DPRINT1("Console Dispatcher Active: %lx %lx\n", CodeAndFlag
, nCode
);
85 SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST
);
90 case CTRL_BREAK_EVENT
:
92 if (IsDebuggerPresent())
94 erException
.ExceptionCode
= (nCode
== CTRL_C_EVENT
?
95 DBG_CONTROL_C
: DBG_CONTROL_BREAK
);
96 erException
.ExceptionFlags
= 0;
97 erException
.ExceptionRecord
= NULL
;
98 erException
.ExceptionAddress
= DefaultConsoleCtrlHandler
;
99 erException
.NumberParameters
= 0;
103 RtlRaiseException(&erException
);
105 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
107 RtlEnterCriticalSection(&ConsoleLock
);
109 if ((nCode
!= CTRL_C_EVENT
) ||
110 (NtCurrentPeb()->ProcessParameters
->ConsoleFlags
!= 1))
112 for (i
= NrCtrlHandlers
; i
> 0; i
--)
114 if (CtrlHandlers
[i
- 1](nCode
)) break;
118 RtlLeaveCriticalSection(&ConsoleLock
);
127 case CTRL_CLOSE_EVENT
:
128 case CTRL_LOGOFF_EVENT
:
129 case CTRL_SHUTDOWN_EVENT
:
137 ExitProcess(CONTROL_C_EXIT
);
145 ASSERT(ConsoleInitialized
);
147 RtlEnterCriticalSection(&ConsoleLock
);
150 if ((nCode
!= CTRL_C_EVENT
) || (NtCurrentPeb()->ProcessParameters
->ConsoleFlags
!= 1))
152 for (i
= NrCtrlHandlers
; i
> 0; i
--)
155 (CodeAndFlag
& MINLONG
) &&
156 ((nCode
== CTRL_LOGOFF_EVENT
) || (nCode
== CTRL_SHUTDOWN_EVENT
)))
158 DPRINT("Skipping system/service apps\n");
162 if (CtrlHandlers
[i
- 1](nCode
))
166 case CTRL_CLOSE_EVENT
:
167 case CTRL_LOGOFF_EVENT
:
168 case CTRL_SHUTDOWN_EVENT
:
170 nExitCode
= CodeAndFlag
;
178 RtlLeaveCriticalSection(&ConsoleLock
);
180 ExitThread(nExitCode
);
181 return STATUS_SUCCESS
;
186 InitConsoleCtrlHandling(VOID
)
188 /* Initialize Console Ctrl Handler */
189 NrAllocatedHandlers
= NrCtrlHandlers
= 1;
190 CtrlHandlers
= InitialHandler
;
191 CtrlHandlers
[0] = DefaultConsoleCtrlHandler
;
195 /* FUNCTIONS ******************************************************************/
198 IntCheckForConsoleFileName(IN LPCWSTR pszName
,
199 IN DWORD dwDesiredAccess
)
201 LPCWSTR ConsoleName
= pszName
;
202 ULONG DeviceNameInfo
;
205 * Check whether we deal with a DOS device, and if so,
206 * strip the path till the file name.
207 * Therefore, things like \\.\CON or C:\some_path\CONIN$
208 * are transformed into CON or CONIN$, for example.
210 DeviceNameInfo
= RtlIsDosDeviceName_U(pszName
);
211 if (DeviceNameInfo
!= 0)
213 ConsoleName
= (LPCWSTR
)((ULONG_PTR
)ConsoleName
+ ((DeviceNameInfo
>> 16) & 0xFFFF));
216 /* Return a standard console "file" name according to what we passed in parameters */
217 if (_wcsicmp(ConsoleName
, BaseConInputFileName
) == 0)
219 return BaseConInputFileName
;
221 else if (_wcsicmp(ConsoleName
, BaseConOutputFileName
) == 0)
223 return BaseConOutputFileName
;
225 else if (_wcsicmp(ConsoleName
, BaseConFileName
) == 0)
227 if ((dwDesiredAccess
& (GENERIC_READ
| GENERIC_WRITE
)) == GENERIC_READ
)
229 return BaseConInputFileName
;
231 else if ((dwDesiredAccess
& (GENERIC_READ
| GENERIC_WRITE
)) == GENERIC_WRITE
)
233 return BaseConOutputFileName
;
237 /* If we are there, that means that either the file name or the desired access are wrong */
243 * @implemented (Undocumented)
244 * @note See http://undoc.airesoft.co.uk/kernel32.dll/ConsoleMenuControl.php
248 ConsoleMenuControl(HANDLE hConsoleOutput
,
252 CONSOLE_API_MESSAGE ApiMessage
;
253 PCONSOLE_MENUCONTROL MenuControlRequest
= &ApiMessage
.Data
.MenuControlRequest
;
255 MenuControlRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
256 MenuControlRequest
->OutputHandle
= hConsoleOutput
;
257 MenuControlRequest
->CmdIdLow
= dwCmdIdLow
;
258 MenuControlRequest
->CmdIdHigh
= dwCmdIdHigh
;
259 MenuControlRequest
->MenuHandle
= NULL
;
261 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
263 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepMenuControl
),
264 sizeof(*MenuControlRequest
));
266 return MenuControlRequest
->MenuHandle
;
275 DuplicateConsoleHandle(HANDLE hConsole
,
276 DWORD dwDesiredAccess
,
281 CONSOLE_API_MESSAGE ApiMessage
;
282 PCONSOLE_DUPLICATEHANDLE DuplicateHandleRequest
= &ApiMessage
.Data
.DuplicateHandleRequest
;
284 if ( (dwOptions
& ~(DUPLICATE_CLOSE_SOURCE
| DUPLICATE_SAME_ACCESS
)) ||
285 (!(dwOptions
& DUPLICATE_SAME_ACCESS
) &&
286 (dwDesiredAccess
& ~(GENERIC_READ
| GENERIC_WRITE
))) )
288 SetLastError (ERROR_INVALID_PARAMETER
);
289 return INVALID_HANDLE_VALUE
;
292 DuplicateHandleRequest
->ConsoleHandle
= hConsole
;
293 DuplicateHandleRequest
->Access
= dwDesiredAccess
;
294 DuplicateHandleRequest
->Inheritable
= bInheritHandle
;
295 DuplicateHandleRequest
->Options
= dwOptions
;
297 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
299 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepDuplicateHandle
),
300 sizeof(CONSOLE_DUPLICATEHANDLE
));
301 if (!NT_SUCCESS(Status
))
303 BaseSetLastNTError(Status
);
304 return INVALID_HANDLE_VALUE
;
307 return DuplicateHandleRequest
->ConsoleHandle
;
316 GetConsoleDisplayMode(LPDWORD lpModeFlags
)
318 CONSOLE_API_MESSAGE ApiMessage
;
319 PCONSOLE_GETDISPLAYMODE GetDisplayModeRequest
= &ApiMessage
.Data
.GetDisplayModeRequest
;
321 if (lpModeFlags
== NULL
)
323 SetLastError(ERROR_INVALID_PARAMETER
);
327 GetDisplayModeRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
329 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
331 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetDisplayMode
),
332 sizeof(*GetDisplayModeRequest
));
333 if (!NT_SUCCESS(ApiMessage
.Status
))
335 BaseSetLastNTError(ApiMessage
.Status
);
339 *lpModeFlags
= GetDisplayModeRequest
->DisplayMode
; // ModeFlags
345 * @unimplemented (Undocumented)
349 GetConsoleFontInfo(HANDLE hConsoleOutput
,
352 PCONSOLE_FONT_INFO lpConsoleFontInfo
)
354 DPRINT1("GetConsoleFontInfo(0x%p, %d, %lu, 0x%p) UNIMPLEMENTED!\n", hConsoleOutput
, bMaximumWindow
, nFontCount
, lpConsoleFontInfo
);
355 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
365 GetConsoleFontSize(HANDLE hConsoleOutput
,
368 COORD Empty
= {0, 0};
369 DPRINT1("GetConsoleFontSize(0x%p, 0x%x) UNIMPLEMENTED!\n", hConsoleOutput
, nFont
);
370 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
376 * @implemented (Undocumented)
380 GetConsoleHardwareState(HANDLE hConsoleOutput
,
384 CONSOLE_API_MESSAGE ApiMessage
;
385 PCONSOLE_GETSETHWSTATE HardwareStateRequest
= &ApiMessage
.Data
.HardwareStateRequest
;
387 DPRINT1("GetConsoleHardwareState(%lu, 0x%p) UNIMPLEMENTED!\n", Flags
, State
);
389 if (Flags
== NULL
|| State
== NULL
)
391 SetLastError(ERROR_INVALID_PARAMETER
);
395 HardwareStateRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
396 HardwareStateRequest
->OutputHandle
= hConsoleOutput
;
398 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
400 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetHardwareState
),
401 sizeof(*HardwareStateRequest
));
402 if (!NT_SUCCESS(ApiMessage
.Status
))
404 BaseSetLastNTError(ApiMessage
.Status
);
408 *Flags
= HardwareStateRequest
->Flags
;
409 *State
= HardwareStateRequest
->State
;
415 * @implemented (Undocumented)
419 GetConsoleInputWaitHandle(VOID
)
421 return InputWaitHandle
;
430 GetCurrentConsoleFont(HANDLE hConsoleOutput
,
432 PCONSOLE_FONT_INFO lpConsoleCurrentFont
)
434 DPRINT1("GetCurrentConsoleFont(0x%p, 0x%x, 0x%p) UNIMPLEMENTED!\n", hConsoleOutput
, bMaximumWindow
, lpConsoleCurrentFont
);
435 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
441 * @unimplemented (Undocumented)
445 GetNumberOfConsoleFonts(VOID
)
447 DPRINT1("GetNumberOfConsoleFonts() UNIMPLEMENTED!\n");
448 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
454 * @implemented (Undocumented)
455 * @note See http://blog.airesoft.co.uk/2012/10/things-ms-can-do-that-they-dont-tell-you-about-console-graphics/
459 InvalidateConsoleDIBits(IN HANDLE hConsoleOutput
,
460 IN PSMALL_RECT lpRect
)
462 CONSOLE_API_MESSAGE ApiMessage
;
463 PCONSOLE_INVALIDATEDIBITS InvalidateDIBitsRequest
= &ApiMessage
.Data
.InvalidateDIBitsRequest
;
467 SetLastError(ERROR_INVALID_PARAMETER
);
471 InvalidateDIBitsRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
472 InvalidateDIBitsRequest
->OutputHandle
= hConsoleOutput
;
473 InvalidateDIBitsRequest
->Region
= *lpRect
;
475 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
477 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepInvalidateBitMapRect
),
478 sizeof(*InvalidateDIBitsRequest
));
479 if (!NT_SUCCESS(ApiMessage
.Status
))
481 BaseSetLastNTError(ApiMessage
.Status
);
490 * @unimplemented (Undocumented)
494 OpenConsoleW(LPCWSTR wsName
,
495 DWORD dwDesiredAccess
,
499 NTSTATUS Status
= STATUS_SUCCESS
;
500 CONSOLE_API_MESSAGE ApiMessage
;
501 PCONSOLE_OPENCONSOLE OpenConsoleRequest
= &ApiMessage
.Data
.OpenConsoleRequest
;
502 CONSOLE_HANDLE_TYPE HandleType
;
504 if (wsName
&& 0 == _wcsicmp(wsName
, BaseConInputFileName
))
506 HandleType
= HANDLE_INPUT
;
508 else if (wsName
&& 0 == _wcsicmp(wsName
, BaseConOutputFileName
))
510 HandleType
= HANDLE_OUTPUT
;
514 SetLastError(ERROR_INVALID_PARAMETER
);
515 return INVALID_HANDLE_VALUE
;
518 if ( (dwDesiredAccess
& ~(GENERIC_READ
| GENERIC_WRITE
)) ||
519 (dwShareMode
& ~(FILE_SHARE_READ
| FILE_SHARE_WRITE
)) )
521 SetLastError(ERROR_INVALID_PARAMETER
);
522 return INVALID_HANDLE_VALUE
;
525 OpenConsoleRequest
->HandleType
= HandleType
;
526 OpenConsoleRequest
->Access
= dwDesiredAccess
;
527 OpenConsoleRequest
->Inheritable
= bInheritHandle
;
528 OpenConsoleRequest
->ShareMode
= dwShareMode
;
530 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
532 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepOpenConsole
),
533 sizeof(CONSOLE_OPENCONSOLE
));
534 if (!NT_SUCCESS(Status
))
536 BaseSetLastNTError(Status
);
537 return INVALID_HANDLE_VALUE
;
540 return OpenConsoleRequest
->ConsoleHandle
;
545 * @implemented (Undocumented)
546 * @note See http://undoc.airesoft.co.uk/kernel32.dll/SetConsoleCursor.php
550 SetConsoleCursor(HANDLE hConsoleOutput
,
553 CONSOLE_API_MESSAGE ApiMessage
;
554 PCONSOLE_SETCURSOR SetCursorRequest
= &ApiMessage
.Data
.SetCursorRequest
;
556 SetCursorRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
557 SetCursorRequest
->OutputHandle
= hConsoleOutput
;
558 SetCursorRequest
->CursorHandle
= hCursor
;
560 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
562 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetCursor
),
563 sizeof(*SetCursorRequest
));
564 if (!NT_SUCCESS(ApiMessage
.Status
))
566 BaseSetLastNTError(ApiMessage
.Status
);
579 SetConsoleDisplayMode(HANDLE hConsoleOutput
,
580 DWORD dwFlags
, // dwModeFlags
581 PCOORD lpNewScreenBufferDimensions
)
583 CONSOLE_API_MESSAGE ApiMessage
;
584 PCONSOLE_SETDISPLAYMODE SetDisplayModeRequest
= &ApiMessage
.Data
.SetDisplayModeRequest
;
586 SetDisplayModeRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
587 SetDisplayModeRequest
->OutputHandle
= hConsoleOutput
;
588 SetDisplayModeRequest
->DisplayMode
= dwFlags
; // ModeFlags ; dwModeFlags
589 SetDisplayModeRequest
->NewSBDim
.X
= 0;
590 SetDisplayModeRequest
->NewSBDim
.Y
= 0;
591 /* SetDisplayModeRequest->EventHandle; */
593 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
595 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetDisplayMode
),
596 sizeof(*SetDisplayModeRequest
));
597 if (!NT_SUCCESS(ApiMessage
.Status
))
599 BaseSetLastNTError(ApiMessage
.Status
);
603 if (lpNewScreenBufferDimensions
)
604 *lpNewScreenBufferDimensions
= SetDisplayModeRequest
->NewSBDim
;
611 * @unimplemented (Undocumented)
615 SetConsoleFont(HANDLE hConsoleOutput
,
618 DPRINT1("SetConsoleFont(0x%p, %lu) UNIMPLEMENTED!\n", hConsoleOutput
, nFont
);
619 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
625 * @implemented (Undocumented)
629 SetConsoleHardwareState(HANDLE hConsoleOutput
,
633 CONSOLE_API_MESSAGE ApiMessage
;
634 PCONSOLE_GETSETHWSTATE HardwareStateRequest
= &ApiMessage
.Data
.HardwareStateRequest
;
636 DPRINT1("SetConsoleHardwareState(%lu, %lu) UNIMPLEMENTED!\n", Flags
, State
);
638 HardwareStateRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
639 HardwareStateRequest
->OutputHandle
= hConsoleOutput
;
640 HardwareStateRequest
->Flags
= Flags
;
641 HardwareStateRequest
->State
= State
;
643 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
645 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetHardwareState
),
646 sizeof(*HardwareStateRequest
));
647 if (!NT_SUCCESS(ApiMessage
.Status
))
649 BaseSetLastNTError(ApiMessage
.Status
);
658 * @unimplemented (Undocumented)
662 SetConsoleKeyShortcuts(DWORD Unknown0
,
667 DPRINT1("SetConsoleKeyShortcuts(0x%x, 0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
, Unknown2
, Unknown3
);
668 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
674 * @implemented (Undocumented)
675 * @note See http://undoc.airesoft.co.uk/kernel32.dll/SetConsoleMaximumWindowSize.php
676 * Does nothing, returns TRUE only. Checked on Windows Server 2003.
680 SetConsoleMaximumWindowSize(HANDLE hConsoleOutput
,
683 DPRINT1("SetConsoleMaximumWindowSize(0x%p, {%d, %d}) does nothing\n",
684 hConsoleOutput
, dwMaximumSize
.X
, dwMaximumSize
.Y
);
690 * @implemented (Undocumented)
694 SetConsoleMenuClose(BOOL bEnable
)
696 CONSOLE_API_MESSAGE ApiMessage
;
697 PCONSOLE_SETMENUCLOSE SetMenuCloseRequest
= &ApiMessage
.Data
.SetMenuCloseRequest
;
699 SetMenuCloseRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
700 SetMenuCloseRequest
->Enable
= bEnable
;
702 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
704 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetMenuClose
),
705 sizeof(*SetMenuCloseRequest
));
706 if (!NT_SUCCESS(ApiMessage
.Status
))
708 BaseSetLastNTError(ApiMessage
.Status
);
717 * @implemented (Undocumented)
718 * @note See http://comments.gmane.org/gmane.comp.lang.harbour.devel/27844
719 * Usage example: https://github.com/harbour/core/commit/d79a1b7b812cbde6ddf718ebfd6939a24f633e52
723 SetConsolePalette(HANDLE hConsoleOutput
,
727 CONSOLE_API_MESSAGE ApiMessage
;
728 PCONSOLE_SETPALETTE SetPaletteRequest
= &ApiMessage
.Data
.SetPaletteRequest
;
730 SetPaletteRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
731 SetPaletteRequest
->OutputHandle
= hConsoleOutput
;
732 SetPaletteRequest
->PaletteHandle
= hPalette
;
733 SetPaletteRequest
->Usage
= dwUsage
;
735 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
737 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetPalette
),
738 sizeof(*SetPaletteRequest
));
739 if (!NT_SUCCESS(ApiMessage
.Status
))
741 BaseSetLastNTError(ApiMessage
.Status
);
749 * @implemented (Undocumented)
750 * @note See http://undoc.airesoft.co.uk/kernel32.dll/ShowConsoleCursor.php
754 ShowConsoleCursor(HANDLE hConsoleOutput
,
757 CONSOLE_API_MESSAGE ApiMessage
;
758 PCONSOLE_SHOWCURSOR ShowCursorRequest
= &ApiMessage
.Data
.ShowCursorRequest
;
760 ShowCursorRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
761 ShowCursorRequest
->OutputHandle
= hConsoleOutput
;
762 ShowCursorRequest
->Show
= bShow
;
763 ShowCursorRequest
->RefCount
= 0;
765 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
767 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepShowCursor
),
768 sizeof(*ShowCursorRequest
));
770 return ShowCursorRequest
->RefCount
;
775 * FUNCTION: Checks whether the given handle is a valid console handle.
778 * hIoHandle - Handle to be checked.
781 * TRUE : Handle is a valid console handle.
782 * FALSE: Handle is not a valid console handle.
784 * STATUS: Officially undocumented
790 VerifyConsoleIoHandle(HANDLE hIoHandle
)
792 CONSOLE_API_MESSAGE ApiMessage
;
793 PCONSOLE_VERIFYHANDLE VerifyHandleRequest
= &ApiMessage
.Data
.VerifyHandleRequest
;
795 VerifyHandleRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
796 VerifyHandleRequest
->Handle
= hIoHandle
;
797 VerifyHandleRequest
->IsValid
= FALSE
;
799 /* If the process is not attached to a console, return invalid handle */
800 if (VerifyHandleRequest
->ConsoleHandle
== NULL
) return FALSE
;
802 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
804 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepVerifyIoHandle
),
805 sizeof(*VerifyHandleRequest
));
806 if (!NT_SUCCESS(ApiMessage
.Status
))
808 BaseSetLastNTError(ApiMessage
.Status
);
812 return VerifyHandleRequest
->IsValid
;
817 * @implemented (Undocumented)
821 CloseConsoleHandle(HANDLE hHandle
)
823 CONSOLE_API_MESSAGE ApiMessage
;
824 PCONSOLE_CLOSEHANDLE CloseHandleRequest
= &ApiMessage
.Data
.CloseHandleRequest
;
826 CloseHandleRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
827 CloseHandleRequest
->Handle
= hHandle
;
829 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
831 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepCloseHandle
),
832 sizeof(*CloseHandleRequest
));
833 if (!NT_SUCCESS(ApiMessage
.Status
))
835 BaseSetLastNTError(ApiMessage
.Status
);
848 GetStdHandle(DWORD nStdHandle
)
850 * FUNCTION: Get a handle for the standard input, standard output
851 * and a standard error device.
854 * nStdHandle - Specifies the device for which to return the handle.
856 * RETURNS: If the function succeeds, the return value is the handle
857 * of the specified device. Otherwise the value is INVALID_HANDLE_VALUE.
860 PRTL_USER_PROCESS_PARAMETERS Ppb
= NtCurrentPeb()->ProcessParameters
;
861 HANDLE Handle
= INVALID_HANDLE_VALUE
;
865 case STD_INPUT_HANDLE
:
866 Handle
= Ppb
->StandardInput
;
869 case STD_OUTPUT_HANDLE
:
870 Handle
= Ppb
->StandardOutput
;
873 case STD_ERROR_HANDLE
:
874 Handle
= Ppb
->StandardError
;
878 /* If the returned handle is invalid, set last error */
879 if (Handle
== INVALID_HANDLE_VALUE
) SetLastError(ERROR_INVALID_HANDLE
);
890 SetStdHandle(DWORD nStdHandle
,
893 * FUNCTION: Set the handle for the standard input, standard output or
894 * the standard error device.
897 * nStdHandle - Specifies the handle to be set.
898 * hHandle - The handle to set.
900 * RETURNS: TRUE if the function succeeds, FALSE otherwise.
903 PRTL_USER_PROCESS_PARAMETERS Ppb
= NtCurrentPeb()->ProcessParameters
;
905 /* No need to check if hHandle == INVALID_HANDLE_VALUE */
909 case STD_INPUT_HANDLE
:
910 Ppb
->StandardInput
= hHandle
;
913 case STD_OUTPUT_HANDLE
:
914 Ppb
->StandardOutput
= hHandle
;
917 case STD_ERROR_HANDLE
:
918 Ppb
->StandardError
= hHandle
;
922 /* nStdHandle was invalid, bail out */
923 SetLastError(ERROR_INVALID_HANDLE
);
928 /*--------------------------------------------------------------
938 PRTL_USER_PROCESS_PARAMETERS Parameters
= NtCurrentPeb()->ProcessParameters
;
939 CONSOLE_API_MESSAGE ApiMessage
;
940 PCONSOLE_ALLOCCONSOLE AllocConsoleRequest
= &ApiMessage
.Data
.AllocConsoleRequest
;
941 PCSR_CAPTURE_BUFFER CaptureBuffer
;
943 if (Parameters
->ConsoleHandle
)
945 DPRINT1("AllocConsole: Allocating a console to a process already having one\n");
946 SetLastError(ERROR_ACCESS_DENIED
);
950 CaptureBuffer
= CsrAllocateCaptureBuffer(1, sizeof(CONSOLE_START_INFO
));
951 if (CaptureBuffer
== NULL
)
953 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
954 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
958 CsrAllocateMessagePointer(CaptureBuffer
,
959 sizeof(CONSOLE_START_INFO
),
960 (PVOID
*)&AllocConsoleRequest
->ConsoleStartInfo
);
962 InitConsoleInfo(AllocConsoleRequest
->ConsoleStartInfo
,
963 &Parameters
->ImagePathName
);
965 AllocConsoleRequest
->ConsoleHandle
= NULL
;
966 AllocConsoleRequest
->CtrlDispatcher
= ConsoleControlDispatcher
;
967 AllocConsoleRequest
->PropDispatcher
= PropDialogHandler
;
969 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
971 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepAlloc
),
972 sizeof(CONSOLE_ALLOCCONSOLE
));
974 CsrFreeCaptureBuffer(CaptureBuffer
);
976 if (!NT_SUCCESS(Status
))
978 BaseSetLastNTError(Status
);
982 Parameters
->ConsoleHandle
= AllocConsoleRequest
->ConsoleHandle
;
983 SetStdHandle(STD_INPUT_HANDLE
, AllocConsoleRequest
->InputHandle
);
984 SetStdHandle(STD_OUTPUT_HANDLE
, AllocConsoleRequest
->OutputHandle
);
985 SetStdHandle(STD_ERROR_HANDLE
, AllocConsoleRequest
->ErrorHandle
);
987 /* Initialize Console Ctrl Handler */
988 InitConsoleCtrlHandling();
990 InputWaitHandle
= AllocConsoleRequest
->InputWaitHandle
;
996 /*--------------------------------------------------------------
1005 // AG: I'm not sure if this is correct (what happens to std handles?)
1006 // but I just tried to reverse what AllocConsole() does...
1009 CONSOLE_API_MESSAGE ApiMessage
;
1011 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1013 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepFree
),
1014 sizeof(CONSOLE_FREECONSOLE
));
1015 if (!NT_SUCCESS(Status
))
1017 BaseSetLastNTError(Status
);
1021 NtCurrentPeb()->ProcessParameters
->ConsoleHandle
= NULL
;
1023 CloseHandle(InputWaitHandle
);
1024 InputWaitHandle
= INVALID_HANDLE_VALUE
;
1030 /*--------------------------------------------------------------
1031 * GetConsoleScreenBufferInfo
1037 GetConsoleScreenBufferInfo(HANDLE hConsoleOutput
,
1038 PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo
)
1040 CONSOLE_API_MESSAGE ApiMessage
;
1041 PCONSOLE_GETSCREENBUFFERINFO ScreenBufferInfoRequest
= &ApiMessage
.Data
.ScreenBufferInfoRequest
;
1043 if (lpConsoleScreenBufferInfo
== NULL
)
1045 SetLastError(ERROR_INVALID_PARAMETER
);
1049 ScreenBufferInfoRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1050 ScreenBufferInfoRequest
->OutputHandle
= hConsoleOutput
;
1052 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1054 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetScreenBufferInfo
),
1055 sizeof(*ScreenBufferInfoRequest
));
1056 if (!NT_SUCCESS(ApiMessage
.Status
))
1058 BaseSetLastNTError(ApiMessage
.Status
);
1062 lpConsoleScreenBufferInfo
->dwSize
= ScreenBufferInfoRequest
->ScreenBufferSize
;
1063 lpConsoleScreenBufferInfo
->dwCursorPosition
= ScreenBufferInfoRequest
->CursorPosition
;
1064 lpConsoleScreenBufferInfo
->wAttributes
= ScreenBufferInfoRequest
->Attributes
;
1065 lpConsoleScreenBufferInfo
->srWindow
.Left
= ScreenBufferInfoRequest
->ViewOrigin
.X
;
1066 lpConsoleScreenBufferInfo
->srWindow
.Top
= ScreenBufferInfoRequest
->ViewOrigin
.Y
;
1067 lpConsoleScreenBufferInfo
->srWindow
.Right
= ScreenBufferInfoRequest
->ViewOrigin
.X
+ ScreenBufferInfoRequest
->ViewSize
.X
- 1;
1068 lpConsoleScreenBufferInfo
->srWindow
.Bottom
= ScreenBufferInfoRequest
->ViewOrigin
.Y
+ ScreenBufferInfoRequest
->ViewSize
.Y
- 1;
1069 lpConsoleScreenBufferInfo
->dwMaximumWindowSize
= ScreenBufferInfoRequest
->MaximumViewSize
;
1075 /*--------------------------------------------------------------
1076 * SetConsoleCursorPosition
1082 SetConsoleCursorPosition(HANDLE hConsoleOutput
,
1083 COORD dwCursorPosition
)
1086 CONSOLE_API_MESSAGE ApiMessage
;
1088 ApiMessage
.Data
.SetCursorPositionRequest
.OutputHandle
= hConsoleOutput
;
1089 ApiMessage
.Data
.SetCursorPositionRequest
.Position
= dwCursorPosition
;
1091 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1093 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetCursorPosition
),
1094 sizeof(CONSOLE_SETCURSORPOSITION
));
1095 if (!NT_SUCCESS(Status
))
1097 BaseSetLastNTError(Status
);
1105 /*--------------------------------------------------------------
1112 GetConsoleMode(HANDLE hConsoleHandle
,
1116 CONSOLE_API_MESSAGE ApiMessage
;
1117 PCONSOLE_GETSETCONSOLEMODE ConsoleModeRequest
= &ApiMessage
.Data
.ConsoleModeRequest
;
1121 SetLastError(ERROR_INVALID_PARAMETER
);
1125 ConsoleModeRequest
->ConsoleHandle
= hConsoleHandle
;
1127 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1129 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetMode
),
1130 sizeof(CONSOLE_GETSETCONSOLEMODE
));
1131 if (!NT_SUCCESS(Status
))
1133 BaseSetLastNTError(Status
);
1137 *lpMode
= ConsoleModeRequest
->ConsoleMode
;
1143 /*--------------------------------------------------------------
1144 * GetNumberOfConsoleInputEvents
1150 GetNumberOfConsoleInputEvents(HANDLE hConsoleInput
,
1151 LPDWORD lpNumberOfEvents
)
1154 CONSOLE_API_MESSAGE ApiMessage
;
1155 PCONSOLE_GETNUMINPUTEVENTS GetNumInputEventsRequest
= &ApiMessage
.Data
.GetNumInputEventsRequest
;
1157 GetNumInputEventsRequest
->InputHandle
= hConsoleInput
;
1158 GetNumInputEventsRequest
->NumInputEvents
= 0;
1160 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1162 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetNumberOfInputEvents
),
1163 sizeof(CONSOLE_GETNUMINPUTEVENTS
));
1164 if (!NT_SUCCESS(Status
))
1166 BaseSetLastNTError(Status
);
1170 if (lpNumberOfEvents
== NULL
)
1172 SetLastError(ERROR_INVALID_ACCESS
);
1176 *lpNumberOfEvents
= GetNumInputEventsRequest
->NumInputEvents
;
1182 /*--------------------------------------------------------------
1183 * GetLargestConsoleWindowSize
1189 GetLargestConsoleWindowSize(HANDLE hConsoleOutput
)
1192 CONSOLE_API_MESSAGE ApiMessage
;
1193 PCONSOLE_GETLARGESTWINDOWSIZE GetLargestWindowSizeRequest
= &ApiMessage
.Data
.GetLargestWindowSizeRequest
;
1195 GetLargestWindowSizeRequest
->OutputHandle
= hConsoleOutput
;
1196 GetLargestWindowSizeRequest
->Size
.X
= 0;
1197 GetLargestWindowSizeRequest
->Size
.Y
= 0;
1199 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1201 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetLargestWindowSize
),
1202 sizeof(CONSOLE_GETLARGESTWINDOWSIZE
));
1203 if (!NT_SUCCESS(Status
))
1205 BaseSetLastNTError(Status
);
1208 DPRINT1("GetLargestConsoleWindowSize, X = %d, Y = %d\n", GetLargestWindowSizeRequest
->Size
.X
, GetLargestWindowSizeRequest
->Size
.Y
);
1209 return GetLargestWindowSizeRequest
->Size
;
1213 /*--------------------------------------------------------------
1214 * GetConsoleCursorInfo
1220 GetConsoleCursorInfo(HANDLE hConsoleOutput
,
1221 PCONSOLE_CURSOR_INFO lpConsoleCursorInfo
)
1224 CONSOLE_API_MESSAGE ApiMessage
;
1226 if (!lpConsoleCursorInfo
)
1228 if (!hConsoleOutput
)
1229 SetLastError(ERROR_INVALID_HANDLE
);
1231 SetLastError(ERROR_INVALID_ACCESS
);
1236 ApiMessage
.Data
.CursorInfoRequest
.OutputHandle
= hConsoleOutput
;
1238 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1240 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetCursorInfo
),
1241 sizeof(CONSOLE_GETSETCURSORINFO
));
1242 if (!NT_SUCCESS(Status
))
1244 BaseSetLastNTError(Status
);
1248 *lpConsoleCursorInfo
= ApiMessage
.Data
.CursorInfoRequest
.Info
;
1254 /*--------------------------------------------------------------
1255 * GetNumberOfConsoleMouseButtons
1261 GetNumberOfConsoleMouseButtons(LPDWORD lpNumberOfMouseButtons
)
1263 DPRINT1("GetNumberOfConsoleMouseButtons(0x%p) UNIMPLEMENTED!\n", lpNumberOfMouseButtons
);
1264 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1269 /*--------------------------------------------------------------
1276 SetConsoleMode(HANDLE hConsoleHandle
,
1280 CONSOLE_API_MESSAGE ApiMessage
;
1281 PCONSOLE_GETSETCONSOLEMODE ConsoleModeRequest
= &ApiMessage
.Data
.ConsoleModeRequest
;
1283 ConsoleModeRequest
->ConsoleHandle
= hConsoleHandle
;
1284 ConsoleModeRequest
->ConsoleMode
= dwMode
;
1286 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1288 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetMode
),
1289 sizeof(CONSOLE_GETSETCONSOLEMODE
));
1290 if (!NT_SUCCESS(Status
))
1292 BaseSetLastNTError(Status
);
1300 /*--------------------------------------------------------------
1301 * SetConsoleActiveScreenBuffer
1307 SetConsoleActiveScreenBuffer(HANDLE hConsoleOutput
)
1310 CONSOLE_API_MESSAGE ApiMessage
;
1312 ApiMessage
.Data
.SetScreenBufferRequest
.OutputHandle
= hConsoleOutput
;
1314 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1316 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetActiveScreenBuffer
),
1317 sizeof(CONSOLE_SETACTIVESCREENBUFFER
));
1318 if (!NT_SUCCESS(Status
))
1320 BaseSetLastNTError(Status
);
1328 /*--------------------------------------------------------------
1329 * FlushConsoleInputBuffer
1335 FlushConsoleInputBuffer(HANDLE hConsoleInput
)
1338 CONSOLE_API_MESSAGE ApiMessage
;
1340 ApiMessage
.Data
.FlushInputBufferRequest
.InputHandle
= hConsoleInput
;
1342 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1344 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepFlushInputBuffer
),
1345 sizeof(CONSOLE_FLUSHINPUTBUFFER
));
1346 if (!NT_SUCCESS(Status
))
1348 BaseSetLastNTError(Status
);
1356 /*--------------------------------------------------------------
1357 * SetConsoleScreenBufferSize
1363 SetConsoleScreenBufferSize(HANDLE hConsoleOutput
,
1367 CONSOLE_API_MESSAGE ApiMessage
;
1369 ApiMessage
.Data
.SetScreenBufferSizeRequest
.OutputHandle
= hConsoleOutput
;
1370 ApiMessage
.Data
.SetScreenBufferSizeRequest
.Size
= dwSize
;
1372 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1374 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetScreenBufferSize
),
1375 sizeof(CONSOLE_SETSCREENBUFFERSIZE
));
1376 if (!NT_SUCCESS(Status
))
1378 BaseSetLastNTError(Status
);
1386 /*--------------------------------------------------------------
1387 * SetConsoleCursorInfo
1393 SetConsoleCursorInfo(HANDLE hConsoleOutput
,
1394 CONST CONSOLE_CURSOR_INFO
*lpConsoleCursorInfo
)
1397 CONSOLE_API_MESSAGE ApiMessage
;
1399 ApiMessage
.Data
.CursorInfoRequest
.OutputHandle
= hConsoleOutput
;
1400 ApiMessage
.Data
.CursorInfoRequest
.Info
= *lpConsoleCursorInfo
;
1402 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1404 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetCursorInfo
),
1405 sizeof(CONSOLE_GETSETCURSORINFO
));
1406 if (!NT_SUCCESS(Status
))
1408 BaseSetLastNTError(Status
);
1418 IntScrollConsoleScreenBuffer(HANDLE hConsoleOutput
,
1419 const SMALL_RECT
*lpScrollRectangle
,
1420 const SMALL_RECT
*lpClipRectangle
,
1421 COORD dwDestinationOrigin
,
1422 const CHAR_INFO
*lpFill
,
1426 CONSOLE_API_MESSAGE ApiMessage
;
1427 PCONSOLE_SCROLLSCREENBUFFER ScrollScreenBufferRequest
= &ApiMessage
.Data
.ScrollScreenBufferRequest
;
1429 ScrollScreenBufferRequest
->OutputHandle
= hConsoleOutput
;
1430 ScrollScreenBufferRequest
->Unicode
= bUnicode
;
1431 ScrollScreenBufferRequest
->ScrollRectangle
= *lpScrollRectangle
;
1433 if (lpClipRectangle
!= NULL
)
1435 ScrollScreenBufferRequest
->UseClipRectangle
= TRUE
;
1436 ScrollScreenBufferRequest
->ClipRectangle
= *lpClipRectangle
;
1440 ScrollScreenBufferRequest
->UseClipRectangle
= FALSE
;
1443 ScrollScreenBufferRequest
->DestinationOrigin
= dwDestinationOrigin
;
1444 ScrollScreenBufferRequest
->Fill
= *lpFill
;
1446 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1448 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepScrollScreenBuffer
),
1449 sizeof(CONSOLE_SCROLLSCREENBUFFER
));
1451 if (!NT_SUCCESS(Status
))
1453 BaseSetLastNTError(Status
);
1461 /*--------------------------------------------------------------
1462 * ScrollConsoleScreenBufferA
1468 ScrollConsoleScreenBufferA(HANDLE hConsoleOutput
,
1469 CONST SMALL_RECT
*lpScrollRectangle
,
1470 CONST SMALL_RECT
*lpClipRectangle
,
1471 COORD dwDestinationOrigin
,
1472 CONST CHAR_INFO
*lpFill
)
1474 return IntScrollConsoleScreenBuffer(hConsoleOutput
,
1475 (PSMALL_RECT
)lpScrollRectangle
,
1476 (PSMALL_RECT
)lpClipRectangle
,
1477 dwDestinationOrigin
,
1483 /*--------------------------------------------------------------
1484 * ScrollConsoleScreenBufferW
1490 ScrollConsoleScreenBufferW(HANDLE hConsoleOutput
,
1491 CONST SMALL_RECT
*lpScrollRectangle
,
1492 CONST SMALL_RECT
*lpClipRectangle
,
1493 COORD dwDestinationOrigin
,
1494 CONST CHAR_INFO
*lpFill
)
1496 return IntScrollConsoleScreenBuffer(hConsoleOutput
,
1499 dwDestinationOrigin
,
1505 /*--------------------------------------------------------------
1506 * SetConsoleWindowInfo
1512 SetConsoleWindowInfo(HANDLE hConsoleOutput
,
1514 CONST SMALL_RECT
*lpConsoleWindow
)
1517 CONSOLE_API_MESSAGE ApiMessage
;
1518 PCONSOLE_SETWINDOWINFO SetWindowInfoRequest
= &ApiMessage
.Data
.SetWindowInfoRequest
;
1520 if (lpConsoleWindow
== NULL
)
1522 SetLastError(ERROR_INVALID_PARAMETER
);
1526 SetWindowInfoRequest
->OutputHandle
= hConsoleOutput
;
1527 SetWindowInfoRequest
->Absolute
= bAbsolute
;
1528 SetWindowInfoRequest
->WindowRect
= *lpConsoleWindow
;
1530 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1532 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetWindowInfo
),
1533 sizeof(CONSOLE_SETWINDOWINFO
));
1534 if (!NT_SUCCESS(Status
))
1536 BaseSetLastNTError(Status
);
1544 /*--------------------------------------------------------------
1545 * SetConsoleTextAttribute
1551 SetConsoleTextAttribute(HANDLE hConsoleOutput
,
1555 CONSOLE_API_MESSAGE ApiMessage
;
1557 ApiMessage
.Data
.SetTextAttribRequest
.OutputHandle
= hConsoleOutput
;
1558 ApiMessage
.Data
.SetTextAttribRequest
.Attrib
= wAttributes
;
1560 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1562 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetTextAttribute
),
1563 sizeof(CONSOLE_SETTEXTATTRIB
));
1564 if (!NT_SUCCESS(Status
))
1566 BaseSetLastNTError(Status
);
1576 AddConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine
)
1578 PHANDLER_ROUTINE
* NewCtrlHandlers
= NULL
;
1580 if (HandlerRoutine
== NULL
)
1582 NtCurrentPeb()->ProcessParameters
->ConsoleFlags
= TRUE
;
1586 if (NrCtrlHandlers
== NrAllocatedHandlers
)
1588 NewCtrlHandlers
= RtlAllocateHeap(RtlGetProcessHeap(),
1590 (NrCtrlHandlers
+ 4) * sizeof(PHANDLER_ROUTINE
));
1591 if (NewCtrlHandlers
== NULL
)
1593 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1597 memmove(NewCtrlHandlers
, CtrlHandlers
, sizeof(PHANDLER_ROUTINE
) * NrCtrlHandlers
);
1599 if (NrAllocatedHandlers
> 1) RtlFreeHeap(RtlGetProcessHeap(), 0, CtrlHandlers
);
1601 CtrlHandlers
= NewCtrlHandlers
;
1602 NrAllocatedHandlers
+= 4;
1605 ASSERT(NrCtrlHandlers
< NrAllocatedHandlers
);
1607 CtrlHandlers
[NrCtrlHandlers
++] = HandlerRoutine
;
1614 RemoveConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine
)
1618 if (HandlerRoutine
== NULL
)
1620 NtCurrentPeb()->ProcessParameters
->ConsoleFlags
= FALSE
;
1624 for (i
= 0; i
< NrCtrlHandlers
; i
++)
1626 if (CtrlHandlers
[i
] == HandlerRoutine
)
1628 if (i
< (NrCtrlHandlers
- 1))
1630 memmove(&CtrlHandlers
[i
],
1632 (NrCtrlHandlers
- i
+ 1) * sizeof(PHANDLER_ROUTINE
));
1640 SetLastError(ERROR_INVALID_PARAMETER
);
1650 SetConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine
,
1655 RtlEnterCriticalSection(&BaseDllDirectoryLock
);
1658 Ret
= AddConsoleCtrlHandler(HandlerRoutine
);
1662 Ret
= RemoveConsoleCtrlHandler(HandlerRoutine
);
1665 RtlLeaveCriticalSection(&BaseDllDirectoryLock
);
1670 /*--------------------------------------------------------------
1671 * GenerateConsoleCtrlEvent
1677 GenerateConsoleCtrlEvent(DWORD dwCtrlEvent
,
1678 DWORD dwProcessGroupId
)
1681 CONSOLE_API_MESSAGE ApiMessage
;
1683 if (dwCtrlEvent
!= CTRL_C_EVENT
&& dwCtrlEvent
!= CTRL_BREAK_EVENT
)
1685 SetLastError(ERROR_INVALID_PARAMETER
);
1689 ApiMessage
.Data
.GenerateCtrlEventRequest
.Event
= dwCtrlEvent
;
1690 ApiMessage
.Data
.GenerateCtrlEventRequest
.ProcessGroup
= dwProcessGroupId
;
1692 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1694 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGenerateCtrlEvent
),
1695 sizeof(CONSOLE_GENERATECTRLEVENT
));
1696 if (!NT_SUCCESS(Status
))
1698 BaseSetLastNTError(Status
);
1707 IntGetConsoleTitle(LPVOID lpConsoleTitle
, DWORD nSize
, BOOL bUnicode
)
1710 CONSOLE_API_MESSAGE ApiMessage
;
1711 PCONSOLE_GETSETCONSOLETITLE TitleRequest
= &ApiMessage
.Data
.TitleRequest
;
1712 PCSR_CAPTURE_BUFFER CaptureBuffer
;
1714 if (nSize
== 0) return 0;
1716 TitleRequest
->Length
= nSize
* (bUnicode
? 1 : sizeof(WCHAR
));
1717 CaptureBuffer
= CsrAllocateCaptureBuffer(1, TitleRequest
->Length
);
1718 if (CaptureBuffer
== NULL
)
1720 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
1721 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1725 CsrAllocateMessagePointer(CaptureBuffer
,
1726 TitleRequest
->Length
,
1727 (PVOID
*)&TitleRequest
->Title
);
1729 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1731 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetTitle
),
1732 sizeof(CONSOLE_GETSETCONSOLETITLE
));
1733 if (!NT_SUCCESS(Status
))
1735 CsrFreeCaptureBuffer(CaptureBuffer
);
1736 BaseSetLastNTError(Status
);
1742 if (nSize
>= sizeof(WCHAR
))
1743 wcscpy((LPWSTR
)lpConsoleTitle
, TitleRequest
->Title
);
1747 if (nSize
< TitleRequest
->Length
/ sizeof(WCHAR
) ||
1748 !WideCharToMultiByte(CP_ACP
, // ANSI code page
1749 0, // performance and mapping flags
1750 TitleRequest
->Title
, // address of wide-character string
1751 -1, // number of characters in string
1752 (LPSTR
)lpConsoleTitle
, // address of buffer for new string
1753 nSize
, // size of buffer
1757 /* Yes, if the buffer isn't big enough, it returns 0... Bad API */
1758 *(LPSTR
)lpConsoleTitle
= '\0';
1759 TitleRequest
->Length
= 0;
1762 CsrFreeCaptureBuffer(CaptureBuffer
);
1764 return TitleRequest
->Length
/ sizeof(WCHAR
);
1768 /*--------------------------------------------------------------
1775 GetConsoleTitleW(LPWSTR lpConsoleTitle
,
1778 return IntGetConsoleTitle(lpConsoleTitle
, nSize
, TRUE
);
1782 /*--------------------------------------------------------------
1789 GetConsoleTitleA(LPSTR lpConsoleTitle
,
1792 return IntGetConsoleTitle(lpConsoleTitle
, nSize
, FALSE
);
1796 /*--------------------------------------------------------------
1803 SetConsoleTitleW(LPCWSTR lpConsoleTitle
)
1806 CONSOLE_API_MESSAGE ApiMessage
;
1807 PCONSOLE_GETSETCONSOLETITLE TitleRequest
= &ApiMessage
.Data
.TitleRequest
;
1808 PCSR_CAPTURE_BUFFER CaptureBuffer
;
1810 TitleRequest
->Length
= wcslen(lpConsoleTitle
) * sizeof(WCHAR
);
1812 CaptureBuffer
= CsrAllocateCaptureBuffer(1, TitleRequest
->Length
);
1813 if (CaptureBuffer
== NULL
)
1815 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
1816 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1820 CsrCaptureMessageBuffer(CaptureBuffer
,
1821 (PVOID
)lpConsoleTitle
,
1822 TitleRequest
->Length
,
1823 (PVOID
*)&TitleRequest
->Title
);
1825 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1827 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetTitle
),
1828 sizeof(CONSOLE_GETSETCONSOLETITLE
));
1830 CsrFreeCaptureBuffer(CaptureBuffer
);
1832 if (!NT_SUCCESS(Status
))
1834 BaseSetLastNTError(Status
);
1842 /*--------------------------------------------------------------
1849 SetConsoleTitleA(LPCSTR lpConsoleTitle
)
1852 ULONG Length
= strlen(lpConsoleTitle
) + 1;
1853 LPWSTR WideTitle
= HeapAlloc(GetProcessHeap(), 0, Length
* sizeof(WCHAR
));
1857 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1861 MultiByteToWideChar(CP_ACP
, 0, lpConsoleTitle
, -1, WideTitle
, Length
);
1863 Ret
= SetConsoleTitleW(WideTitle
);
1865 HeapFree(GetProcessHeap(), 0, WideTitle
);
1870 /*--------------------------------------------------------------
1871 * CreateConsoleScreenBuffer
1877 CreateConsoleScreenBuffer(DWORD dwDesiredAccess
,
1879 CONST SECURITY_ATTRIBUTES
*lpSecurityAttributes
,
1881 LPVOID lpScreenBufferData
)
1884 CONSOLE_API_MESSAGE ApiMessage
;
1885 PCONSOLE_CREATESCREENBUFFER CreateScreenBufferRequest
= &ApiMessage
.Data
.CreateScreenBufferRequest
;
1886 PCSR_CAPTURE_BUFFER CaptureBuffer
= NULL
;
1887 PCONSOLE_GRAPHICS_BUFFER_INFO GraphicsBufferInfo
= /*(PCONSOLE_GRAPHICS_BUFFER_INFO)*/lpScreenBufferData
;
1889 if ( (dwDesiredAccess
& ~(GENERIC_READ
| GENERIC_WRITE
)) ||
1890 (dwShareMode
& ~(FILE_SHARE_READ
| FILE_SHARE_WRITE
)) ||
1891 (dwFlags
!= CONSOLE_TEXTMODE_BUFFER
&& dwFlags
!= CONSOLE_GRAPHICS_BUFFER
) )
1893 SetLastError(ERROR_INVALID_PARAMETER
);
1894 return INVALID_HANDLE_VALUE
;
1897 CreateScreenBufferRequest
->ScreenBufferType
= dwFlags
;
1898 CreateScreenBufferRequest
->Access
= dwDesiredAccess
;
1899 CreateScreenBufferRequest
->ShareMode
= dwShareMode
;
1900 CreateScreenBufferRequest
->Inheritable
=
1901 (lpSecurityAttributes
? lpSecurityAttributes
->bInheritHandle
: FALSE
);
1903 if (dwFlags
== CONSOLE_GRAPHICS_BUFFER
)
1905 if (CreateScreenBufferRequest
->Inheritable
|| GraphicsBufferInfo
== NULL
)
1907 SetLastError(ERROR_INVALID_PARAMETER
);
1908 return INVALID_HANDLE_VALUE
;
1911 CreateScreenBufferRequest
->GraphicsBufferInfo
= *GraphicsBufferInfo
;
1913 CaptureBuffer
= CsrAllocateCaptureBuffer(1, GraphicsBufferInfo
->dwBitMapInfoLength
);
1914 if (CaptureBuffer
== NULL
)
1916 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1920 CsrCaptureMessageBuffer(CaptureBuffer
,
1921 (PVOID
)GraphicsBufferInfo
->lpBitMapInfo
,
1922 GraphicsBufferInfo
->dwBitMapInfoLength
,
1923 (PVOID
*)&CreateScreenBufferRequest
->GraphicsBufferInfo
.lpBitMapInfo
);
1926 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1928 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepCreateScreenBuffer
),
1929 sizeof(CONSOLE_CREATESCREENBUFFER
));
1932 CsrFreeCaptureBuffer(CaptureBuffer
);
1934 if (!NT_SUCCESS(Status
))
1936 BaseSetLastNTError(Status
);
1937 return INVALID_HANDLE_VALUE
;
1940 if (dwFlags
== CONSOLE_GRAPHICS_BUFFER
&& GraphicsBufferInfo
)
1942 GraphicsBufferInfo
->hMutex
= CreateScreenBufferRequest
->GraphicsBufferInfo
.hMutex
;
1943 GraphicsBufferInfo
->lpBitMap
= CreateScreenBufferRequest
->GraphicsBufferInfo
.lpBitMap
;
1946 return CreateScreenBufferRequest
->OutputHandle
;
1950 /*--------------------------------------------------------------
1959 CONSOLE_API_MESSAGE ApiMessage
;
1960 PCONSOLE_GETINPUTOUTPUTCP GetConsoleCPRequest
= &ApiMessage
.Data
.GetConsoleCPRequest
;
1962 /* Get the Input Code Page */
1963 GetConsoleCPRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1964 GetConsoleCPRequest
->OutputCP
= FALSE
;
1966 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1968 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetCP
),
1969 sizeof(*GetConsoleCPRequest
));
1970 if (!NT_SUCCESS(ApiMessage
.Status
))
1972 BaseSetLastNTError(ApiMessage
.Status
);
1976 return GetConsoleCPRequest
->CodePage
;
1980 /*--------------------------------------------------------------
1987 SetConsoleCP(UINT wCodePageID
)
1989 CONSOLE_API_MESSAGE ApiMessage
;
1990 PCONSOLE_SETINPUTOUTPUTCP SetConsoleCPRequest
= &ApiMessage
.Data
.SetConsoleCPRequest
;
1992 /* Set the Input Code Page */
1993 SetConsoleCPRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
1994 SetConsoleCPRequest
->CodePage
= wCodePageID
;
1995 SetConsoleCPRequest
->OutputCP
= FALSE
;
1996 /* SetConsoleCPRequest->EventHandle; */
1998 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2000 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetCP
),
2001 sizeof(*SetConsoleCPRequest
));
2002 if (!NT_SUCCESS(ApiMessage
.Status
))
2004 BaseSetLastNTError(ApiMessage
.Status
);
2012 /*--------------------------------------------------------------
2013 * GetConsoleOutputCP
2019 GetConsoleOutputCP(VOID
)
2021 CONSOLE_API_MESSAGE ApiMessage
;
2022 PCONSOLE_GETINPUTOUTPUTCP GetConsoleCPRequest
= &ApiMessage
.Data
.GetConsoleCPRequest
;
2024 /* Get the Output Code Page */
2025 GetConsoleCPRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
2026 GetConsoleCPRequest
->OutputCP
= TRUE
;
2028 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2030 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetCP
),
2031 sizeof(*GetConsoleCPRequest
));
2032 if (!NT_SUCCESS(ApiMessage
.Status
))
2034 BaseSetLastNTError(ApiMessage
.Status
);
2038 return GetConsoleCPRequest
->CodePage
;
2042 /*--------------------------------------------------------------
2043 * SetConsoleOutputCP
2049 SetConsoleOutputCP(UINT wCodePageID
)
2051 CONSOLE_API_MESSAGE ApiMessage
;
2052 PCONSOLE_SETINPUTOUTPUTCP SetConsoleCPRequest
= &ApiMessage
.Data
.SetConsoleCPRequest
;
2054 /* Set the Output Code Page */
2055 SetConsoleCPRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
2056 SetConsoleCPRequest
->CodePage
= wCodePageID
;
2057 SetConsoleCPRequest
->OutputCP
= TRUE
;
2058 /* SetConsoleCPRequest->EventHandle; */
2060 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2062 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetCP
),
2063 sizeof(*SetConsoleCPRequest
));
2064 if (!NT_SUCCESS(ApiMessage
.Status
))
2066 BaseSetLastNTError(ApiMessage
.Status
);
2074 /*--------------------------------------------------------------
2075 * GetConsoleProcessList
2081 GetConsoleProcessList(LPDWORD lpdwProcessList
,
2082 DWORD dwProcessCount
)
2084 CONSOLE_API_MESSAGE ApiMessage
;
2085 PCONSOLE_GETPROCESSLIST GetProcessListRequest
= &ApiMessage
.Data
.GetProcessListRequest
;
2086 PCSR_CAPTURE_BUFFER CaptureBuffer
;
2087 ULONG nProcesses
= 0;
2089 if (lpdwProcessList
== NULL
|| dwProcessCount
== 0)
2091 SetLastError(ERROR_INVALID_PARAMETER
);
2095 CaptureBuffer
= CsrAllocateCaptureBuffer(1, dwProcessCount
* sizeof(DWORD
));
2096 if (CaptureBuffer
== NULL
)
2098 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
2099 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2103 GetProcessListRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
2104 GetProcessListRequest
->ProcessCount
= dwProcessCount
;
2106 CsrAllocateMessagePointer(CaptureBuffer
,
2107 dwProcessCount
* sizeof(DWORD
),
2108 (PVOID
*)&GetProcessListRequest
->ProcessIdsList
);
2110 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2112 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetProcessList
),
2113 sizeof(*GetProcessListRequest
));
2114 if (!NT_SUCCESS(ApiMessage
.Status
))
2116 BaseSetLastNTError(ApiMessage
.Status
);
2120 nProcesses
= GetProcessListRequest
->ProcessCount
;
2121 if (dwProcessCount
>= nProcesses
)
2123 memcpy(lpdwProcessList
, GetProcessListRequest
->ProcessIdsList
, nProcesses
* sizeof(DWORD
));
2127 CsrFreeCaptureBuffer(CaptureBuffer
);
2132 /*--------------------------------------------------------------
2133 * GetConsoleSelectionInfo
2139 GetConsoleSelectionInfo(PCONSOLE_SELECTION_INFO lpConsoleSelectionInfo
)
2141 CONSOLE_API_MESSAGE ApiMessage
;
2142 PCONSOLE_GETSELECTIONINFO GetSelectionInfoRequest
= &ApiMessage
.Data
.GetSelectionInfoRequest
;
2144 if (lpConsoleSelectionInfo
== NULL
)
2146 SetLastError(ERROR_INVALID_PARAMETER
);
2150 GetSelectionInfoRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
2152 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2154 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetSelectionInfo
),
2155 sizeof(*GetSelectionInfoRequest
));
2156 if (!NT_SUCCESS(ApiMessage
.Status
))
2158 BaseSetLastNTError(ApiMessage
.Status
);
2162 *lpConsoleSelectionInfo
= GetSelectionInfoRequest
->Info
;
2167 /*--------------------------------------------------------------
2172 * @note Strongly inspired by AllocConsole.
2176 AttachConsole(DWORD dwProcessId
)
2179 PRTL_USER_PROCESS_PARAMETERS Parameters
= NtCurrentPeb()->ProcessParameters
;
2180 CONSOLE_API_MESSAGE ApiMessage
;
2181 PCONSOLE_ATTACHCONSOLE AttachConsoleRequest
= &ApiMessage
.Data
.AttachConsoleRequest
;
2183 if (Parameters
->ConsoleHandle
)
2185 DPRINT1("AttachConsole: Attaching a console to a process already having one\n");
2186 SetLastError(ERROR_ACCESS_DENIED
);
2190 AttachConsoleRequest
->ProcessId
= dwProcessId
;
2191 AttachConsoleRequest
->CtrlDispatcher
= ConsoleControlDispatcher
;
2192 AttachConsoleRequest
->PropDispatcher
= PropDialogHandler
;
2194 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2196 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepAttach
),
2197 sizeof(CONSOLE_ATTACHCONSOLE
));
2198 if (!NT_SUCCESS(Status
))
2200 BaseSetLastNTError(Status
);
2204 Parameters
->ConsoleHandle
= AttachConsoleRequest
->ConsoleHandle
;
2205 SetStdHandle(STD_INPUT_HANDLE
, AttachConsoleRequest
->InputHandle
);
2206 SetStdHandle(STD_OUTPUT_HANDLE
, AttachConsoleRequest
->OutputHandle
);
2207 SetStdHandle(STD_ERROR_HANDLE
, AttachConsoleRequest
->ErrorHandle
);
2209 /* Initialize Console Ctrl Handler */
2210 InitConsoleCtrlHandling();
2212 InputWaitHandle
= AttachConsoleRequest
->InputWaitHandle
;
2218 /*--------------------------------------------------------------
2225 GetConsoleWindow(VOID
)
2227 CONSOLE_API_MESSAGE ApiMessage
;
2228 PCONSOLE_GETWINDOW GetWindowRequest
= &ApiMessage
.Data
.GetWindowRequest
;
2230 GetWindowRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
2232 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2234 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetConsoleWindow
),
2235 sizeof(*GetWindowRequest
));
2236 if (!NT_SUCCESS(ApiMessage
.Status
))
2238 BaseSetLastNTError(ApiMessage
.Status
);
2242 return GetWindowRequest
->WindowHandle
;
2246 /*--------------------------------------------------------------
2253 SetConsoleIcon(HICON hIcon
)
2255 CONSOLE_API_MESSAGE ApiMessage
;
2256 PCONSOLE_SETICON SetIconRequest
= &ApiMessage
.Data
.SetIconRequest
;
2258 SetIconRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
2259 SetIconRequest
->IconHandle
= hIcon
;
2261 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2263 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetIcon
),
2264 sizeof(*SetIconRequest
));
2265 if (!NT_SUCCESS(ApiMessage
.Status
))
2267 BaseSetLastNTError(ApiMessage
.Status
);
2275 /******************************************************************************
2276 * \name SetConsoleInputExeNameW
2277 * \brief Sets the console input file name from a unicode string.
2278 * \param lpInputExeName Pointer to a unicode string with the name.
2279 * \return TRUE if successful, FALSE if unsuccsedful.
2280 * \remarks If lpInputExeName is 0 or the string length is 0 or greater than 255,
2281 * the function fails and sets last error to ERROR_INVALID_PARAMETER.
2285 SetConsoleInputExeNameW(LPCWSTR lpInputExeName
)
2289 if ( !lpInputExeName
||
2290 (lenName
= lstrlenW(lpInputExeName
)) == 0 ||
2291 lenName
> INPUTEXENAME_BUFLEN
- 1 )
2293 /* Fail if string is empty or too long */
2294 SetLastError(ERROR_INVALID_PARAMETER
);
2298 RtlEnterCriticalSection(&ConsoleLock
);
2301 RtlCopyMemory(InputExeName
, lpInputExeName
, lenName
* sizeof(WCHAR
));
2302 InputExeName
[lenName
] = L
'\0';
2306 RtlLeaveCriticalSection(&ConsoleLock
);
2314 /******************************************************************************
2315 * \name SetConsoleInputExeNameA
2316 * \brief Sets the console input file name from an ansi string.
2317 * \param lpInputExeName Pointer to an ansi string with the name.
2318 * \return TRUE if successful, FALSE if unsuccsedful.
2319 * \remarks If lpInputExeName is 0 or the string length is 0 or greater than 255,
2320 * the function fails and sets last error to ERROR_INVALID_PARAMETER.
2324 SetConsoleInputExeNameA(LPCSTR lpInputExeName
)
2326 WCHAR Buffer
[INPUTEXENAME_BUFLEN
];
2327 ANSI_STRING InputExeNameA
;
2328 UNICODE_STRING InputExeNameU
;
2331 RtlInitAnsiString(&InputExeNameA
, lpInputExeName
);
2333 if ( InputExeNameA
.Length
== 0 ||
2334 InputExeNameA
.Length
> INPUTEXENAME_BUFLEN
- 1 )
2336 /* Fail if string is empty or too long */
2337 SetLastError(ERROR_INVALID_PARAMETER
);
2341 InputExeNameU
.Buffer
= Buffer
;
2342 InputExeNameU
.MaximumLength
= sizeof(Buffer
);
2343 InputExeNameU
.Length
= 0;
2345 Status
= RtlAnsiStringToUnicodeString(&InputExeNameU
, &InputExeNameA
, FALSE
);
2346 if (!NT_SUCCESS(Status
))
2348 BaseSetLastNTError(Status
);
2352 return SetConsoleInputExeNameW(InputExeNameU
.Buffer
);
2356 /******************************************************************************
2357 * \name GetConsoleInputExeNameW
2358 * \brief Retrieves the console input file name as unicode string.
2359 * \param nBufferLength Length of the buffer in WCHARs.
2360 * Specify 0 to receive the needed buffer length.
2361 * \param lpBuffer Pointer to a buffer that receives the string.
2362 * \return Needed buffer size if \p nBufferLength is 0.
2363 * Otherwise 1 if successful, 2 if buffer is too small.
2364 * \remarks Sets last error value to ERROR_BUFFER_OVERFLOW if the buffer
2365 * is not big enough.
2369 GetConsoleInputExeNameW(DWORD nBufferLength
, LPWSTR lpBuffer
)
2371 ULONG lenName
= lstrlenW(InputExeName
);
2373 if (nBufferLength
== 0)
2375 /* Buffer size is requested, return it */
2379 if (lenName
+ 1 > nBufferLength
)
2381 /* Buffer is not large enough! */
2382 SetLastError(ERROR_BUFFER_OVERFLOW
);
2386 RtlEnterCriticalSection(&ConsoleLock
);
2389 RtlCopyMemory(lpBuffer
, InputExeName
, lenName
* sizeof(WCHAR
));
2390 lpBuffer
[lenName
] = '\0';
2394 RtlLeaveCriticalSection(&ConsoleLock
);
2398 /* Success, return 1 */
2403 /******************************************************************************
2404 * \name GetConsoleInputExeNameA
2405 * \brief Retrieves the console input file name as ansi string.
2406 * \param nBufferLength Length of the buffer in CHARs.
2407 * \param lpBuffer Pointer to a buffer that receives the string.
2408 * \return 1 if successful, 2 if buffer is too small.
2409 * \remarks Sets last error value to ERROR_BUFFER_OVERFLOW if the buffer
2410 * is not big enough. The buffer receives as much characters as fit.
2414 GetConsoleInputExeNameA(DWORD nBufferLength
, LPSTR lpBuffer
)
2416 WCHAR Buffer
[INPUTEXENAME_BUFLEN
];
2418 UNICODE_STRING BufferU
;
2419 ANSI_STRING BufferA
;
2421 /* Get the unicode name */
2422 Ret
= GetConsoleInputExeNameW(sizeof(Buffer
) / sizeof(Buffer
[0]), Buffer
);
2424 /* Initialize strings for conversion */
2425 RtlInitUnicodeString(&BufferU
, Buffer
);
2427 BufferA
.MaximumLength
= (USHORT
)nBufferLength
;
2428 BufferA
.Buffer
= lpBuffer
;
2430 /* Convert unicode name to ansi, copying as much chars as fit */
2431 RtlUnicodeStringToAnsiString(&BufferA
, &BufferU
, FALSE
);
2433 /* Error handling */
2434 if (nBufferLength
<= BufferU
.Length
/ sizeof(WCHAR
))
2436 SetLastError(ERROR_BUFFER_OVERFLOW
);
2445 GetConsoleCharType(HANDLE hConsole
, COORD Coord
, PDWORD Type
)
2453 GetConsoleCursorMode(HANDLE hConsole
, PBOOL pUnknown1
, PBOOL pUnknown2
)
2461 GetConsoleNlsMode(HANDLE hConsole
, LPDWORD lpMode
)
2469 SetConsoleCursorMode(HANDLE hConsole
, BOOL Unknown1
, BOOL Unknown2
)
2477 SetConsoleLocalEUDC(DWORD Unknown1
, DWORD Unknown2
, DWORD Unknown3
, DWORD Unknown4
)
2485 SetConsoleNlsMode(HANDLE hConsole
, DWORD dwMode
)
2493 RegisterConsoleIME(HWND hWnd
, LPDWORD ThreadId
)
2501 RegisterConsoleOS2(BOOL bUnknown
)
2509 SetConsoleOS2OemFormat(BOOL bUnknown
)
2517 UnregisterConsoleIME(VOID
)
2527 BOOL WINAPI
GetConsoleKeyboardLayoutNameA(LPSTR name
)
2536 BOOL WINAPI
GetConsoleKeyboardLayoutNameW(LPWSTR name
)
2547 SetLastConsoleEventActive(VOID
)