1 /* $Id: console.c,v 1.88 2004/12/21 21:38:25 weiden Exp $
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: lib/kernel32/misc/console.c
6 * PURPOSE: Win32 server console functions
7 * PROGRAMMER: James Tabor
8 * <jimtabor@adsl-64-217-116-74.dsl.hstntx.swbell.net>
11 * 19990204 EA SetConsoleTitleA
15 /* INCLUDES ******************************************************************/
20 #include "../include/debug.h"
22 extern BOOL WINAPI
DefaultConsoleCtrlHandler(DWORD Event
);
23 extern __declspec(noreturn
) VOID CALLBACK
ConsoleControlDispatcher(DWORD CodeAndFlag
);
24 extern CRITICAL_SECTION ConsoleLock
;
25 extern BOOL WINAPI
IsDebuggerPresent(VOID
);
28 /* GLOBALS *******************************************************************/
30 static BOOL IgnoreCtrlEvents
= FALSE
;
32 static PHANDLER_ROUTINE
* CtrlHandlers
= NULL
;
33 static ULONG NrCtrlHandlers
= 0;
34 static WCHAR InputExeName
[MAX_PATH
+ 1] = L
"";
36 /* Default Console Control Handler *******************************************/
38 BOOL WINAPI
DefaultConsoleCtrlHandler(DWORD Event
)
43 DPRINT("Ctrl-C Event\n");
46 case CTRL_BREAK_EVENT
:
47 DPRINT("Ctrl-Break Event\n");
50 case CTRL_SHUTDOWN_EVENT
:
51 DPRINT("Ctrl Shutdown Event\n");
54 case CTRL_CLOSE_EVENT
:
55 DPRINT("Ctrl Close Event\n");
58 case CTRL_LOGOFF_EVENT
:
59 DPRINT("Ctrl Logoff Event\n");
67 __declspec(noreturn
) VOID CALLBACK
ConsoleControlDispatcher(DWORD CodeAndFlag
)
70 DWORD nCode
= CodeAndFlag
& MAXLONG
;
73 SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST
);
78 case CTRL_BREAK_EVENT
:
80 if(IsDebuggerPresent())
82 EXCEPTION_RECORD erException
;
83 erException
.ExceptionCode
=
84 (nCode
== CTRL_C_EVENT
? DBG_CONTROL_C
: DBG_CONTROL_BREAK
);
85 erException
.ExceptionFlags
= 0;
86 erException
.ExceptionRecord
= NULL
;
87 erException
.ExceptionAddress
= &DefaultConsoleCtrlHandler
;
88 erException
.NumberParameters
= 0;
89 RtlRaiseException(&erException
);
91 RtlEnterCriticalSection(&ConsoleLock
);
93 if(!(nCode
== CTRL_C_EVENT
&&
94 NtCurrentPeb()->ProcessParameters
->ProcessGroup
& 1))
96 for(i
= NrCtrlHandlers
; i
> 0; -- i
)
97 if(CtrlHandlers
[i
- 1](nCode
)) break;
99 RtlLeaveCriticalSection(&ConsoleLock
);
102 case CTRL_CLOSE_EVENT
:
103 case CTRL_LOGOFF_EVENT
:
104 case CTRL_SHUTDOWN_EVENT
:
107 default: ExitThread(0);
110 RtlEnterCriticalSection(&ConsoleLock
);
112 if(!(nCode
== CTRL_C_EVENT
&&
113 NtCurrentPeb()->ProcessParameters
->ProcessGroup
& 1))
118 if (i
== 1 && (CodeAndFlag
& MINLONG
) &&
119 (nCode
== CTRL_LOGOFF_EVENT
|| nCode
== CTRL_SHUTDOWN_EVENT
))
122 if(CtrlHandlers
[i
- 1](nCode
))
126 case CTRL_CLOSE_EVENT
:
127 case CTRL_LOGOFF_EVENT
:
128 case CTRL_SHUTDOWN_EVENT
:
129 nExitCode
= CodeAndFlag
;
136 RtlLeaveCriticalSection(&ConsoleLock
);
137 ExitThread(nExitCode
);
141 /* FUNCTIONS *****************************************************************/
147 AddConsoleAliasA (LPSTR Source
,
151 DPRINT1("AddConsoleAliasA(0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Source
, Target
, ExeName
);
152 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
161 AddConsoleAliasW (LPWSTR Source
,
165 DPRINT1("AddConsoleAliasW(0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Source
, Target
, ExeName
);
166 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
175 ConsoleMenuControl (HANDLE hConsole
,
182 DPRINT1("ConsoleMenuControl(0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", hConsole
, Unknown1
, Unknown2
);
183 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
192 DuplicateConsoleHandle (HANDLE hConsole
,
193 DWORD dwDesiredAccess
,
197 CSRSS_API_REQUEST Request
;
198 CSRSS_API_REPLY Reply
;
201 if (IsConsoleHandle (hConsole
) == FALSE
)
203 SetLastError (ERROR_INVALID_PARAMETER
);
204 return INVALID_HANDLE_VALUE
;
207 Request
.Type
= CSRSS_DUPLICATE_HANDLE
;
208 Request
.Data
.DuplicateHandleRequest
.Handle
= hConsole
;
209 Request
.Data
.DuplicateHandleRequest
.ProcessId
= GetCurrentProcessId();
210 Status
= CsrClientCallServer(&Request
,
212 sizeof(CSRSS_API_REQUEST
),
213 sizeof(CSRSS_API_REPLY
));
214 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
=Reply
.Status
))
216 SetLastErrorByStatus(Status
);
217 return INVALID_HANDLE_VALUE
;
219 return Reply
.Data
.DuplicateHandleReply
.Handle
;
227 ExpungeConsoleCommandHistoryW (DWORD Unknown0
)
232 DPRINT1("ExpungeConsoleCommandHistoryW(0x%x) UNIMPLEMENTED!\n", Unknown0
);
233 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
242 ExpungeConsoleCommandHistoryA (DWORD Unknown0
)
248 DPRINT1("ExpungeConsoleCommandHistoryW(0x%x) UNIMPLEMENTED!\n", Unknown0
);
249 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
258 GetConsoleAliasW (DWORD Unknown0
,
266 DPRINT1("GetConsoleAliasW(0x%x, 0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
, Unknown2
, Unknown3
);
267 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
276 GetConsoleAliasA (DWORD Unknown0
,
284 DPRINT1("GetConsoleAliasA(0x%x, 0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
, Unknown2
, Unknown3
);
285 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
294 GetConsoleAliasExesW (DWORD Unknown0
,
300 DPRINT1("GetConsoleAliasExesW(0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
);
301 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
310 GetConsoleAliasExesA (DWORD Unknown0
,
316 DPRINT1("GetConsoleAliasExesA(0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
);
317 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
326 GetConsoleAliasExesLengthA (VOID
)
331 DPRINT1("GetConsoleAliasExesLengthA() UNIMPLEMENTED!\n");
332 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
341 GetConsoleAliasExesLengthW (VOID
)
346 DPRINT1("GetConsoleAliasExesLengthW() UNIMPLEMENTED!\n");
347 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
356 GetConsoleAliasesW (DWORD Unknown0
,
363 DPRINT1("GetConsoleAliasesW(0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
, Unknown2
);
364 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
373 GetConsoleAliasesA (DWORD Unknown0
,
380 DPRINT1("GetConsoleAliasesA(0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
, Unknown2
);
381 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
390 GetConsoleAliasesLengthW (DWORD Unknown0
)
395 DPRINT1("GetConsoleAliasesLengthW(0x%x) UNIMPLEMENTED!\n", Unknown0
);
396 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
405 GetConsoleAliasesLengthA (DWORD Unknown0
)
410 DPRINT1("GetConsoleAliasesLengthA(0x%x) UNIMPLEMENTED!\n", Unknown0
);
411 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
420 GetConsoleCommandHistoryW (DWORD Unknown0
,
427 DPRINT1("GetConsoleCommandHistoryW(0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
, Unknown2
);
428 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
437 GetConsoleCommandHistoryA (DWORD Unknown0
,
444 DPRINT1("GetConsoleCommandHistoryA(0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
, Unknown2
);
445 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
454 GetConsoleCommandHistoryLengthW (DWORD Unknown0
)
459 DPRINT1("GetConsoleCommandHistoryLengthW(0x%x) UNIMPLEMENTED!\n", Unknown0
);
460 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
469 GetConsoleCommandHistoryLengthA (DWORD Unknown0
)
474 DPRINT1("GetConsoleCommandHistoryLengthA(0x%x) UNIMPLEMENTED!\n", Unknown0
);
475 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
483 GetConsoleDisplayMode (LPDWORD lpdwMode
)
485 * FUNCTION: Get the console display mode
487 * lpdwMode - Address of variable that receives the current value
489 * STATUS: Undocumented
492 DPRINT1("GetConsoleDisplayMode(0x%x) UNIMPLEMENTED!\n", lpdwMode
);
493 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
502 GetConsoleFontInfo (DWORD Unknown0
,
510 DPRINT1("GetConsoleFontInfo(0x%x, 0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
, Unknown2
, Unknown3
);
511 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
520 GetConsoleFontSize(HANDLE hConsoleOutput
,
523 DPRINT1("GetConsoleFontSize(0x%x, 0x%x) UNIMPLEMENTED!\n", hConsoleOutput
, nFont
);
524 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
533 GetConsoleHardwareState (HANDLE hConsole
,
540 CSRSS_API_REQUEST Request
;
541 CSRSS_API_REPLY Reply
;
544 Request
.Type
= CSRSS_SETGET_CONSOLE_HW_STATE
;
545 Request
.Data
.ConsoleHardwareStateRequest
.ConsoleHandle
= hConsole
;
546 Request
.Data
.ConsoleHardwareStateRequest
.SetGet
= CONSOLE_HARDWARE_STATE_GET
;
548 Status
= CsrClientCallServer(& Request
,
550 sizeof(CSRSS_API_REQUEST
),
551 sizeof(CSRSS_API_REPLY
));
552 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
554 SetLastErrorByStatus(Status
);
557 *State
= Reply
.Data
.ConsoleHardwareStateReply
.State
;
566 GetConsoleInputWaitHandle (VOID
)
571 CSRSS_API_REQUEST Request
;
572 CSRSS_API_REPLY Reply
;
575 Request
.Type
= CSRSS_GET_INPUT_WAIT_HANDLE
;
576 Status
= CsrClientCallServer(&Request
, &Reply
, sizeof(CSRSS_API_REQUEST
),
577 sizeof(CSRSS_API_REPLY
));
578 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
580 SetLastErrorByStatus(Status
);
583 return (DWORD
) Reply
.Data
.GetConsoleInputWaitHandle
.InputWaitHandle
;
591 GetCurrentConsoleFont(HANDLE hConsoleOutput
,
593 PCONSOLE_FONT_INFO lpConsoleCurrentFont
)
595 DPRINT1("GetCurrentConsoleFont(0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", hConsoleOutput
, bMaximumWindow
, lpConsoleCurrentFont
);
596 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
605 GetNumberOfConsoleFonts (VOID
)
610 DPRINT1("GetNumberOfConsoleFonts() UNIMPLEMENTED!\n");
611 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
612 return 1; /* FIXME: call csrss.exe */
620 InvalidateConsoleDIBits (DWORD Unknown0
,
626 DPRINT1("InvalidateConsoleDIBits(0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
);
627 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
636 OpenConsoleW (LPWSTR wsName
,
637 DWORD dwDesiredAccess
,
639 DWORD dwCreationDistribution
)
644 CSRSS_API_REQUEST Request
;
645 CSRSS_API_REPLY Reply
;
646 PHANDLE phConsole
= NULL
;
647 NTSTATUS Status
= STATUS_SUCCESS
;
649 if(0 == _wcsicmp(wsName
, L
"CONIN$"))
651 Request
.Type
= CSRSS_GET_INPUT_HANDLE
;
652 phConsole
= & Reply
.Data
.GetInputHandleReply
.InputHandle
;
654 else if (0 == _wcsicmp(wsName
, L
"CONOUT$"))
656 Request
.Type
= CSRSS_GET_OUTPUT_HANDLE
;
657 phConsole
= & Reply
.Data
.GetOutputHandleReply
.OutputHandle
;
661 SetLastError(ERROR_INVALID_PARAMETER
);
662 return(INVALID_HANDLE_VALUE
);
664 if ((GENERIC_READ
|GENERIC_WRITE
) != dwDesiredAccess
)
666 SetLastError(ERROR_INVALID_PARAMETER
);
667 return(INVALID_HANDLE_VALUE
);
669 if (OPEN_EXISTING
!= dwCreationDistribution
)
671 SetLastError(ERROR_INVALID_PARAMETER
);
672 return(INVALID_HANDLE_VALUE
);
674 Status
= CsrClientCallServer(& Request
,
676 sizeof(CSRSS_API_REQUEST
),
677 sizeof(CSRSS_API_REPLY
));
678 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
680 SetLastErrorByStatus(Status
);
681 return INVALID_HANDLE_VALUE
;
691 SetConsoleCommandHistoryMode (DWORD dwMode
)
696 DPRINT1("SetConsoleCommandHistoryMode(0x%x) UNIMPLEMENTED!\n", dwMode
);
697 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
706 SetConsoleCursor (DWORD Unknown0
,
712 DPRINT1("SetConsoleCursor(0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
);
713 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
722 SetConsoleDisplayMode (HANDLE hOut
,
726 * FUNCTION: Set the console display mode.
728 * hOut - Standard output handle.
729 * dwNewMode - New mode.
730 * lpdwOldMode - Address of a variable that receives the old mode.
733 DPRINT1("SetConsoleDisplayMode(0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", hOut
, dwNewMode
, lpdwOldMode
);
734 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
743 SetConsoleFont (DWORD Unknown0
,
749 DPRINT1("SetConsoleFont(0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
);
750 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
759 SetConsoleHardwareState (HANDLE hConsole
,
766 CSRSS_API_REQUEST Request
;
767 CSRSS_API_REPLY Reply
;
770 Request
.Type
= CSRSS_SETGET_CONSOLE_HW_STATE
;
771 Request
.Data
.ConsoleHardwareStateRequest
.ConsoleHandle
= hConsole
;
772 Request
.Data
.ConsoleHardwareStateRequest
.SetGet
= CONSOLE_HARDWARE_STATE_SET
;
773 Request
.Data
.ConsoleHardwareStateRequest
.State
= State
;
775 Status
= CsrClientCallServer(& Request
,
777 sizeof(CSRSS_API_REQUEST
),
778 sizeof(CSRSS_API_REPLY
));
779 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
781 SetLastErrorByStatus(Status
);
792 SetConsoleKeyShortcuts (DWORD Unknown0
,
800 DPRINT1("SetConsoleKeyShortcuts(0x%x, 0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
, Unknown2
, Unknown3
);
801 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
810 SetConsoleMaximumWindowSize (DWORD Unknown0
,
816 DPRINT1("SetConsoleMaximumWindowSize(0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
);
817 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
826 SetConsoleMenuClose (DWORD Unknown0
)
831 DPRINT1("SetConsoleMenuClose(0x%x) UNIMPLEMENTED!\n", Unknown0
);
832 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
841 SetConsoleNumberOfCommandsA (DWORD Unknown0
,
847 DPRINT1("SetConsoleNumberOfCommandsA(0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
);
848 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
857 SetConsoleNumberOfCommandsW (DWORD Unknown0
,
863 DPRINT1("SetConsoleNumberOfCommandsW(0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
);
864 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
873 SetConsolePalette (DWORD Unknown0
,
880 DPRINT1("SetConsolePalette(0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
, Unknown2
);
881 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
890 SetLastConsoleEventActive (VOID
)
895 DPRINT1("SetLastConsoleEventActive() UNIMPLEMENTED!\n");
896 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
905 ShowConsoleCursor (DWORD Unknown0
,
911 DPRINT1("ShowConsoleCursor(0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
);
912 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
918 * FUNCTION: Checks whether the given handle is a valid console handle.
920 * Handle - Handle to be checked
922 * TRUE: Handle is a valid console handle
923 * FALSE: Handle is not a valid console handle.
924 * STATUS: Officially undocumented
929 VerifyConsoleIoHandle(HANDLE Handle
)
931 CSRSS_API_REQUEST Request
;
932 CSRSS_API_REPLY Reply
;
935 Request
.Type
= CSRSS_VERIFY_HANDLE
;
936 Request
.Data
.VerifyHandleRequest
.Handle
= Handle
;
937 Status
= CsrClientCallServer(&Request
,
939 sizeof(CSRSS_API_REQUEST
),
940 sizeof(CSRSS_API_REPLY
));
941 if (!NT_SUCCESS(Status
))
943 SetLastErrorByStatus(Status
);
947 return (BOOL
)NT_SUCCESS(Reply
.Status
);
955 WriteConsoleInputVDMA (DWORD Unknown0
,
960 DPRINT1("WriteConsoleInputVDMA(0x%x, 0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
, Unknown2
, Unknown3
);
961 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
970 WriteConsoleInputVDMW (DWORD Unknown0
,
975 DPRINT1("WriteConsoleInputVDMW(0x%x, 0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
, Unknown2
, Unknown3
);
976 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
985 CloseConsoleHandle(HANDLE Handle
)
990 CSRSS_API_REQUEST Request
;
991 CSRSS_API_REPLY Reply
;
994 if (IsConsoleHandle (Handle
) == FALSE
)
996 SetLastError (ERROR_INVALID_PARAMETER
);
1000 Request
.Type
= CSRSS_CLOSE_HANDLE
;
1001 Request
.Data
.CloseHandleRequest
.Handle
= Handle
;
1002 Status
= CsrClientCallServer(&Request
,
1004 sizeof(CSRSS_API_REQUEST
),
1005 sizeof(CSRSS_API_REPLY
));
1006 if (!NT_SUCCESS(Status
))
1008 SetLastErrorByStatus(Status
);
1020 IsConsoleHandle(HANDLE Handle
)
1022 if ((((ULONG
)Handle
) & 0x10000003) == 0x3)
1034 GetStdHandle(DWORD nStdHandle
)
1036 * FUNCTION: Get a handle for the standard input, standard output
1037 * and a standard error device.
1039 * nStdHandle - Specifies the device for which to return the handle.
1040 * RETURNS: If the function succeeds, the return value is the handle
1041 * of the specified device. Otherwise the value is INVALID_HANDLE_VALUE.
1044 PRTL_USER_PROCESS_PARAMETERS Ppb
;
1046 Ppb
= NtCurrentPeb()->ProcessParameters
;
1049 case STD_INPUT_HANDLE
:
1050 return Ppb
->hStdInput
;
1052 case STD_OUTPUT_HANDLE
:
1053 return Ppb
->hStdOutput
;
1055 case STD_ERROR_HANDLE
:
1056 return Ppb
->hStdError
;
1059 SetLastError (ERROR_INVALID_PARAMETER
);
1060 return INVALID_HANDLE_VALUE
;
1068 SetStdHandle(DWORD nStdHandle
,
1071 * FUNCTION: Set the handle for the standard input, standard output or
1072 * the standard error device.
1074 * nStdHandle - Specifies the handle to be set.
1075 * hHandle - The handle to set.
1076 * RETURNS: TRUE if the function succeeds, FALSE otherwise.
1079 PRTL_USER_PROCESS_PARAMETERS Ppb
;
1081 /* no need to check if hHandle == INVALID_HANDLE_VALUE */
1083 Ppb
= NtCurrentPeb()->ProcessParameters
;
1087 case STD_INPUT_HANDLE
:
1088 Ppb
->hStdInput
= hHandle
;
1091 case STD_OUTPUT_HANDLE
:
1092 Ppb
->hStdOutput
= hHandle
;
1095 case STD_ERROR_HANDLE
:
1096 Ppb
->hStdError
= hHandle
;
1100 /* windows for whatever reason sets the last error to ERROR_INVALID_HANDLE here */
1101 SetLastError (ERROR_INVALID_HANDLE
);
1107 IntWriteConsole(HANDLE hConsoleOutput
,
1109 DWORD nNumberOfCharsToWrite
,
1110 LPDWORD lpNumberOfCharsWritten
,
1114 PCSRSS_API_REQUEST Request
;
1115 CSRSS_API_REPLY Reply
;
1118 ULONG MessageSize
, BufferSize
, SizeBytes
, CharSize
;
1121 CharSize
= (bUnicode
? sizeof(WCHAR
) : sizeof(CHAR
));
1123 BufferSize
= sizeof(CSRSS_API_REQUEST
) + min(nNumberOfCharsToWrite
* CharSize
, CSRSS_MAX_WRITE_CONSOLE_REQUEST
);
1124 Request
= RtlAllocateHeap(GetProcessHeap(), 0, BufferSize
);
1127 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1131 Request
->Type
= CSRSS_WRITE_CONSOLE
;
1132 Request
->Data
.WriteConsoleRequest
.ConsoleHandle
= hConsoleOutput
;
1133 Request
->Data
.WriteConsoleRequest
.Unicode
= bUnicode
;
1135 while(nNumberOfCharsToWrite
> 0)
1137 nChars
= min(nNumberOfCharsToWrite
, CSRSS_MAX_WRITE_CONSOLE_REQUEST
/ CharSize
);
1138 Request
->Data
.WriteConsoleRequest
.NrCharactersToWrite
= nChars
;
1140 SizeBytes
= nChars
* CharSize
;
1142 memcpy(Request
->Data
.WriteConsoleRequest
.Buffer
, lpBuffer
, SizeBytes
);
1144 MessageSize
= CSRSS_REQUEST_HEADER_SIZE
+ sizeof(CSRSS_WRITE_CONSOLE_REQUEST
) + SizeBytes
;
1145 Status
= CsrClientCallServer(Request
,
1148 sizeof(CSRSS_API_REPLY
));
1150 if(!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
1152 RtlFreeHeap(GetProcessHeap(), 0, Request
);
1153 SetLastErrorByStatus(Status
);
1157 nNumberOfCharsToWrite
-= nChars
;
1158 lpBuffer
= (PVOID
)((ULONG_PTR
)lpBuffer
+ (ULONG_PTR
)SizeBytes
);
1159 Written
+= Reply
.Data
.WriteConsoleReply
.NrCharactersWritten
;
1162 RtlFreeHeap(GetProcessHeap(), 0, Request
);
1164 if(lpNumberOfCharsWritten
!= NULL
)
1166 *lpNumberOfCharsWritten
= Written
;
1173 /*--------------------------------------------------------------
1179 WriteConsoleA(HANDLE hConsoleOutput
,
1180 CONST VOID
*lpBuffer
,
1181 DWORD nNumberOfCharsToWrite
,
1182 LPDWORD lpNumberOfCharsWritten
,
1185 return IntWriteConsole(hConsoleOutput
,
1187 nNumberOfCharsToWrite
,
1188 lpNumberOfCharsWritten
,
1194 /*--------------------------------------------------------------
1201 HANDLE hConsoleOutput
,
1202 CONST VOID
*lpBuffer
,
1203 DWORD nNumberOfCharsToWrite
,
1204 LPDWORD lpNumberOfCharsWritten
,
1208 return IntWriteConsole(hConsoleOutput
,
1210 nNumberOfCharsToWrite
,
1211 lpNumberOfCharsWritten
,
1218 IntReadConsole(HANDLE hConsoleInput
,
1220 DWORD nNumberOfCharsToRead
,
1221 LPDWORD lpNumberOfCharsRead
,
1225 CSRSS_API_REQUEST Request
;
1226 PCSRSS_API_REPLY Reply
;
1228 ULONG BufferSize
, CharSize
, CharsRead
= 0;
1230 CharSize
= (bUnicode
? sizeof(WCHAR
) : sizeof(CHAR
));
1232 BufferSize
= sizeof(CSRSS_API_REQUEST
) + min(nNumberOfCharsToRead
* CharSize
, CSRSS_MAX_READ_CONSOLE_REQUEST
);
1233 Reply
= RtlAllocateHeap(GetProcessHeap(), 0, BufferSize
);
1236 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1240 Reply
->Status
= STATUS_SUCCESS
;
1244 if(Reply
->Status
== STATUS_PENDING
)
1246 Status
= NtWaitForSingleObject(Reply
->Data
.ReadConsoleReply
.EventHandle
, FALSE
, 0);
1247 if(!NT_SUCCESS(Status
))
1249 DPRINT1("Wait for console input failed!\n");
1254 Request
.Type
= CSRSS_READ_CONSOLE
;
1255 Request
.Data
.ReadConsoleRequest
.ConsoleHandle
= hConsoleInput
;
1256 Request
.Data
.ReadConsoleRequest
.Unicode
= bUnicode
;
1257 Request
.Data
.ReadConsoleRequest
.NrCharactersToRead
= min(nNumberOfCharsToRead
, CSRSS_MAX_READ_CONSOLE_REQUEST
/ CharSize
);
1258 Request
.Data
.ReadConsoleRequest
.nCharsCanBeDeleted
= CharsRead
;
1259 Status
= CsrClientCallServer(&Request
,
1261 sizeof(CSRSS_API_REQUEST
),
1262 sizeof(CSRSS_API_REPLY
) + (Request
.Data
.ReadConsoleRequest
.NrCharactersToRead
* CharSize
));
1264 if(!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
->Status
))
1266 DPRINT1("CSR returned error in ReadConsole\n");
1267 SetLastErrorByStatus(Status
);
1268 RtlFreeHeap(GetProcessHeap(), 0, Reply
);
1272 nNumberOfCharsToRead
-= Reply
->Data
.ReadConsoleReply
.NrCharactersRead
;
1273 memcpy((PVOID
)((ULONG_PTR
)lpBuffer
+ (ULONG_PTR
)(CharsRead
* CharSize
)),
1274 Reply
->Data
.ReadConsoleReply
.Buffer
,
1275 Reply
->Data
.ReadConsoleReply
.NrCharactersRead
* CharSize
);
1276 CharsRead
+= Reply
->Data
.ReadConsoleReply
.NrCharactersRead
;
1278 if(Reply
->Status
== STATUS_NOTIFY_CLEANUP
)
1283 nNumberOfCharsToRead
++;
1285 Reply
->Status
= STATUS_PENDING
;
1287 } while(Reply
->Status
== STATUS_PENDING
&& nNumberOfCharsToRead
> 0);
1289 if(lpNumberOfCharsRead
!= NULL
)
1291 *lpNumberOfCharsRead
= CharsRead
;
1298 /*--------------------------------------------------------------
1304 ReadConsoleA(HANDLE hConsoleInput
,
1306 DWORD nNumberOfCharsToRead
,
1307 LPDWORD lpNumberOfCharsRead
,
1310 return IntReadConsole(hConsoleInput
,
1312 nNumberOfCharsToRead
,
1313 lpNumberOfCharsRead
,
1319 /*--------------------------------------------------------------
1325 ReadConsoleW(HANDLE hConsoleInput
,
1327 DWORD nNumberOfCharsToRead
,
1328 LPDWORD lpNumberOfCharsRead
,
1331 return IntReadConsole(hConsoleInput
,
1333 nNumberOfCharsToRead
,
1334 lpNumberOfCharsRead
,
1340 /*--------------------------------------------------------------
1345 BOOL STDCALL
AllocConsole(VOID
)
1347 PUNICODE_STRING DesktopName
, Title
;
1348 CSRSS_API_REQUEST Request
;
1349 CSRSS_API_REPLY Reply
;
1353 PVOID BufferBase
, BufferTargetBase
;
1354 PWCHAR szDest
, szTargetDest
;
1356 if(NtCurrentPeb()->ProcessParameters
->hConsole
)
1358 DPRINT("AllocConsole: Allocate duplicate console to the same Process\n");
1359 SetLastErrorByStatus (STATUS_OBJECT_NAME_EXISTS
);
1363 DesktopName
= &NtCurrentPeb()->ProcessParameters
->DesktopInfo
;
1364 Title
= &NtCurrentPeb()->ProcessParameters
->WindowTitle
;
1366 BufSize
= ((DesktopName
->Length
>= sizeof(WCHAR
)) ? DesktopName
->Length
+ sizeof(WCHAR
) : 0);
1367 BufSize
+= ((Title
->Length
>= sizeof(WCHAR
)) ? Title
->Length
+ sizeof(WCHAR
) : 0);
1371 Status
= CsrCaptureParameterBuffer(NULL
, BufSize
, &BufferBase
, &BufferTargetBase
);
1372 if(!NT_SUCCESS(Status
))
1374 SetLastErrorByStatus(Status
);
1377 szDest
= BufferBase
;
1378 szTargetDest
= BufferTargetBase
;
1380 if(DesktopName
->Length
>= sizeof(WCHAR
))
1382 memcpy(szDest
, DesktopName
->Buffer
, DesktopName
->Length
);
1383 szDest
= (PWSTR
)((ULONG_PTR
)szDest
+ DesktopName
->Length
);
1384 *(szDest
++) = L
'\0';
1385 Request
.Data
.AllocConsoleRequest
.DesktopName
.Length
= DesktopName
->Length
;
1386 Request
.Data
.AllocConsoleRequest
.DesktopName
.MaximumLength
= DesktopName
->Length
+ sizeof(WCHAR
);
1387 Request
.Data
.AllocConsoleRequest
.DesktopName
.Buffer
= szTargetDest
;
1388 szTargetDest
= (PWSTR
)((ULONG_PTR
)szTargetDest
+ DesktopName
->Length
+ sizeof(WCHAR
));
1392 RtlInitUnicodeString(&Request
.Data
.AllocConsoleRequest
.DesktopName
, NULL
);
1395 if(Title
->Length
>= sizeof(WCHAR
))
1397 memcpy(szDest
, Title
->Buffer
, Title
->Length
);
1398 szDest
= (PWSTR
)((ULONG_PTR
)szDest
+ Title
->Length
);
1399 *(szDest
++) = L
'\0';
1400 Request
.Data
.AllocConsoleRequest
.Title
.Length
= Title
->Length
;
1401 Request
.Data
.AllocConsoleRequest
.Title
.MaximumLength
= Title
->Length
+ sizeof(WCHAR
);
1402 Request
.Data
.AllocConsoleRequest
.Title
.Buffer
= szTargetDest
;
1403 szTargetDest
= (PWSTR
)((ULONG_PTR
)szTargetDest
+ Title
->Length
+ sizeof(WCHAR
));
1407 RtlInitUnicodeString(&Request
.Data
.AllocConsoleRequest
.Title
, NULL
);
1411 Request
.Data
.AllocConsoleRequest
.CtrlDispatcher
= (PCONTROLDISPATCHER
) &ConsoleControlDispatcher
;
1413 Request
.Type
= CSRSS_ALLOC_CONSOLE
;
1414 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
1415 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
1419 CsrReleaseParameterBuffer(BufferBase
);
1421 SetLastErrorByStatus ( Status
);
1427 CsrReleaseParameterBuffer(BufferBase
);
1430 /* FIXME - thread-safe exchange!!! */
1431 NtCurrentPeb()->ProcessParameters
->hConsole
= Reply
.Data
.AllocConsoleReply
.Console
;
1432 SetStdHandle( STD_INPUT_HANDLE
, Reply
.Data
.AllocConsoleReply
.InputHandle
);
1433 SetStdHandle( STD_OUTPUT_HANDLE
, Reply
.Data
.AllocConsoleReply
.OutputHandle
);
1434 hStdError
= DuplicateConsoleHandle(Reply
.Data
.AllocConsoleReply
.OutputHandle
,
1437 DUPLICATE_SAME_ACCESS
);
1438 SetStdHandle( STD_ERROR_HANDLE
, hStdError
);
1443 /*--------------------------------------------------------------
1448 BOOL STDCALL
FreeConsole(VOID
)
1450 // AG: I'm not sure if this is correct (what happens to std handles?)
1451 // but I just tried to reverse what AllocConsole() does...
1453 CSRSS_API_REQUEST Request
;
1454 CSRSS_API_REPLY Reply
;
1457 Request
.Type
= CSRSS_FREE_CONSOLE
;
1458 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
1459 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
1461 SetLastErrorByStatus ( Status
);
1469 /*--------------------------------------------------------------
1470 * GetConsoleScreenBufferInfo
1476 GetConsoleScreenBufferInfo(
1477 HANDLE hConsoleOutput
,
1478 PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo
1481 CSRSS_API_REQUEST Request
;
1482 CSRSS_API_REPLY Reply
;
1485 Request
.Type
= CSRSS_SCREEN_BUFFER_INFO
;
1486 Request
.Data
.ScreenBufferInfoRequest
.ConsoleHandle
= hConsoleOutput
;
1487 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
1488 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
1490 SetLastErrorByStatus ( Status
);
1493 *lpConsoleScreenBufferInfo
= Reply
.Data
.ScreenBufferInfoReply
.Info
;
1498 /*--------------------------------------------------------------
1499 * SetConsoleCursorPosition
1505 SetConsoleCursorPosition(
1506 HANDLE hConsoleOutput
,
1507 COORD dwCursorPosition
1510 CSRSS_API_REQUEST Request
;
1511 CSRSS_API_REPLY Reply
;
1514 Request
.Type
= CSRSS_SET_CURSOR
;
1515 Request
.Data
.SetCursorRequest
.ConsoleHandle
= hConsoleOutput
;
1516 Request
.Data
.SetCursorRequest
.Position
= dwCursorPosition
;
1517 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
1518 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
1520 SetLastErrorByStatus ( Status
);
1528 IntFillConsoleOutputCharacter(HANDLE hConsoleOutput
,
1532 LPDWORD lpNumberOfCharsWritten
,
1535 CSRSS_API_REQUEST Request
;
1536 CSRSS_API_REPLY Reply
;
1539 Request
.Type
= CSRSS_FILL_OUTPUT
;
1540 Request
.Data
.FillOutputRequest
.ConsoleHandle
= hConsoleOutput
;
1541 Request
.Data
.FillOutputRequest
.Unicode
= bUnicode
;
1543 Request
.Data
.FillOutputRequest
.Char
.UnicodeChar
= *((WCHAR
*)cCharacter
);
1545 Request
.Data
.FillOutputRequest
.Char
.AsciiChar
= *((CHAR
*)cCharacter
);
1546 Request
.Data
.FillOutputRequest
.Position
= dwWriteCoord
;
1547 Request
.Data
.FillOutputRequest
.Length
= nLength
;
1548 Status
= CsrClientCallServer(&Request
, &Reply
,
1549 sizeof(CSRSS_API_REQUEST
),
1550 sizeof(CSRSS_API_REPLY
));
1552 if(!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
1554 SetLastErrorByStatus(Status
);
1558 if(lpNumberOfCharsWritten
!= NULL
)
1560 *lpNumberOfCharsWritten
= Reply
.Data
.FillOutputReply
.NrCharactersWritten
;
1566 /*--------------------------------------------------------------
1567 * FillConsoleOutputCharacterA
1572 FillConsoleOutputCharacterA(
1573 HANDLE hConsoleOutput
,
1577 LPDWORD lpNumberOfCharsWritten
1580 return IntFillConsoleOutputCharacter(hConsoleOutput
,
1584 lpNumberOfCharsWritten
,
1589 /*--------------------------------------------------------------
1590 * FillConsoleOutputCharacterW
1596 FillConsoleOutputCharacterW(
1597 HANDLE hConsoleOutput
,
1601 LPDWORD lpNumberOfCharsWritten
1604 return IntFillConsoleOutputCharacter(hConsoleOutput
,
1608 lpNumberOfCharsWritten
,
1614 IntPeekConsoleInput(HANDLE hConsoleInput
,
1615 PINPUT_RECORD lpBuffer
,
1617 LPDWORD lpNumberOfEventsRead
,
1620 CSRSS_API_REQUEST Request
;
1621 CSRSS_API_REPLY Reply
;
1624 PVOID BufferTargetBase
;
1627 if(lpBuffer
== NULL
)
1629 SetLastError(ERROR_INVALID_PARAMETER
);
1633 Size
= nLength
* sizeof(INPUT_RECORD
);
1635 Status
= CsrCaptureParameterBuffer((PVOID
)lpBuffer
, Size
, &BufferBase
, &BufferTargetBase
);
1636 if(!NT_SUCCESS(Status
))
1638 SetLastErrorByStatus(Status
);
1642 Request
.Type
= CSRSS_PEEK_CONSOLE_INPUT
;
1643 Request
.Data
.PeekConsoleInputRequest
.ConsoleHandle
= hConsoleInput
;
1644 Request
.Data
.PeekConsoleInputRequest
.Unicode
= bUnicode
;
1645 Request
.Data
.PeekConsoleInputRequest
.Length
= nLength
;
1646 Request
.Data
.PeekConsoleInputRequest
.InputRecord
= (INPUT_RECORD
*)BufferTargetBase
;
1648 Status
= CsrClientCallServer(&Request
, &Reply
,
1649 sizeof(CSRSS_API_REQUEST
),
1650 sizeof(CSRSS_API_REPLY
));
1652 if(!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
1654 CsrReleaseParameterBuffer(BufferBase
);
1658 memcpy(lpBuffer
, BufferBase
, sizeof(INPUT_RECORD
) * Reply
.Data
.PeekConsoleInputReply
.Length
);
1660 CsrReleaseParameterBuffer(BufferBase
);
1662 if(lpNumberOfEventsRead
!= NULL
)
1664 *lpNumberOfEventsRead
= Reply
.Data
.PeekConsoleInputReply
.Length
;
1670 /*--------------------------------------------------------------
1678 HANDLE hConsoleInput
,
1679 PINPUT_RECORD lpBuffer
,
1681 LPDWORD lpNumberOfEventsRead
1684 return IntPeekConsoleInput(hConsoleInput
, lpBuffer
, nLength
,
1685 lpNumberOfEventsRead
, FALSE
);
1689 /*--------------------------------------------------------------
1697 HANDLE hConsoleInput
,
1698 PINPUT_RECORD lpBuffer
,
1700 LPDWORD lpNumberOfEventsRead
1703 return IntPeekConsoleInput(hConsoleInput
, lpBuffer
, nLength
,
1704 lpNumberOfEventsRead
, TRUE
);
1709 IntReadConsoleInput(HANDLE hConsoleInput
,
1710 PINPUT_RECORD lpBuffer
,
1712 LPDWORD lpNumberOfEventsRead
,
1715 CSRSS_API_REQUEST Request
;
1716 CSRSS_API_REPLY Reply
;
1720 Request
.Type
= CSRSS_READ_INPUT
;
1721 Request
.Data
.ReadInputRequest
.ConsoleHandle
= hConsoleInput
;
1722 Request
.Data
.ReadInputRequest
.Unicode
= bUnicode
;
1727 Status
= CsrClientCallServer(&Request
, &Reply
,
1728 sizeof(CSRSS_API_REQUEST
),
1729 sizeof(CSRSS_API_REPLY
));
1730 if(!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
1734 /* we couldn't read a single record, fail */
1735 SetLastErrorByStatus(Status
);
1740 /* FIXME - fail gracefully in case we already read at least one record? */
1744 else if(Status
== STATUS_PENDING
)
1748 Status
= NtWaitForSingleObject(Reply
.Data
.ReadInputReply
.Event
, FALSE
, 0);
1749 if(!NT_SUCCESS(Status
))
1751 SetLastErrorByStatus(Status
);
1757 /* nothing more to read (waiting for more input??), let's just bail */
1763 lpBuffer
[Read
++] = Reply
.Data
.ReadInputReply
.Input
;
1766 if(!Reply
.Data
.ReadInputReply
.MoreEvents
)
1768 /* nothing more to read, bail */
1774 if(lpNumberOfEventsRead
!= NULL
)
1776 *lpNumberOfEventsRead
= Read
;
1783 /*--------------------------------------------------------------
1789 ReadConsoleInputA(HANDLE hConsoleInput
,
1790 PINPUT_RECORD lpBuffer
,
1792 LPDWORD lpNumberOfEventsRead
)
1794 return IntReadConsoleInput(hConsoleInput
, lpBuffer
, nLength
,
1795 lpNumberOfEventsRead
, FALSE
);
1799 /*--------------------------------------------------------------
1807 HANDLE hConsoleInput
,
1808 PINPUT_RECORD lpBuffer
,
1810 LPDWORD lpNumberOfEventsRead
1813 return IntReadConsoleInput(hConsoleInput
, lpBuffer
, nLength
,
1814 lpNumberOfEventsRead
, TRUE
);
1819 IntWriteConsoleInput(HANDLE hConsoleInput
,
1820 PINPUT_RECORD lpBuffer
,
1822 LPDWORD lpNumberOfEventsWritten
,
1825 CSRSS_API_REQUEST Request
;
1826 CSRSS_API_REPLY Reply
;
1827 PVOID BufferBase
, BufferTargetBase
;
1831 if(lpBuffer
== NULL
)
1833 SetLastError(ERROR_INVALID_PARAMETER
);
1837 Size
= nLength
* sizeof(INPUT_RECORD
);
1839 Status
= CsrCaptureParameterBuffer((PVOID
)lpBuffer
, Size
, &BufferBase
, &BufferTargetBase
);
1840 if(!NT_SUCCESS(Status
))
1842 SetLastErrorByStatus(Status
);
1846 Request
.Type
= CSRSS_WRITE_CONSOLE_INPUT
;
1847 Request
.Data
.WriteConsoleInputRequest
.ConsoleHandle
= hConsoleInput
;
1848 Request
.Data
.WriteConsoleInputRequest
.Unicode
= bUnicode
;
1849 Request
.Data
.WriteConsoleInputRequest
.Length
= nLength
;
1850 Request
.Data
.WriteConsoleInputRequest
.InputRecord
= (PINPUT_RECORD
)BufferTargetBase
;
1852 Status
= CsrClientCallServer(&Request
, &Reply
,
1853 sizeof(CSRSS_API_REQUEST
),
1854 sizeof(CSRSS_API_REPLY
));
1856 CsrReleaseParameterBuffer(BufferBase
);
1858 if(!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
1860 SetLastErrorByStatus(Status
);
1864 if(lpNumberOfEventsWritten
!= NULL
)
1866 *lpNumberOfEventsWritten
= Reply
.Data
.WriteConsoleInputReply
.Length
;
1873 /*--------------------------------------------------------------
1874 * WriteConsoleInputA
1881 HANDLE hConsoleInput
,
1882 CONST INPUT_RECORD
*lpBuffer
,
1884 LPDWORD lpNumberOfEventsWritten
1887 return IntWriteConsoleInput(hConsoleInput
,
1888 (PINPUT_RECORD
)lpBuffer
,
1890 lpNumberOfEventsWritten
,
1895 /*--------------------------------------------------------------
1896 * WriteConsoleInputW
1903 HANDLE hConsoleInput
,
1904 CONST INPUT_RECORD
*lpBuffer
,
1906 LPDWORD lpNumberOfEventsWritten
1909 return IntWriteConsoleInput(hConsoleInput
,
1910 (PINPUT_RECORD
)lpBuffer
,
1912 lpNumberOfEventsWritten
,
1918 IntReadConsoleOutput(HANDLE hConsoleOutput
,
1919 PCHAR_INFO lpBuffer
,
1921 COORD dwBufferCoord
,
1922 PSMALL_RECT lpReadRegion
,
1925 CSRSS_API_REQUEST Request
;
1926 CSRSS_API_REPLY Reply
;
1928 PVOID BufferTargetBase
;
1930 DWORD Size
, SizeX
, SizeY
;
1932 if(lpBuffer
== NULL
)
1934 SetLastError(ERROR_INVALID_PARAMETER
);
1938 Size
= dwBufferSize
.X
* dwBufferSize
.Y
* sizeof(CHAR_INFO
);
1940 Status
= CsrCaptureParameterBuffer((PVOID
)lpBuffer
, Size
, &BufferBase
, &BufferTargetBase
);
1941 if(!NT_SUCCESS(Status
))
1943 SetLastErrorByStatus(Status
);
1947 Request
.Type
= CSRSS_READ_CONSOLE_OUTPUT
;
1948 Request
.Data
.ReadConsoleOutputRequest
.ConsoleHandle
= hConsoleOutput
;
1949 Request
.Data
.ReadConsoleOutputRequest
.Unicode
= bUnicode
;
1950 Request
.Data
.ReadConsoleOutputRequest
.BufferSize
= dwBufferSize
;
1951 Request
.Data
.ReadConsoleOutputRequest
.BufferCoord
= dwBufferCoord
;
1952 Request
.Data
.ReadConsoleOutputRequest
.ReadRegion
= *lpReadRegion
;
1953 Request
.Data
.ReadConsoleOutputRequest
.CharInfo
= (PCHAR_INFO
)BufferTargetBase
;
1955 Status
= CsrClientCallServer(&Request
, &Reply
,
1956 sizeof(CSRSS_API_REQUEST
),
1957 sizeof(CSRSS_API_REPLY
));
1959 if(!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
1961 SetLastErrorByStatus(Status
);
1962 CsrReleaseParameterBuffer(BufferBase
);
1966 SizeX
= Reply
.Data
.ReadConsoleOutputReply
.ReadRegion
.Right
- Reply
.Data
.ReadConsoleOutputReply
.ReadRegion
.Left
+ 1;
1967 SizeY
= Reply
.Data
.ReadConsoleOutputReply
.ReadRegion
.Bottom
- Reply
.Data
.ReadConsoleOutputReply
.ReadRegion
.Top
+ 1;
1969 memcpy(lpBuffer
, BufferBase
, sizeof(CHAR_INFO
) * SizeX
* SizeY
);
1971 CsrReleaseParameterBuffer(BufferBase
);
1973 *lpReadRegion
= Reply
.Data
.ReadConsoleOutputReply
.ReadRegion
;
1978 /*--------------------------------------------------------------
1979 * ReadConsoleOutputA
1986 HANDLE hConsoleOutput
,
1987 PCHAR_INFO lpBuffer
,
1989 COORD dwBufferCoord
,
1990 PSMALL_RECT lpReadRegion
1993 return IntReadConsoleOutput(hConsoleOutput
, lpBuffer
, dwBufferSize
,
1994 dwBufferCoord
, lpReadRegion
, FALSE
);
1998 /*--------------------------------------------------------------
1999 * ReadConsoleOutputW
2006 HANDLE hConsoleOutput
,
2007 PCHAR_INFO lpBuffer
,
2009 COORD dwBufferCoord
,
2010 PSMALL_RECT lpReadRegion
2013 return IntReadConsoleOutput(hConsoleOutput
, lpBuffer
, dwBufferSize
,
2014 dwBufferCoord
, lpReadRegion
, TRUE
);
2019 IntWriteConsoleOutput(HANDLE hConsoleOutput
,
2020 CONST CHAR_INFO
*lpBuffer
,
2022 COORD dwBufferCoord
,
2023 PSMALL_RECT lpWriteRegion
,
2026 CSRSS_API_REQUEST Request
;
2027 CSRSS_API_REPLY Reply
;
2031 PVOID BufferTargetBase
;
2033 Size
= dwBufferSize
.Y
* dwBufferSize
.X
* sizeof(CHAR_INFO
);
2035 Status
= CsrCaptureParameterBuffer((PVOID
)lpBuffer
,
2039 if (!NT_SUCCESS(Status
))
2041 SetLastErrorByStatus(Status
);
2045 Request
.Type
= CSRSS_WRITE_CONSOLE_OUTPUT
;
2046 Request
.Data
.WriteConsoleOutputRequest
.ConsoleHandle
= hConsoleOutput
;
2047 Request
.Data
.WriteConsoleOutputRequest
.Unicode
= bUnicode
;
2048 Request
.Data
.WriteConsoleOutputRequest
.BufferSize
= dwBufferSize
;
2049 Request
.Data
.WriteConsoleOutputRequest
.BufferCoord
= dwBufferCoord
;
2050 Request
.Data
.WriteConsoleOutputRequest
.WriteRegion
= *lpWriteRegion
;
2051 Request
.Data
.WriteConsoleOutputRequest
.CharInfo
=
2052 (CHAR_INFO
*)BufferTargetBase
;
2054 Status
= CsrClientCallServer(&Request
, &Reply
,
2055 sizeof(CSRSS_API_REQUEST
),
2056 sizeof(CSRSS_API_REPLY
));
2058 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
2060 CsrReleaseParameterBuffer(BufferBase
);
2061 SetLastErrorByStatus(Status
);
2065 CsrReleaseParameterBuffer(BufferBase
);
2067 *lpWriteRegion
= Reply
.Data
.WriteConsoleOutputReply
.WriteRegion
;
2072 /*--------------------------------------------------------------
2073 * WriteConsoleOutputA
2078 WriteConsoleOutputA(HANDLE hConsoleOutput
,
2079 CONST CHAR_INFO
*lpBuffer
,
2081 COORD dwBufferCoord
,
2082 PSMALL_RECT lpWriteRegion
)
2084 return IntWriteConsoleOutput(hConsoleOutput
, lpBuffer
, dwBufferSize
,
2085 dwBufferCoord
, lpWriteRegion
, FALSE
);
2089 /*--------------------------------------------------------------
2090 * WriteConsoleOutputW
2096 WriteConsoleOutputW(
2097 HANDLE hConsoleOutput
,
2098 CONST CHAR_INFO
*lpBuffer
,
2100 COORD dwBufferCoord
,
2101 PSMALL_RECT lpWriteRegion
2104 return IntWriteConsoleOutput(hConsoleOutput
, lpBuffer
, dwBufferSize
,
2105 dwBufferCoord
, lpWriteRegion
, TRUE
);
2110 IntReadConsoleOutputCharacter(HANDLE hConsoleOutput
,
2114 LPDWORD lpNumberOfCharsRead
,
2117 CSRSS_API_REQUEST Request
;
2118 PCSRSS_API_REPLY Reply
;
2120 ULONG nChars
, SizeBytes
, CharSize
;
2121 DWORD CharsRead
= 0;
2123 CharSize
= (bUnicode
? sizeof(WCHAR
) : sizeof(CHAR
));
2125 nChars
= min(nLength
, CSRSS_MAX_READ_CONSOLE_OUTPUT_CHAR
/ CharSize
);
2126 SizeBytes
= nChars
* CharSize
;
2128 Reply
= RtlAllocateHeap(GetProcessHeap(), 0,
2129 sizeof(CSRSS_API_REPLY
) + SizeBytes
);
2132 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2137 Request
.Type
= CSRSS_READ_CONSOLE_OUTPUT_CHAR
;
2138 Request
.Data
.ReadConsoleOutputCharRequest
.ConsoleHandle
= hConsoleOutput
;
2139 Request
.Data
.ReadConsoleOutputCharRequest
.Unicode
= bUnicode
;
2140 Request
.Data
.ReadConsoleOutputCharRequest
.ReadCoord
= dwReadCoord
;
2146 Request
.Data
.ReadConsoleOutputCharRequest
.NumCharsToRead
= min(nLength
, nChars
);
2148 Status
= CsrClientCallServer(&Request
,
2150 sizeof(CSRSS_API_REQUEST
),
2151 sizeof(CSRSS_API_REPLY
) + SizeBytes
);
2152 if(!NT_SUCCESS(Status
) || !NT_SUCCESS(Reply
->Status
))
2154 SetLastErrorByStatus(Status
);
2158 BytesRead
= Reply
->Data
.ReadConsoleOutputCharReply
.CharsRead
* CharSize
;
2159 memcpy(lpCharacter
, &Reply
->Data
.ReadConsoleOutputCharReply
.String
[0], BytesRead
);
2160 lpCharacter
= (PVOID
)((ULONG_PTR
)lpCharacter
+ (ULONG_PTR
)BytesRead
);
2161 CharsRead
+= Reply
->Data
.ReadConsoleOutputCharReply
.CharsRead
;
2162 nLength
-= Reply
->Data
.ReadConsoleOutputCharReply
.CharsRead
;
2164 Request
.Data
.ReadConsoleOutputCharRequest
.ReadCoord
= Reply
->Data
.ReadConsoleOutputCharReply
.EndCoord
;
2167 RtlFreeHeap(GetProcessHeap(), 0, Reply
);
2169 if(lpNumberOfCharsRead
!= NULL
)
2171 *lpNumberOfCharsRead
= CharsRead
;
2178 /*--------------------------------------------------------------
2179 * ReadConsoleOutputCharacterA
2185 ReadConsoleOutputCharacterA(
2186 HANDLE hConsoleOutput
,
2190 LPDWORD lpNumberOfCharsRead
2193 return IntReadConsoleOutputCharacter(hConsoleOutput
,
2197 lpNumberOfCharsRead
,
2202 /*--------------------------------------------------------------
2203 * ReadConsoleOutputCharacterW
2209 ReadConsoleOutputCharacterW(
2210 HANDLE hConsoleOutput
,
2214 LPDWORD lpNumberOfCharsRead
2217 return IntReadConsoleOutputCharacter(hConsoleOutput
,
2221 lpNumberOfCharsRead
,
2226 /*--------------------------------------------------------------
2227 * ReadConsoleOutputAttribute
2233 ReadConsoleOutputAttribute(
2234 HANDLE hConsoleOutput
,
2238 LPDWORD lpNumberOfAttrsRead
2241 CSRSS_API_REQUEST Request
;
2242 PCSRSS_API_REPLY Reply
;
2246 Reply
= RtlAllocateHeap(GetProcessHeap(), 0,
2247 sizeof(CSRSS_API_REPLY
) + min(nLength
, CSRSS_MAX_READ_CONSOLE_OUTPUT_ATTRIB
));
2250 SetLastError(ERROR_OUTOFMEMORY
);
2254 if (lpNumberOfAttrsRead
!= NULL
)
2255 *lpNumberOfAttrsRead
= nLength
;
2257 Request
.Type
= CSRSS_READ_CONSOLE_OUTPUT_ATTRIB
;
2258 Request
.Data
.ReadConsoleOutputAttribRequest
.ConsoleHandle
= hConsoleOutput
;
2259 Request
.Data
.ReadConsoleOutputAttribRequest
.ReadCoord
= dwReadCoord
;
2261 while (nLength
!= 0)
2263 if (nLength
> CSRSS_MAX_READ_CONSOLE_OUTPUT_ATTRIB
)
2264 Size
= CSRSS_MAX_READ_CONSOLE_OUTPUT_ATTRIB
;
2268 Request
.Data
.ReadConsoleOutputAttribRequest
.NumAttrsToRead
= Size
;
2270 Status
= CsrClientCallServer(&Request
,
2272 sizeof(CSRSS_API_REQUEST
),
2273 sizeof(CSRSS_API_REPLY
) + Size
);
2274 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Reply
->Status
))
2276 RtlFreeHeap(GetProcessHeap(), 0, Reply
);
2277 SetLastErrorByStatus(Status
);
2281 // Convert CHARs to WORDs
2282 for(i
= 0; i
< Size
; ++i
)
2283 *lpAttribute
++ = Reply
->Data
.ReadConsoleOutputAttribReply
.String
[i
];
2286 Request
.Data
.ReadConsoleOutputAttribRequest
.ReadCoord
= Reply
->Data
.ReadConsoleOutputAttribReply
.EndCoord
;
2289 RtlFreeHeap(GetProcessHeap(), 0, Reply
);
2296 IntWriteConsoleOutputCharacter(HANDLE hConsoleOutput
,
2300 LPDWORD lpNumberOfCharsWritten
,
2303 PCSRSS_API_REQUEST Request
;
2304 CSRSS_API_REPLY Reply
;
2306 ULONG SizeBytes
, CharSize
, nChars
;
2309 CharSize
= (bUnicode
? sizeof(WCHAR
) : sizeof(CHAR
));
2311 nChars
= min(nLength
, CSRSS_MAX_WRITE_CONSOLE_REQUEST
/ CharSize
);
2312 SizeBytes
= nChars
* CharSize
;
2314 Request
= RtlAllocateHeap(GetProcessHeap(), 0,
2315 sizeof(CSRSS_API_REQUEST
) + (nChars
* CharSize
));
2318 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2322 Request
->Type
= CSRSS_WRITE_CONSOLE_OUTPUT_CHAR
;
2323 Request
->Data
.WriteConsoleOutputCharRequest
.ConsoleHandle
= hConsoleOutput
;
2324 Request
->Data
.WriteConsoleOutputCharRequest
.Unicode
= bUnicode
;
2325 Request
->Data
.WriteConsoleOutputCharRequest
.Coord
= dwWriteCoord
;
2331 Request
->Data
.WriteConsoleOutputCharRequest
.Length
= min(nLength
, nChars
);
2332 BytesWrite
= Request
->Data
.WriteConsoleOutputCharRequest
.Length
* CharSize
;
2334 memcpy(&Request
->Data
.WriteConsoleOutputCharRequest
.String
[0], lpCharacter
, BytesWrite
);
2336 Status
= CsrClientCallServer(Request
, &Reply
,
2337 sizeof(CSRSS_API_REQUEST
) + BytesWrite
,
2338 sizeof(CSRSS_API_REPLY
));
2340 if(!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
2342 RtlFreeHeap(GetProcessHeap(), 0, Request
);
2343 SetLastErrorByStatus(Status
);
2347 nLength
-= Reply
.Data
.WriteConsoleOutputCharReply
.NrCharactersWritten
;
2348 lpCharacter
= (PVOID
)((ULONG_PTR
)lpCharacter
+ (ULONG_PTR
)(Reply
.Data
.WriteConsoleOutputCharReply
.NrCharactersWritten
* CharSize
));
2349 Written
+= Reply
.Data
.WriteConsoleOutputCharReply
.NrCharactersWritten
;
2351 Request
->Data
.WriteConsoleOutputCharRequest
.Coord
= Reply
.Data
.WriteConsoleOutputCharReply
.EndCoord
;
2354 RtlFreeHeap(GetProcessHeap(), 0, Request
);
2356 if(lpNumberOfCharsWritten
!= NULL
)
2358 *lpNumberOfCharsWritten
= Written
;
2365 /*--------------------------------------------------------------
2366 * WriteConsoleOutputCharacterA
2371 WriteConsoleOutputCharacterA(HANDLE hConsoleOutput
,
2375 LPDWORD lpNumberOfCharsWritten
)
2377 return IntWriteConsoleOutputCharacter(hConsoleOutput
,
2381 lpNumberOfCharsWritten
,
2386 /*--------------------------------------------------------------
2387 * WriteConsoleOutputCharacterW
2392 WriteConsoleOutputCharacterW(HANDLE hConsoleOutput
,
2393 LPCWSTR lpCharacter
,
2396 LPDWORD lpNumberOfCharsWritten
)
2398 return IntWriteConsoleOutputCharacter(hConsoleOutput
,
2402 lpNumberOfCharsWritten
,
2407 /*--------------------------------------------------------------
2408 * WriteConsoleOutputAttribute
2414 WriteConsoleOutputAttribute(
2415 HANDLE hConsoleOutput
,
2416 CONST WORD
*lpAttribute
,
2419 LPDWORD lpNumberOfAttrsWritten
2422 PCSRSS_API_REQUEST Request
;
2423 CSRSS_API_REPLY Reply
;
2428 Request
= RtlAllocateHeap(GetProcessHeap(), 0,
2429 sizeof(CSRSS_API_REQUEST
) +
2430 min(nLength
, CSRSS_MAX_WRITE_CONSOLE_OUTPUT_ATTRIB
));
2433 SetLastError( ERROR_OUTOFMEMORY
);
2436 Request
->Type
= CSRSS_WRITE_CONSOLE_OUTPUT_ATTRIB
;
2437 Request
->Data
.WriteConsoleOutputAttribRequest
.ConsoleHandle
= hConsoleOutput
;
2438 Request
->Data
.WriteConsoleOutputAttribRequest
.Coord
= dwWriteCoord
;
2439 if( lpNumberOfAttrsWritten
)
2440 *lpNumberOfAttrsWritten
= nLength
;
2443 Size
= nLength
> CSRSS_MAX_WRITE_CONSOLE_OUTPUT_ATTRIB
? CSRSS_MAX_WRITE_CONSOLE_OUTPUT_ATTRIB
: nLength
;
2444 Request
->Data
.WriteConsoleOutputAttribRequest
.Length
= Size
;
2445 for( c
= 0; c
< Size
; c
++ )
2446 Request
->Data
.WriteConsoleOutputAttribRequest
.String
[c
] = (char)lpAttribute
[c
];
2447 Status
= CsrClientCallServer( Request
, &Reply
, sizeof( CSRSS_API_REQUEST
) + (Size
* 2), sizeof( CSRSS_API_REPLY
) );
2448 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
2450 RtlFreeHeap( GetProcessHeap(), 0, Request
);
2451 SetLastErrorByStatus ( Status
);
2455 lpAttribute
+= Size
;
2456 Request
->Data
.WriteConsoleOutputAttribRequest
.Coord
= Reply
.Data
.WriteConsoleOutputAttribReply
.EndCoord
;
2459 RtlFreeHeap( GetProcessHeap(), 0, Request
);
2464 /*--------------------------------------------------------------
2465 * FillConsoleOutputAttribute
2471 FillConsoleOutputAttribute(
2472 HANDLE hConsoleOutput
,
2476 LPDWORD lpNumberOfAttrsWritten
2479 CSRSS_API_REQUEST Request
;
2480 CSRSS_API_REPLY Reply
;
2483 Request
.Type
= CSRSS_FILL_OUTPUT_ATTRIB
;
2484 Request
.Data
.FillOutputAttribRequest
.ConsoleHandle
= hConsoleOutput
;
2485 Request
.Data
.FillOutputAttribRequest
.Attribute
= wAttribute
;
2486 Request
.Data
.FillOutputAttribRequest
.Coord
= dwWriteCoord
;
2487 Request
.Data
.FillOutputAttribRequest
.Length
= nLength
;
2488 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
2489 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
2491 SetLastErrorByStatus ( Status
);
2494 if( lpNumberOfAttrsWritten
)
2495 *lpNumberOfAttrsWritten
= nLength
;
2500 /*--------------------------------------------------------------
2508 HANDLE hConsoleHandle
,
2512 CSRSS_API_REQUEST Request
;
2513 CSRSS_API_REPLY Reply
;
2516 Request
.Type
= CSRSS_GET_CONSOLE_MODE
;
2517 Request
.Data
.GetConsoleModeRequest
.ConsoleHandle
= hConsoleHandle
;
2518 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
2519 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
2521 SetLastErrorByStatus ( Status
);
2524 *lpMode
= Reply
.Data
.GetConsoleModeReply
.ConsoleMode
;
2529 /*--------------------------------------------------------------
2530 * GetNumberOfConsoleInputEvents
2536 GetNumberOfConsoleInputEvents(
2537 HANDLE hConsoleInput
,
2538 LPDWORD lpNumberOfEvents
2541 CSRSS_API_REQUEST Request
;
2542 CSRSS_API_REPLY Reply
;
2545 if(lpNumberOfEvents
== NULL
)
2547 SetLastError(ERROR_INVALID_PARAMETER
);
2551 Request
.Type
= CSRSS_GET_NUM_INPUT_EVENTS
;
2552 Request
.Data
.GetNumInputEventsRequest
.ConsoleHandle
= hConsoleInput
;
2553 Status
= CsrClientCallServer(&Request
, &Reply
, sizeof(CSRSS_API_REQUEST
), sizeof(CSRSS_API_REPLY
));
2554 if(!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
2556 SetLastErrorByStatus(Status
);
2560 *lpNumberOfEvents
= Reply
.Data
.GetNumInputEventsReply
.NumInputEvents
;
2566 /*--------------------------------------------------------------
2567 * GetLargestConsoleWindowSize
2573 GetLargestConsoleWindowSize(
2574 HANDLE hConsoleOutput
2577 COORD Coord
= {80,25};
2578 DPRINT1("GetLargestConsoleWindowSize(0x%x) UNIMPLEMENTED!\n", hConsoleOutput
);
2579 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2584 /*--------------------------------------------------------------
2585 * GetConsoleCursorInfo
2591 GetConsoleCursorInfo(
2592 HANDLE hConsoleOutput
,
2593 PCONSOLE_CURSOR_INFO lpConsoleCursorInfo
2596 CSRSS_API_REQUEST Request
;
2597 CSRSS_API_REPLY Reply
;
2600 Request
.Type
= CSRSS_GET_CURSOR_INFO
;
2601 Request
.Data
.GetCursorInfoRequest
.ConsoleHandle
= hConsoleOutput
;
2602 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
2604 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
2606 SetLastErrorByStatus ( Status
);
2609 *lpConsoleCursorInfo
= Reply
.Data
.GetCursorInfoReply
.Info
;
2614 /*--------------------------------------------------------------
2615 * GetNumberOfConsoleMouseButtons
2621 GetNumberOfConsoleMouseButtons(
2622 LPDWORD lpNumberOfMouseButtons
2625 DPRINT1("GetNumberOfConsoleMouseButtons(0x%x) UNIMPLEMENTED!\n", lpNumberOfMouseButtons
);
2626 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2631 /*--------------------------------------------------------------
2639 HANDLE hConsoleHandle
,
2643 CSRSS_API_REQUEST Request
;
2644 CSRSS_API_REPLY Reply
;
2647 Request
.Type
= CSRSS_SET_CONSOLE_MODE
;
2648 Request
.Data
.SetConsoleModeRequest
.ConsoleHandle
= hConsoleHandle
;
2649 Request
.Data
.SetConsoleModeRequest
.Mode
= dwMode
;
2650 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
2651 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
2653 SetLastErrorByStatus ( Status
);
2660 /*--------------------------------------------------------------
2661 * SetConsoleActiveScreenBuffer
2667 SetConsoleActiveScreenBuffer(
2668 HANDLE hConsoleOutput
2671 CSRSS_API_REQUEST Request
;
2672 CSRSS_API_REPLY Reply
;
2675 Request
.Type
= CSRSS_SET_SCREEN_BUFFER
;
2676 Request
.Data
.SetScreenBufferRequest
.OutputHandle
= hConsoleOutput
;
2677 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
2678 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
2680 SetLastErrorByStatus ( Status
);
2687 /*--------------------------------------------------------------
2688 * FlushConsoleInputBuffer
2694 FlushConsoleInputBuffer(
2695 HANDLE hConsoleInput
2698 CSRSS_API_REQUEST Request
;
2699 CSRSS_API_REPLY Reply
;
2702 Request
.Type
= CSRSS_FLUSH_INPUT_BUFFER
;
2703 Request
.Data
.FlushInputBufferRequest
.ConsoleInput
= hConsoleInput
;
2704 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
2705 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
2707 SetLastErrorByStatus ( Status
);
2714 /*--------------------------------------------------------------
2715 * SetConsoleScreenBufferSize
2721 SetConsoleScreenBufferSize(
2722 HANDLE hConsoleOutput
,
2726 DPRINT1("SetConsoleScreenBufferSize(0x%x, 0x%x) UNIMPLEMENTED!\n", hConsoleOutput
, dwSize
);
2727 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2731 /*--------------------------------------------------------------
2732 * SetConsoleCursorInfo
2738 SetConsoleCursorInfo(
2739 HANDLE hConsoleOutput
,
2740 CONST CONSOLE_CURSOR_INFO
*lpConsoleCursorInfo
2743 CSRSS_API_REQUEST Request
;
2744 CSRSS_API_REPLY Reply
;
2747 Request
.Type
= CSRSS_SET_CURSOR_INFO
;
2748 Request
.Data
.SetCursorInfoRequest
.ConsoleHandle
= hConsoleOutput
;
2749 Request
.Data
.SetCursorInfoRequest
.Info
= *lpConsoleCursorInfo
;
2750 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
2752 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
2754 SetLastErrorByStatus ( Status
);
2762 IntScrollConsoleScreenBuffer(HANDLE hConsoleOutput
,
2763 PSMALL_RECT lpScrollRectangle
,
2764 PSMALL_RECT lpClipRectangle
,
2765 COORD dwDestinationOrigin
,
2769 CSRSS_API_REQUEST Request
;
2770 CSRSS_API_REPLY Reply
;
2773 Request
.Type
= CSRSS_SCROLL_CONSOLE_SCREEN_BUFFER
;
2774 Request
.Data
.ScrollConsoleScreenBufferRequest
.ConsoleHandle
= hConsoleOutput
;
2775 Request
.Data
.ScrollConsoleScreenBufferRequest
.Unicode
= bUnicode
;
2776 Request
.Data
.ScrollConsoleScreenBufferRequest
.ScrollRectangle
= *lpScrollRectangle
;
2778 if(lpClipRectangle
!= NULL
)
2780 Request
.Data
.ScrollConsoleScreenBufferRequest
.UseClipRectangle
= TRUE
;
2781 Request
.Data
.ScrollConsoleScreenBufferRequest
.ClipRectangle
= *lpClipRectangle
;
2785 Request
.Data
.ScrollConsoleScreenBufferRequest
.UseClipRectangle
= FALSE
;
2788 Request
.Data
.ScrollConsoleScreenBufferRequest
.DestinationOrigin
= dwDestinationOrigin
;
2789 Request
.Data
.ScrollConsoleScreenBufferRequest
.Fill
= *lpFill
;
2790 Status
= CsrClientCallServer(&Request
, &Reply
,
2791 sizeof(CSRSS_API_REQUEST
),
2792 sizeof(CSRSS_API_REPLY
));
2794 if(!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
2796 SetLastErrorByStatus(Status
);
2804 /*--------------------------------------------------------------
2805 * ScrollConsoleScreenBufferA
2811 ScrollConsoleScreenBufferA(
2812 HANDLE hConsoleOutput
,
2813 CONST SMALL_RECT
*lpScrollRectangle
,
2814 CONST SMALL_RECT
*lpClipRectangle
,
2815 COORD dwDestinationOrigin
,
2816 CONST CHAR_INFO
*lpFill
2819 return IntScrollConsoleScreenBuffer(hConsoleOutput
,
2820 (PSMALL_RECT
)lpScrollRectangle
,
2821 (PSMALL_RECT
)lpClipRectangle
,
2822 dwDestinationOrigin
,
2828 /*--------------------------------------------------------------
2829 * ScrollConsoleScreenBufferW
2835 ScrollConsoleScreenBufferW(
2836 HANDLE hConsoleOutput
,
2837 CONST SMALL_RECT
*lpScrollRectangle
,
2838 CONST SMALL_RECT
*lpClipRectangle
,
2839 COORD dwDestinationOrigin
,
2840 CONST CHAR_INFO
*lpFill
2843 return IntScrollConsoleScreenBuffer(hConsoleOutput
,
2844 (PSMALL_RECT
)lpScrollRectangle
,
2845 (PSMALL_RECT
)lpClipRectangle
,
2846 dwDestinationOrigin
,
2852 /*--------------------------------------------------------------
2853 * SetConsoleWindowInfo
2859 SetConsoleWindowInfo(
2860 HANDLE hConsoleOutput
,
2862 CONST SMALL_RECT
*lpConsoleWindow
2865 DPRINT1("SetConsoleWindowInfo(0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", hConsoleOutput
, bAbsolute
, lpConsoleWindow
);
2866 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2871 /*--------------------------------------------------------------
2872 * SetConsoleTextAttribute
2878 SetConsoleTextAttribute(
2879 HANDLE hConsoleOutput
,
2883 CSRSS_API_REQUEST Request
;
2884 CSRSS_API_REPLY Reply
;
2887 Request
.Type
= CSRSS_SET_ATTRIB
;
2888 Request
.Data
.SetAttribRequest
.ConsoleHandle
= hConsoleOutput
;
2889 Request
.Data
.SetAttribRequest
.Attrib
= wAttributes
;
2890 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
2891 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
2893 SetLastErrorByStatus ( Status
);
2901 AddConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine
)
2903 if (HandlerRoutine
== NULL
)
2905 IgnoreCtrlEvents
= TRUE
;
2911 if (CtrlHandlers
== NULL
)
2913 CtrlHandlers
= RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY
,
2914 NrCtrlHandlers
* sizeof(PHANDLER_ROUTINE
));
2918 CtrlHandlers
= RtlReAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY
,
2919 (PVOID
)CtrlHandlers
,
2920 NrCtrlHandlers
* sizeof(PHANDLER_ROUTINE
));
2922 if (CtrlHandlers
== NULL
)
2925 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2928 CtrlHandlers
[NrCtrlHandlers
- 1] = HandlerRoutine
;
2935 RemoveConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine
)
2939 if (HandlerRoutine
== NULL
)
2941 IgnoreCtrlEvents
= FALSE
;
2946 for (i
= 0; i
< NrCtrlHandlers
; i
++)
2948 if ( ((void*)(CtrlHandlers
[i
])) == (void*)HandlerRoutine
)
2951 memmove(CtrlHandlers
+ i
, CtrlHandlers
+ i
+ 1,
2952 (NrCtrlHandlers
- i
) * sizeof(PHANDLER_ROUTINE
));
2954 RtlReAllocateHeap(RtlGetProcessHeap(),
2956 (PVOID
)CtrlHandlers
,
2957 NrCtrlHandlers
* sizeof(PHANDLER_ROUTINE
));
2970 SetConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine
,
2975 RtlEnterCriticalSection(&DllLock
);
2978 Ret
= AddConsoleCtrlHandler(HandlerRoutine
);
2982 Ret
= RemoveConsoleCtrlHandler(HandlerRoutine
);
2984 RtlLeaveCriticalSection(&DllLock
);
2989 /*--------------------------------------------------------------
2990 * GenerateConsoleCtrlEvent
2995 GenerateConsoleCtrlEvent(
2997 DWORD dwProcessGroupId
3000 DPRINT1("GenerateConsoleCtrlEvent(0x%x, 0x%x) UNIMPLEMENTED!\n", dwCtrlEvent
, dwProcessGroupId
);
3001 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3006 /*--------------------------------------------------------------
3014 LPWSTR lpConsoleTitle
,
3018 CSRSS_API_REQUEST Request
;
3019 PCSRSS_API_REPLY Reply
;
3023 hConsole
= CreateFileW(L
"CONIN$", GENERIC_READ
, 0, NULL
, OPEN_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
3024 if (hConsole
== INVALID_HANDLE_VALUE
)
3029 Reply
= RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CSRSS_API_REPLY
) + CSRSS_MAX_TITLE_LENGTH
* sizeof(WCHAR
));
3032 CloseHandle(hConsole
);
3033 SetLastError(ERROR_OUTOFMEMORY
);
3037 Request
.Type
= CSRSS_GET_TITLE
;
3038 Request
.Data
.GetTitleRequest
.ConsoleHandle
= hConsole
;
3040 Status
= CsrClientCallServer(&Request
, Reply
, sizeof(CSRSS_API_REQUEST
), sizeof(CSRSS_API_REPLY
) + CSRSS_MAX_TITLE_LENGTH
* sizeof(WCHAR
));
3041 CloseHandle(hConsole
);
3042 if(!NT_SUCCESS(Status
) || !(NT_SUCCESS(Status
= Reply
->Status
)))
3044 SetLastErrorByStatus(Status
);
3045 RtlFreeHeap(GetProcessHeap(), 0, Reply
);
3049 if(nSize
* sizeof(WCHAR
) < Reply
->Data
.GetTitleReply
.Length
)
3051 wcsncpy(lpConsoleTitle
, Reply
->Data
.GetTitleReply
.Title
, nSize
- 1);
3052 lpConsoleTitle
[nSize
--] = L
'\0';
3056 nSize
= Reply
->Data
.GetTitleReply
.Length
/ sizeof (WCHAR
);
3057 wcscpy(lpConsoleTitle
, Reply
->Data
.GetTitleReply
.Title
);
3058 lpConsoleTitle
[nSize
] = L
'\0';
3061 RtlFreeHeap(GetProcessHeap(), 0, Reply
);
3066 /*--------------------------------------------------------------
3076 LPSTR lpConsoleTitle
,
3080 wchar_t WideTitle
[CSRSS_MAX_TITLE_LENGTH
];
3081 DWORD nWideTitle
= sizeof WideTitle
;
3084 if (!lpConsoleTitle
|| !nSize
) return 0;
3085 nWideTitle
= GetConsoleTitleW( (LPWSTR
) WideTitle
, nWideTitle
);
3086 if (!nWideTitle
) return 0;
3088 if ( (nWritten
= WideCharToMultiByte(
3089 CP_ACP
, // ANSI code page
3090 0, // performance and mapping flags
3091 (LPWSTR
) WideTitle
, // address of wide-character string
3092 nWideTitle
, // number of characters in string
3093 lpConsoleTitle
, // address of buffer for new string
3094 nSize
, // size of buffer
3099 lpConsoleTitle
[nWritten
] = '\0';
3107 /*--------------------------------------------------------------
3115 LPCWSTR lpConsoleTitle
3118 PCSRSS_API_REQUEST Request
;
3119 CSRSS_API_REPLY Reply
;
3124 hConsole
= CreateFileW(L
"CONIN$", GENERIC_WRITE
, 0, NULL
, OPEN_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
3125 if (hConsole
== INVALID_HANDLE_VALUE
)
3130 Request
= RtlAllocateHeap(GetProcessHeap(),
3132 sizeof(CSRSS_API_REQUEST
) + CSRSS_MAX_SET_TITLE_REQUEST
);
3133 if (Request
== NULL
)
3135 CloseHandle(hConsole
);
3136 SetLastError(ERROR_OUTOFMEMORY
);
3140 Request
->Type
= CSRSS_SET_TITLE
;
3141 Request
->Data
.SetTitleRequest
.Console
= hConsole
;
3143 for( c
= 0; lpConsoleTitle
[c
] && c
< CSRSS_MAX_TITLE_LENGTH
; c
++ )
3144 Request
->Data
.SetTitleRequest
.Title
[c
] = lpConsoleTitle
[c
];
3146 Request
->Data
.SetTitleRequest
.Title
[c
] = 0;
3147 Request
->Data
.SetTitleRequest
.Length
= c
;
3148 Status
= CsrClientCallServer(Request
,
3150 sizeof(CSRSS_API_REQUEST
) +
3152 sizeof(CSRSS_API_REPLY
));
3153 CloseHandle(hConsole
);
3154 if (!NT_SUCCESS(Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
3156 RtlFreeHeap( GetProcessHeap(), 0, Request
);
3157 SetLastErrorByStatus (Status
);
3160 RtlFreeHeap( GetProcessHeap(), 0, Request
);
3165 /*--------------------------------------------------------------
3175 LPCSTR lpConsoleTitle
3178 PCSRSS_API_REQUEST Request
;
3179 CSRSS_API_REPLY Reply
;
3184 hConsole
= CreateFileW(L
"CONIN$", GENERIC_WRITE
, 0, NULL
, OPEN_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
3185 if (hConsole
== INVALID_HANDLE_VALUE
)
3190 Request
= RtlAllocateHeap(GetProcessHeap(),
3192 sizeof(CSRSS_API_REQUEST
) + CSRSS_MAX_SET_TITLE_REQUEST
);
3193 if (Request
== NULL
)
3195 CloseHandle(hConsole
);
3196 SetLastError(ERROR_OUTOFMEMORY
);
3200 Request
->Type
= CSRSS_SET_TITLE
;
3201 Request
->Data
.SetTitleRequest
.Console
= hConsole
;
3203 for( c
= 0; lpConsoleTitle
[c
] && c
< CSRSS_MAX_TITLE_LENGTH
; c
++ )
3204 Request
->Data
.SetTitleRequest
.Title
[c
] = lpConsoleTitle
[c
];
3206 Request
->Data
.SetTitleRequest
.Title
[c
] = 0;
3207 Request
->Data
.SetTitleRequest
.Length
= c
;
3208 Status
= CsrClientCallServer(Request
,
3210 sizeof(CSRSS_API_REQUEST
) +
3212 sizeof(CSRSS_API_REPLY
));
3213 CloseHandle(hConsole
);
3214 if (!NT_SUCCESS(Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
3216 RtlFreeHeap( GetProcessHeap(), 0, Request
);
3217 SetLastErrorByStatus (Status
);
3220 RtlFreeHeap( GetProcessHeap(), 0, Request
);
3225 /*--------------------------------------------------------------
3226 * CreateConsoleScreenBuffer
3232 CreateConsoleScreenBuffer(
3233 DWORD dwDesiredAccess
,
3235 CONST SECURITY_ATTRIBUTES
*lpSecurityAttributes
,
3237 LPVOID lpScreenBufferData
3240 // FIXME: don't ignore access, share mode, and security
3241 CSRSS_API_REQUEST Request
;
3242 CSRSS_API_REPLY Reply
;
3245 Request
.Type
= CSRSS_CREATE_SCREEN_BUFFER
;
3246 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
3247 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
3249 SetLastErrorByStatus ( Status
);
3252 return Reply
.Data
.CreateScreenBufferReply
.OutputHandle
;
3256 /*--------------------------------------------------------------
3263 GetConsoleCP( VOID
)
3265 CSRSS_API_REQUEST Request
;
3266 CSRSS_API_REPLY Reply
;
3269 Request
.Type
= CSRSS_GET_CONSOLE_CP
;
3270 Status
= CsrClientCallServer(&Request
, &Reply
, sizeof(CSRSS_API_REQUEST
),
3271 sizeof(CSRSS_API_REPLY
));
3272 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
3274 SetLastErrorByStatus (Status
);
3277 return Reply
.Data
.GetConsoleCodePage
.CodePage
;
3281 /*--------------------------------------------------------------
3292 CSRSS_API_REQUEST Request
;
3293 CSRSS_API_REPLY Reply
;
3296 Request
.Type
= CSRSS_SET_CONSOLE_CP
;
3297 Request
.Data
.SetConsoleCodePage
.CodePage
= wCodePageID
;
3298 Status
= CsrClientCallServer(&Request
, &Reply
, sizeof(CSRSS_API_REQUEST
),
3299 sizeof(CSRSS_API_REPLY
));
3300 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
3302 SetLastErrorByStatus (Status
);
3304 return NT_SUCCESS(Status
);
3308 /*--------------------------------------------------------------
3309 * GetConsoleOutputCP
3315 GetConsoleOutputCP( VOID
)
3317 CSRSS_API_REQUEST Request
;
3318 CSRSS_API_REPLY Reply
;
3321 Request
.Type
= CSRSS_GET_CONSOLE_OUTPUT_CP
;
3322 Status
= CsrClientCallServer(&Request
, &Reply
, sizeof(CSRSS_API_REQUEST
),
3323 sizeof(CSRSS_API_REPLY
));
3324 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
3326 SetLastErrorByStatus (Status
);
3329 return Reply
.Data
.GetConsoleOutputCodePage
.CodePage
;
3333 /*--------------------------------------------------------------
3334 * SetConsoleOutputCP
3344 CSRSS_API_REQUEST Request
;
3345 CSRSS_API_REPLY Reply
;
3348 Request
.Type
= CSRSS_SET_CONSOLE_OUTPUT_CP
;
3349 Request
.Data
.SetConsoleOutputCodePage
.CodePage
= wCodePageID
;
3350 Status
= CsrClientCallServer(&Request
, &Reply
, sizeof(CSRSS_API_REQUEST
),
3351 sizeof(CSRSS_API_REPLY
));
3352 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
3354 SetLastErrorByStatus (Status
);
3356 return NT_SUCCESS(Status
);
3360 /*--------------------------------------------------------------
3361 * GetConsoleProcessList
3366 GetConsoleProcessList(LPDWORD lpdwProcessList
,
3367 DWORD dwProcessCount
)
3369 DPRINT1("GetConsoleProcessList(0x%x, 0x%x) UNIMPLEMENTED!\n", lpdwProcessList
, dwProcessCount
);
3370 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3376 /*--------------------------------------------------------------
3377 * GetConsoleSelectionInfo
3382 GetConsoleSelectionInfo(PCONSOLE_SELECTION_INFO lpConsoleSelectionInfo
)
3384 DPRINT1("GetConsoleSelectionInfo(0x%x) UNIMPLEMENTED!\n", lpConsoleSelectionInfo
);
3385 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3391 /*--------------------------------------------------------------
3397 AttachConsole(DWORD dwProcessId
)
3399 DPRINT1("AttachConsole(0x%x) UNIMPLEMENTED!\n", dwProcessId
);
3400 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3404 /*--------------------------------------------------------------
3410 GetConsoleWindow (VOID
)
3412 CSRSS_API_REQUEST Request
;
3413 CSRSS_API_REPLY Reply
;
3416 Request
.Type
= CSRSS_GET_CONSOLE_WINDOW
;
3417 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
3418 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
3420 SetLastErrorByStatus (Status
);
3423 return Reply
.Data
.GetConsoleWindowReply
.WindowHandle
;
3427 /*--------------------------------------------------------------
3432 BOOL STDCALL
SetConsoleIcon(HICON hicon
)
3434 CSRSS_API_REQUEST Request
;
3435 CSRSS_API_REPLY Reply
;
3438 Request
.Type
= CSRSS_SET_CONSOLE_ICON
;
3439 Request
.Data
.SetConsoleIconRequest
.WindowIcon
= hicon
;
3440 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
3441 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
3443 SetLastErrorByStatus (Status
);
3446 return NT_SUCCESS(Status
);
3450 /*--------------------------------------------------------------
3451 * SetConsoleInputExeNameW
3456 SetConsoleInputExeNameW(LPCWSTR lpInputExeName
)
3459 int lenName
= lstrlenW(lpInputExeName
);
3462 lenName
> (sizeof(InputExeName
) / sizeof(InputExeName
[0])) - 1)
3464 /* Fail if string is empty or too long */
3465 SetLastError(ERROR_INVALID_PARAMETER
);
3469 RtlEnterCriticalSection(&ConsoleLock
);
3470 /* wrap copying into SEH as we may copy from invalid buffer and in case of an
3471 exception the console lock would've never been released, which would cause
3472 further calls (if the exception was handled by the caller) to recursively
3473 acquire the lock... */
3476 RtlCopyMemory(InputExeName
, lpInputExeName
, lenName
* sizeof(WCHAR
));
3477 InputExeName
[lenName
] = L
'\0';
3483 SetLastErrorByStatus(_SEH_GetExceptionCode());
3486 RtlLeaveCriticalSection(&ConsoleLock
);
3492 /*--------------------------------------------------------------
3493 * SetConsoleInputExeNameA
3498 SetConsoleInputExeNameA(LPCSTR lpInputExeName
)
3500 ANSI_STRING InputExeNameA
;
3501 UNICODE_STRING InputExeNameU
;
3505 RtlInitAnsiString(&InputExeNameA
, lpInputExeName
);
3507 if(InputExeNameA
.Length
< sizeof(InputExeNameA
.Buffer
[0]) ||
3508 InputExeNameA
.Length
>= (sizeof(InputExeName
) / sizeof(InputExeName
[0])) - 1)
3510 /* Fail if string is empty or too long */
3511 SetLastError(ERROR_INVALID_PARAMETER
);
3515 Status
= RtlAnsiStringToUnicodeString(&InputExeNameU
, &InputExeNameA
, TRUE
);
3516 if(NT_SUCCESS(Status
))
3518 Ret
= SetConsoleInputExeNameW(InputExeNameU
.Buffer
);
3519 RtlFreeUnicodeString(&InputExeNameU
);
3523 SetLastErrorByStatus(Status
);
3531 /*--------------------------------------------------------------
3532 * GetConsoleInputExeNameW
3537 GetConsoleInputExeNameW(DWORD nBufferLength
, LPWSTR lpBuffer
)
3541 RtlEnterCriticalSection(&ConsoleLock
);
3543 lenName
= lstrlenW(InputExeName
);
3544 if(lenName
>= nBufferLength
)
3546 /* buffer is not large enough, return the required size */
3547 RtlLeaveCriticalSection(&ConsoleLock
);
3551 /* wrap copying into SEH as we may copy to invalid buffer and in case of an
3552 exception the console lock would've never been released, which would cause
3553 further calls (if the exception was handled by the caller) to recursively
3554 acquire the lock... */
3557 RtlCopyMemory(lpBuffer
, InputExeName
, (lenName
+ 1) * sizeof(WCHAR
));
3562 SetLastErrorByStatus(_SEH_GetExceptionCode());
3566 RtlLeaveCriticalSection(&ConsoleLock
);
3572 /*--------------------------------------------------------------
3573 * GetConsoleInputExeNameA
3578 GetConsoleInputExeNameA(DWORD nBufferLength
, LPSTR lpBuffer
)
3583 if(nBufferLength
> 0)
3585 Buffer
= RtlAllocateHeap(RtlGetProcessHeap(), 0, nBufferLength
* sizeof(WCHAR
));
3588 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3597 Ret
= GetConsoleInputExeNameW(nBufferLength
, Buffer
);
3598 if(nBufferLength
> 0)
3602 UNICODE_STRING BufferU
;
3603 ANSI_STRING BufferA
;
3605 RtlInitUnicodeString(&BufferU
, Buffer
);
3608 BufferA
.MaximumLength
= nBufferLength
;
3609 BufferA
.Buffer
= lpBuffer
;
3611 RtlUnicodeStringToAnsiString(&BufferA
, &BufferU
, FALSE
);
3614 RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer
);