1 /* $Id: console.c,v 1.76 2004/06/13 20:04:56 navaraf 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 #define _NOACHS(__X) (sizeof(__X) / sizeof((__X)[0]))
23 extern BOOL WINAPI
DefaultConsoleCtrlHandler(DWORD Event
);
24 extern __declspec(noreturn
) VOID CALLBACK
ConsoleControlDispatcher(DWORD CodeAndFlag
);
25 extern CRITICAL_SECTION ConsoleLock
;
26 extern BOOL WINAPI
IsDebuggerPresent(VOID
);
29 /* GLOBALS *******************************************************************/
31 static BOOL IgnoreCtrlEvents
= FALSE
;
33 static PHANDLER_ROUTINE
* CtrlHandlers
= NULL
;
34 static ULONG NrCtrlHandlers
= 0;
36 /* Default Console Control Handler *******************************************/
38 BOOL WINAPI
DefaultConsoleCtrlHandler(DWORD Event
)
43 DPRINT("Ctrl-C Event\n");
47 case CTRL_BREAK_EVENT
:
48 DPRINT("Ctrl-Break Event\n");
52 case CTRL_SHUTDOWN_EVENT
:
53 DPRINT("Ctrl Shutdown Event\n");
56 case CTRL_CLOSE_EVENT
:
57 DPRINT("Ctrl Close Event\n");
60 case CTRL_LOGOFF_EVENT
:
61 DPRINT("Ctrl Logoff Event\n");
64 // ExitProcess((UINT)&ExitCode);
69 __declspec(noreturn
) VOID CALLBACK
ConsoleControlDispatcher(DWORD CodeAndFlag
)
72 DWORD nCode
= CodeAndFlag
& MAXLONG
;
75 SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST
);
80 case CTRL_BREAK_EVENT
:
82 if(IsDebuggerPresent())
84 EXCEPTION_RECORD erException
;
85 erException
.ExceptionCode
=
86 (nCode
== CTRL_C_EVENT
? DBG_CONTROL_C
: DBG_CONTROL_BREAK
);
87 erException
.ExceptionFlags
= 0;
88 erException
.ExceptionRecord
= NULL
;
89 erException
.ExceptionAddress
= &DefaultConsoleCtrlHandler
;
90 erException
.NumberParameters
= 0;
91 RtlRaiseException(&erException
);
93 RtlEnterCriticalSection(&ConsoleLock
);
95 if(!(nCode
== CTRL_C_EVENT
&&
96 NtCurrentPeb()->ProcessParameters
->ProcessGroup
& 1))
98 for(i
= NrCtrlHandlers
; i
> 0; -- i
)
99 if(CtrlHandlers
[i
- 1](nCode
)) break;
101 RtlLeaveCriticalSection(&ConsoleLock
);
104 case CTRL_CLOSE_EVENT
:
105 case CTRL_LOGOFF_EVENT
:
106 case CTRL_SHUTDOWN_EVENT
:
109 default: ExitThread(0);
112 RtlEnterCriticalSection(&ConsoleLock
);
114 if(!(nCode
== CTRL_C_EVENT
&&
115 NtCurrentPeb()->ProcessParameters
->ProcessGroup
& 1))
120 if (i
== 1 && (CodeAndFlag
& MINLONG
) &&
121 (nCode
== CTRL_LOGOFF_EVENT
|| nCode
== CTRL_SHUTDOWN_EVENT
))
124 if(CtrlHandlers
[i
- 1](nCode
))
128 case CTRL_CLOSE_EVENT
:
129 case CTRL_LOGOFF_EVENT
:
130 case CTRL_SHUTDOWN_EVENT
:
131 nExitCode
= CodeAndFlag
;
138 RtlLeaveCriticalSection(&ConsoleLock
);
139 ExitThread(nExitCode
);
143 /* FUNCTIONS *****************************************************************/
149 AddConsoleAliasA (LPSTR Source
,
153 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
162 AddConsoleAliasW (LPWSTR Source
,
166 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
175 ConsoleMenuControl (HANDLE hConsole
,
182 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
191 DuplicateConsoleHandle (HANDLE hConsole
,
192 DWORD dwDesiredAccess
,
196 CSRSS_API_REQUEST Request
;
197 CSRSS_API_REPLY Reply
;
200 if (IsConsoleHandle (hConsole
) == FALSE
)
202 SetLastError (ERROR_INVALID_PARAMETER
);
203 return INVALID_HANDLE_VALUE
;
206 Request
.Type
= CSRSS_DUPLICATE_HANDLE
;
207 Request
.Data
.DuplicateHandleRequest
.Handle
= hConsole
;
208 Request
.Data
.DuplicateHandleRequest
.ProcessId
= GetCurrentProcessId();
209 Status
= CsrClientCallServer(&Request
,
211 sizeof(CSRSS_API_REQUEST
),
212 sizeof(CSRSS_API_REPLY
));
213 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
=Reply
.Status
))
215 SetLastErrorByStatus(Status
);
216 return INVALID_HANDLE_VALUE
;
218 return Reply
.Data
.DuplicateHandleReply
.Handle
;
226 ExpungeConsoleCommandHistoryW (DWORD Unknown0
)
231 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
240 ExpungeConsoleCommandHistoryA (DWORD Unknown0
)
245 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
254 GetConsoleAliasW (DWORD Unknown0
,
262 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
271 GetConsoleAliasA (DWORD Unknown0
,
279 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
288 GetConsoleAliasExesW (DWORD Unknown0
,
294 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
303 GetConsoleAliasExesA (DWORD Unknown0
,
309 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
318 GetConsoleAliasExesLengthA (VOID
)
323 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
332 GetConsoleAliasExesLengthW (VOID
)
337 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
346 GetConsoleAliasesW (DWORD Unknown0
,
353 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
362 GetConsoleAliasesA (DWORD Unknown0
,
369 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
378 GetConsoleAliasesLengthW (DWORD Unknown0
)
383 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
392 GetConsoleAliasesLengthA (DWORD Unknown0
)
397 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
406 GetConsoleCommandHistoryW (DWORD Unknown0
,
413 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
422 GetConsoleCommandHistoryA (DWORD Unknown0
,
429 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
438 GetConsoleCommandHistoryLengthW (DWORD Unknown0
)
443 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
452 GetConsoleCommandHistoryLengthA (DWORD Unknown0
)
457 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
465 GetConsoleDisplayMode (LPDWORD lpdwMode
)
467 * FUNCTION: Get the console display mode
469 * lpdwMode - Address of variable that receives the current value
471 * STATUS: Undocumented
474 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
483 GetConsoleFontInfo (DWORD Unknown0
,
491 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
500 GetConsoleFontSize(HANDLE hConsoleOutput
,
503 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
512 GetConsoleHardwareState (HANDLE hConsole
,
519 CSRSS_API_REQUEST Request
;
520 CSRSS_API_REPLY Reply
;
523 Request
.Type
= CSRSS_SETGET_CONSOLE_HW_STATE
;
524 Request
.Data
.ConsoleHardwareStateRequest
.ConsoleHandle
= hConsole
;
525 Request
.Data
.ConsoleHardwareStateRequest
.SetGet
= CONSOLE_HARDWARE_STATE_GET
;
527 Status
= CsrClientCallServer(& Request
,
529 sizeof(CSRSS_API_REQUEST
),
530 sizeof(CSRSS_API_REPLY
));
531 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
533 SetLastErrorByStatus(Status
);
536 *State
= Reply
.Data
.ConsoleHardwareStateReply
.State
;
545 GetConsoleInputWaitHandle (VOID
)
550 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
559 GetCurrentConsoleFont(HANDLE hConsoleOutput
,
561 PCONSOLE_FONT_INFO lpConsoleCurrentFont
)
563 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
572 GetNumberOfConsoleFonts (VOID
)
577 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
578 return 1; /* FIXME: call csrss.exe */
586 InvalidateConsoleDIBits (DWORD Unknown0
,
592 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
601 OpenConsoleW (LPWSTR wsName
,
602 DWORD dwDesiredAccess
,
604 DWORD dwCreationDistribution
)
609 CSRSS_API_REQUEST Request
;
610 CSRSS_API_REPLY Reply
;
611 PHANDLE phConsole
= NULL
;
612 NTSTATUS Status
= STATUS_SUCCESS
;
615 if(0 == _wcsicmp(wsName
, L
"CONIN$"))
617 Request
.Type
= CSRSS_GET_INPUT_HANDLE
;
618 phConsole
= & Reply
.Data
.GetInputHandleReply
.InputHandle
;
620 else if (0 == _wcsicmp(wsName
, L
"CONOUT$"))
622 Request
.Type
= CSRSS_GET_OUTPUT_HANDLE
;
623 phConsole
= & Reply
.Data
.GetOutputHandleReply
.OutputHandle
;
627 SetLastError(ERROR_INVALID_PARAMETER
);
628 return(INVALID_HANDLE_VALUE
);
630 if ((GENERIC_READ
|GENERIC_WRITE
) != dwDesiredAccess
)
632 SetLastError(ERROR_INVALID_PARAMETER
);
633 return(INVALID_HANDLE_VALUE
);
635 if (OPEN_EXISTING
!= dwCreationDistribution
)
637 SetLastError(ERROR_INVALID_PARAMETER
);
638 return(INVALID_HANDLE_VALUE
);
640 Status
= CsrClientCallServer(& Request
,
642 sizeof(CSRSS_API_REQUEST
),
643 sizeof(CSRSS_API_REPLY
));
644 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
646 SetLastErrorByStatus(Status
);
647 return INVALID_HANDLE_VALUE
;
657 SetConsoleCommandHistoryMode (DWORD dwMode
)
662 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
671 SetConsoleCursor (DWORD Unknown0
,
677 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
686 SetConsoleDisplayMode (HANDLE hOut
,
690 * FUNCTION: Set the console display mode.
692 * hOut - Standard output handle.
693 * dwNewMode - New mode.
694 * lpdwOldMode - Address of a variable that receives the old mode.
697 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
706 SetConsoleFont (DWORD Unknown0
,
712 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
721 SetConsoleHardwareState (HANDLE hConsole
,
728 CSRSS_API_REQUEST Request
;
729 CSRSS_API_REPLY Reply
;
732 Request
.Type
= CSRSS_SETGET_CONSOLE_HW_STATE
;
733 Request
.Data
.ConsoleHardwareStateRequest
.ConsoleHandle
= hConsole
;
734 Request
.Data
.ConsoleHardwareStateRequest
.SetGet
= CONSOLE_HARDWARE_STATE_SET
;
735 Request
.Data
.ConsoleHardwareStateRequest
.State
= State
;
737 Status
= CsrClientCallServer(& Request
,
739 sizeof(CSRSS_API_REQUEST
),
740 sizeof(CSRSS_API_REPLY
));
741 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
743 SetLastErrorByStatus(Status
);
754 SetConsoleKeyShortcuts (DWORD Unknown0
,
762 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
771 SetConsoleMaximumWindowSize (DWORD Unknown0
,
777 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
786 SetConsoleMenuClose (DWORD Unknown0
)
791 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
800 SetConsoleNumberOfCommandsA (DWORD Unknown0
,
806 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
815 SetConsoleNumberOfCommandsW (DWORD Unknown0
,
821 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
830 SetConsolePalette (DWORD Unknown0
,
837 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
846 SetLastConsoleEventActive (VOID
)
851 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
860 ShowConsoleCursor (DWORD Unknown0
,
866 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
872 * FUNCTION: Checks whether the given handle is a valid console handle.
874 * Handle - Handle to be checked
876 * TRUE: Handle is a valid console handle
877 * FALSE: Handle is not a valid console handle.
878 * STATUS: Officially undocumented
883 VerifyConsoleIoHandle(HANDLE Handle
)
885 CSRSS_API_REQUEST Request
;
886 CSRSS_API_REPLY Reply
;
889 Request
.Type
= CSRSS_VERIFY_HANDLE
;
890 Request
.Data
.VerifyHandleRequest
.Handle
= Handle
;
891 Status
= CsrClientCallServer(&Request
,
893 sizeof(CSRSS_API_REQUEST
),
894 sizeof(CSRSS_API_REPLY
));
895 if (!NT_SUCCESS(Status
))
897 SetLastErrorByStatus(Status
);
901 return (BOOL
)NT_SUCCESS(Reply
.Status
);
909 WriteConsoleInputVDMA (DWORD Unknown0
,
914 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
923 WriteConsoleInputVDMW (DWORD Unknown0
,
928 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
937 CloseConsoleHandle(HANDLE Handle
)
942 CSRSS_API_REQUEST Request
;
943 CSRSS_API_REPLY Reply
;
946 if (IsConsoleHandle (Handle
) == FALSE
)
948 SetLastError (ERROR_INVALID_PARAMETER
);
952 Request
.Type
= CSRSS_CLOSE_HANDLE
;
953 Request
.Data
.CloseHandleRequest
.Handle
= Handle
;
954 Status
= CsrClientCallServer(&Request
,
956 sizeof(CSRSS_API_REQUEST
),
957 sizeof(CSRSS_API_REPLY
));
958 if (!NT_SUCCESS(Status
))
960 SetLastErrorByStatus(Status
);
972 IsConsoleHandle(HANDLE Handle
)
974 if ((((ULONG
)Handle
) & 0x10000003) == 0x3)
986 GetStdHandle(DWORD nStdHandle
)
988 * FUNCTION: Get a handle for the standard input, standard output
989 * and a standard error device.
991 * nStdHandle - Specifies the device for which to return the handle.
992 * RETURNS: If the function succeeds, the return value is the handle
993 * of the specified device. Otherwise the value is INVALID_HANDLE_VALUE.
996 PRTL_USER_PROCESS_PARAMETERS Ppb
;
998 Ppb
= NtCurrentPeb()->ProcessParameters
;
1001 case STD_INPUT_HANDLE
:
1002 return Ppb
->hStdInput
;
1004 case STD_OUTPUT_HANDLE
:
1005 return Ppb
->hStdOutput
;
1007 case STD_ERROR_HANDLE
:
1008 return Ppb
->hStdError
;
1011 SetLastError (ERROR_INVALID_PARAMETER
);
1012 return INVALID_HANDLE_VALUE
;
1020 SetStdHandle(DWORD nStdHandle
,
1023 * FUNCTION: Set the handle for the standard input, standard output or
1024 * the standard error device.
1026 * nStdHandle - Specifies the handle to be set.
1027 * hHandle - The handle to set.
1028 * RETURNS: TRUE if the function succeeds, FALSE otherwise.
1031 PRTL_USER_PROCESS_PARAMETERS Ppb
;
1033 /* no need to check if hHandle == INVALID_HANDLE_VALUE */
1035 Ppb
= NtCurrentPeb()->ProcessParameters
;
1039 case STD_INPUT_HANDLE
:
1040 Ppb
->hStdInput
= hHandle
;
1043 case STD_OUTPUT_HANDLE
:
1044 Ppb
->hStdOutput
= hHandle
;
1047 case STD_ERROR_HANDLE
:
1048 Ppb
->hStdError
= hHandle
;
1052 /* windows for whatever reason sets the last error to ERROR_INVALID_HANDLE here */
1053 SetLastError (ERROR_INVALID_HANDLE
);
1058 /*--------------------------------------------------------------
1064 WriteConsoleA(HANDLE hConsoleOutput
,
1065 CONST VOID
*lpBuffer
,
1066 DWORD nNumberOfCharsToWrite
,
1067 LPDWORD lpNumberOfCharsWritten
,
1070 PCSRSS_API_REQUEST Request
;
1071 CSRSS_API_REPLY Reply
;
1076 Request
= RtlAllocateHeap(GetProcessHeap(),
1078 sizeof(CSRSS_API_REQUEST
) +
1079 CSRSS_MAX_WRITE_CONSOLE_REQUEST
);
1080 if (Request
== NULL
)
1082 SetLastError(ERROR_OUTOFMEMORY
);
1086 Request
->Type
= CSRSS_WRITE_CONSOLE
;
1087 Request
->Data
.WriteConsoleRequest
.ConsoleHandle
= hConsoleOutput
;
1088 if (lpNumberOfCharsWritten
!= NULL
)
1089 *lpNumberOfCharsWritten
= nNumberOfCharsToWrite
;
1090 while (nNumberOfCharsToWrite
)
1092 if (nNumberOfCharsToWrite
> CSRSS_MAX_WRITE_CONSOLE_REQUEST
)
1094 Size
= CSRSS_MAX_WRITE_CONSOLE_REQUEST
;
1098 Size
= nNumberOfCharsToWrite
;
1100 Request
->Data
.WriteConsoleRequest
.NrCharactersToWrite
= Size
;
1102 memcpy(Request
->Data
.WriteConsoleRequest
.Buffer
, lpBuffer
, Size
);
1104 MessageSize
= CSRSS_REQUEST_HEADER_SIZE
+
1105 sizeof(CSRSS_WRITE_CONSOLE_REQUEST
) + Size
;
1106 Status
= CsrClientCallServer(Request
,
1109 sizeof(CSRSS_API_REPLY
));
1111 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
1113 RtlFreeHeap(GetProcessHeap(), 0, Request
);
1114 SetLastErrorByStatus(Status
);
1117 nNumberOfCharsToWrite
-= Size
;
1121 RtlFreeHeap(GetProcessHeap(), 0, Request
);
1127 /*--------------------------------------------------------------
1132 BOOL STDCALL
ReadConsoleA(HANDLE hConsoleInput
,
1134 DWORD nNumberOfCharsToRead
,
1135 LPDWORD lpNumberOfCharsRead
,
1138 CSRSS_API_REQUEST Request
;
1139 PCSRSS_API_REPLY Reply
;
1141 ULONG CharsRead
= 0;
1143 Reply
= RtlAllocateHeap(GetProcessHeap(),
1145 sizeof(CSRSS_API_REPLY
) + nNumberOfCharsToRead
);
1148 SetLastError(ERROR_OUTOFMEMORY
);
1152 Request
.Type
= CSRSS_READ_CONSOLE
;
1153 Request
.Data
.ReadConsoleRequest
.ConsoleHandle
= hConsoleInput
;
1154 Request
.Data
.ReadConsoleRequest
.NrCharactersToRead
= nNumberOfCharsToRead
> CSRSS_MAX_READ_CONSOLE_REQUEST
? CSRSS_MAX_READ_CONSOLE_REQUEST
: nNumberOfCharsToRead
;
1155 Request
.Data
.ReadConsoleRequest
.nCharsCanBeDeleted
= 0;
1156 Status
= CsrClientCallServer(&Request
,
1158 sizeof(CSRSS_API_REQUEST
),
1159 sizeof(CSRSS_API_REPLY
) +
1160 Request
.Data
.ReadConsoleRequest
.NrCharactersToRead
);
1161 if (!NT_SUCCESS(Status
) || !NT_SUCCESS( Status
= Reply
->Status
))
1163 DbgPrint( "CSR returned error in ReadConsole\n" );
1164 SetLastErrorByStatus ( Status
);
1165 RtlFreeHeap( GetProcessHeap(), 0, Reply
);
1168 if( Reply
->Status
== STATUS_NOTIFY_CLEANUP
)
1169 Reply
->Status
= STATUS_PENDING
; // ignore backspace because we have no chars to backspace
1170 /* There may not be any chars or lines to read yet, so wait */
1171 while( Reply
->Status
== STATUS_PENDING
)
1173 /* some chars may have been returned, but not a whole line yet, so recompute buffer and try again */
1174 nNumberOfCharsToRead
-= Reply
->Data
.ReadConsoleReply
.NrCharactersRead
;
1175 /* don't overflow caller's buffer, even if you still don't have a complete line */
1176 if( !nNumberOfCharsToRead
)
1178 Request
.Data
.ReadConsoleRequest
.NrCharactersToRead
= nNumberOfCharsToRead
> CSRSS_MAX_READ_CONSOLE_REQUEST
? CSRSS_MAX_READ_CONSOLE_REQUEST
: nNumberOfCharsToRead
;
1179 /* copy any chars already read to buffer */
1180 memcpy( lpBuffer
+ CharsRead
, Reply
->Data
.ReadConsoleReply
.Buffer
, Reply
->Data
.ReadConsoleReply
.NrCharactersRead
);
1181 CharsRead
+= Reply
->Data
.ReadConsoleReply
.NrCharactersRead
;
1182 /* wait for csrss to signal there is more data to read, but not if we got STATUS_NOTIFY_CLEANUP for backspace */
1183 Status
= NtWaitForSingleObject( Reply
->Data
.ReadConsoleReply
.EventHandle
, FALSE
, 0 );
1184 if( !NT_SUCCESS( Status
) )
1186 DbgPrint( "Wait for console input failed!\n" );
1187 RtlFreeHeap( GetProcessHeap(), 0, Reply
);
1190 Request
.Data
.ReadConsoleRequest
.nCharsCanBeDeleted
= CharsRead
;
1191 Status
= CsrClientCallServer( &Request
, Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) + Request
.Data
.ReadConsoleRequest
.NrCharactersToRead
);
1192 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
->Status
) )
1194 SetLastErrorByStatus ( Status
);
1195 RtlFreeHeap( GetProcessHeap(), 0, Reply
);
1198 if( Reply
->Status
== STATUS_NOTIFY_CLEANUP
)
1204 nNumberOfCharsToRead
++;
1206 Reply
->Status
= STATUS_PENDING
; // retry
1209 /* copy data to buffer, count total returned, and return */
1210 memcpy( lpBuffer
+ CharsRead
, Reply
->Data
.ReadConsoleReply
.Buffer
, Reply
->Data
.ReadConsoleReply
.NrCharactersRead
);
1211 CharsRead
+= Reply
->Data
.ReadConsoleReply
.NrCharactersRead
;
1212 if (lpNumberOfCharsRead
!= NULL
)
1213 *lpNumberOfCharsRead
= CharsRead
;
1214 RtlFreeHeap(GetProcessHeap(),
1222 /*--------------------------------------------------------------
1227 BOOL STDCALL
AllocConsole(VOID
)
1229 CSRSS_API_REQUEST Request
;
1230 CSRSS_API_REPLY Reply
;
1234 if(NtCurrentPeb()->ProcessParameters
->hConsole
)
1236 DPRINT("AllocConsole: Allocate duplicate console to the same Process\n");
1237 SetLastErrorByStatus (STATUS_OBJECT_NAME_EXISTS
);
1241 Request
.Data
.AllocConsoleRequest
.CtrlDispatcher
= (PCONTROLDISPATCHER
) &ConsoleControlDispatcher
;
1243 Request
.Type
= CSRSS_ALLOC_CONSOLE
;
1244 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
1245 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
1247 SetLastErrorByStatus ( Status
);
1250 NtCurrentPeb()->ProcessParameters
->hConsole
= Reply
.Data
.AllocConsoleReply
.Console
;
1251 SetStdHandle( STD_INPUT_HANDLE
, Reply
.Data
.AllocConsoleReply
.InputHandle
);
1252 SetStdHandle( STD_OUTPUT_HANDLE
, Reply
.Data
.AllocConsoleReply
.OutputHandle
);
1253 hStdError
= DuplicateConsoleHandle(Reply
.Data
.AllocConsoleReply
.OutputHandle
,
1256 DUPLICATE_SAME_ACCESS
);
1257 SetStdHandle( STD_ERROR_HANDLE
, hStdError
);
1262 /*--------------------------------------------------------------
1267 BOOL STDCALL
FreeConsole(VOID
)
1269 // AG: I'm not sure if this is correct (what happens to std handles?)
1270 // but I just tried to reverse what AllocConsole() does...
1272 CSRSS_API_REQUEST Request
;
1273 CSRSS_API_REPLY Reply
;
1276 Request
.Type
= CSRSS_FREE_CONSOLE
;
1277 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
1278 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
1280 SetLastErrorByStatus ( Status
);
1288 /*--------------------------------------------------------------
1289 * GetConsoleScreenBufferInfo
1295 GetConsoleScreenBufferInfo(
1296 HANDLE hConsoleOutput
,
1297 PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo
1300 CSRSS_API_REQUEST Request
;
1301 CSRSS_API_REPLY Reply
;
1304 Request
.Type
= CSRSS_SCREEN_BUFFER_INFO
;
1305 Request
.Data
.ScreenBufferInfoRequest
.ConsoleHandle
= hConsoleOutput
;
1306 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
1307 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
1309 SetLastErrorByStatus ( Status
);
1312 *lpConsoleScreenBufferInfo
= Reply
.Data
.ScreenBufferInfoReply
.Info
;
1317 /*--------------------------------------------------------------
1318 * SetConsoleCursorPosition
1324 SetConsoleCursorPosition(
1325 HANDLE hConsoleOutput
,
1326 COORD dwCursorPosition
1329 CSRSS_API_REQUEST Request
;
1330 CSRSS_API_REPLY Reply
;
1333 Request
.Type
= CSRSS_SET_CURSOR
;
1334 Request
.Data
.SetCursorRequest
.ConsoleHandle
= hConsoleOutput
;
1335 Request
.Data
.SetCursorRequest
.Position
= dwCursorPosition
;
1336 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
1337 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
1339 SetLastErrorByStatus ( Status
);
1346 /*--------------------------------------------------------------
1347 * FillConsoleOutputCharacterA
1352 FillConsoleOutputCharacterA(
1353 HANDLE hConsoleOutput
,
1357 LPDWORD lpNumberOfCharsWritten
1360 CSRSS_API_REQUEST Request
;
1361 CSRSS_API_REPLY Reply
;
1364 Request
.Type
= CSRSS_FILL_OUTPUT
;
1365 Request
.Data
.FillOutputRequest
.ConsoleHandle
= hConsoleOutput
;
1366 Request
.Data
.FillOutputRequest
.Char
= cCharacter
;
1367 Request
.Data
.FillOutputRequest
.Position
= dwWriteCoord
;
1368 Request
.Data
.FillOutputRequest
.Length
= nLength
;
1369 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
1370 if ( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
1372 SetLastErrorByStatus(Status
);
1375 if (lpNumberOfCharsWritten
!= NULL
)
1376 *lpNumberOfCharsWritten
= nLength
;
1381 /*--------------------------------------------------------------
1382 * FillConsoleOutputCharacterW
1388 FillConsoleOutputCharacterW(
1389 HANDLE hConsoleOutput
,
1393 LPDWORD lpNumberOfCharsWritten
1401 /*--------------------------------------------------------------
1409 HANDLE hConsoleInput
,
1410 PINPUT_RECORD lpBuffer
,
1412 LPDWORD lpNumberOfEventsRead
1415 PCSRSS_API_REQUEST Request
;
1416 CSRSS_API_REPLY Reply
;
1419 PVOID BufferTargetBase
;
1422 if(lpBuffer
== NULL
)
1424 SetLastError(ERROR_INVALID_PARAMETER
);
1428 Size
= nLength
* sizeof(INPUT_RECORD
);
1430 Status
= CsrCaptureParameterBuffer((PVOID
)lpBuffer
, Size
, &BufferBase
, &BufferTargetBase
);
1431 if(!NT_SUCCESS(Status
))
1433 SetLastErrorByStatus(Status
);
1437 Request
= RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CSRSS_API_REQUEST
));
1440 CsrReleaseParameterBuffer(BufferBase
);
1441 SetLastError(ERROR_OUTOFMEMORY
);
1445 Request
->Type
= CSRSS_PEEK_CONSOLE_INPUT
;
1446 Request
->Data
.PeekConsoleInputRequest
.ConsoleHandle
= hConsoleInput
;
1447 Request
->Data
.PeekConsoleInputRequest
.Length
= nLength
;
1448 Request
->Data
.PeekConsoleInputRequest
.InputRecord
= (INPUT_RECORD
*)BufferTargetBase
;
1450 Status
= CsrClientCallServer(Request
, &Reply
, sizeof(CSRSS_API_REQUEST
), sizeof(CSRSS_API_REPLY
));
1452 if(!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
1454 RtlFreeHeap(GetProcessHeap(), 0, Request
);
1455 CsrReleaseParameterBuffer(BufferBase
);
1459 memcpy(lpBuffer
, BufferBase
, sizeof(INPUT_RECORD
) * Reply
.Data
.PeekConsoleInputReply
.Length
);
1461 if(lpNumberOfEventsRead
!= NULL
)
1462 *lpNumberOfEventsRead
= Reply
.Data
.PeekConsoleInputReply
.Length
;
1464 RtlFreeHeap(GetProcessHeap(), 0, Request
);
1465 CsrReleaseParameterBuffer(BufferBase
);
1471 /*--------------------------------------------------------------
1479 HANDLE hConsoleInput
,
1480 PINPUT_RECORD lpBuffer
,
1482 LPDWORD lpNumberOfEventsRead
1490 /*--------------------------------------------------------------
1496 ReadConsoleInputA(HANDLE hConsoleInput
,
1497 PINPUT_RECORD lpBuffer
,
1499 LPDWORD lpNumberOfEventsRead
)
1501 CSRSS_API_REQUEST Request
;
1502 CSRSS_API_REPLY Reply
;
1503 DWORD NumEventsRead
;
1506 Request
.Type
= CSRSS_READ_INPUT
;
1507 Request
.Data
.ReadInputRequest
.ConsoleHandle
= hConsoleInput
;
1508 Status
= CsrClientCallServer(&Request
, &Reply
, sizeof(CSRSS_API_REQUEST
),
1509 sizeof(CSRSS_API_REPLY
));
1510 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
1512 SetLastErrorByStatus(Status
);
1516 while (Status
== STATUS_PENDING
)
1518 Status
= NtWaitForSingleObject(Reply
.Data
.ReadInputReply
.Event
, FALSE
,
1520 if(!NT_SUCCESS(Status
))
1522 SetLastErrorByStatus(Status
);
1526 Request
.Type
= CSRSS_READ_INPUT
;
1527 Request
.Data
.ReadInputRequest
.ConsoleHandle
= hConsoleInput
;
1528 Status
= CsrClientCallServer(&Request
, &Reply
, sizeof(CSRSS_API_REQUEST
),
1529 sizeof(CSRSS_API_REPLY
));
1530 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
1532 SetLastErrorByStatus(Status
);
1538 *lpBuffer
= Reply
.Data
.ReadInputReply
.Input
;
1542 while ((NumEventsRead
< nLength
) && (Reply
.Data
.ReadInputReply
.MoreEvents
))
1544 Status
= CsrClientCallServer(&Request
, &Reply
, sizeof(CSRSS_API_REQUEST
),
1545 sizeof(CSRSS_API_REPLY
));
1546 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
1548 SetLastErrorByStatus(Status
);
1552 if (Status
== STATUS_PENDING
)
1557 *lpBuffer
= Reply
.Data
.ReadInputReply
.Input
;
1562 *lpNumberOfEventsRead
= NumEventsRead
;
1568 /*--------------------------------------------------------------
1576 HANDLE hConsoleInput
,
1577 PINPUT_RECORD lpBuffer
,
1579 LPDWORD lpNumberOfEventsRead
1587 /*--------------------------------------------------------------
1588 * WriteConsoleInputA
1595 HANDLE hConsoleInput
,
1596 CONST INPUT_RECORD
*lpBuffer
,
1598 LPDWORD lpNumberOfEventsWritten
1601 PCSRSS_API_REQUEST Request
;
1602 CSRSS_API_REPLY Reply
;
1603 PVOID BufferBase
, BufferTargetBase
;
1607 if(lpBuffer
== NULL
)
1609 SetLastError(ERROR_INVALID_PARAMETER
);
1613 Size
= nLength
* sizeof(INPUT_RECORD
);
1615 Status
= CsrCaptureParameterBuffer((PVOID
)lpBuffer
, Size
, &BufferBase
, &BufferTargetBase
);
1616 if(!NT_SUCCESS(Status
))
1618 SetLastErrorByStatus(Status
);
1622 Request
= RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CSRSS_API_REQUEST
));
1625 SetLastError(ERROR_OUTOFMEMORY
);
1626 CsrReleaseParameterBuffer(BufferBase
);
1630 Request
->Type
= CSRSS_WRITE_CONSOLE_INPUT
;
1631 Request
->Data
.WriteConsoleInputRequest
.ConsoleHandle
= hConsoleInput
;
1632 Request
->Data
.WriteConsoleInputRequest
.Length
= nLength
;
1633 Request
->Data
.WriteConsoleInputRequest
.InputRecord
= (PINPUT_RECORD
)BufferTargetBase
;
1635 Status
= CsrClientCallServer(Request
, &Reply
, sizeof(CSRSS_API_REQUEST
), sizeof(CSRSS_API_REPLY
));
1636 if(!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
1638 RtlFreeHeap(GetProcessHeap(), 0, Request
);
1639 CsrReleaseParameterBuffer(BufferBase
);
1643 if(lpNumberOfEventsWritten
!= NULL
)
1644 *lpNumberOfEventsWritten
= Reply
.Data
.WriteConsoleInputReply
.Length
;
1646 RtlFreeHeap(GetProcessHeap(), 0, Request
);
1647 CsrReleaseParameterBuffer(BufferBase
);
1653 /*--------------------------------------------------------------
1654 * WriteConsoleInputW
1661 HANDLE hConsoleInput
,
1662 CONST INPUT_RECORD
*lpBuffer
,
1664 LPDWORD lpNumberOfEventsWritten
1672 /*--------------------------------------------------------------
1673 * ReadConsoleOutputA
1680 HANDLE hConsoleOutput
,
1681 PCHAR_INFO lpBuffer
,
1683 COORD dwBufferCoord
,
1684 PSMALL_RECT lpReadRegion
1687 PCSRSS_API_REQUEST Request
;
1688 CSRSS_API_REPLY Reply
;
1690 PVOID BufferTargetBase
;
1692 DWORD Size
, SizeX
, SizeY
;
1694 if(lpBuffer
== NULL
)
1696 SetLastError(ERROR_INVALID_PARAMETER
);
1700 Size
= dwBufferSize
.X
* dwBufferSize
.Y
* sizeof(CHAR_INFO
);
1702 Status
= CsrCaptureParameterBuffer((PVOID
)lpBuffer
, Size
, &BufferBase
, &BufferTargetBase
);
1703 if(!NT_SUCCESS(Status
))
1705 SetLastErrorByStatus(Status
);
1709 Request
= RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CSRSS_API_REQUEST
));
1712 SetLastError(ERROR_OUTOFMEMORY
);
1713 CsrReleaseParameterBuffer(BufferBase
);
1717 Request
->Type
= CSRSS_READ_CONSOLE_OUTPUT
;
1718 Request
->Data
.ReadConsoleOutputRequest
.ConsoleHandle
= hConsoleOutput
;
1719 Request
->Data
.ReadConsoleOutputRequest
.BufferSize
= dwBufferSize
;
1720 Request
->Data
.ReadConsoleOutputRequest
.BufferCoord
= dwBufferCoord
;
1721 Request
->Data
.ReadConsoleOutputRequest
.ReadRegion
= *lpReadRegion
;
1722 Request
->Data
.ReadConsoleOutputRequest
.CharInfo
= (PCHAR_INFO
)BufferTargetBase
;
1724 Status
= CsrClientCallServer(Request
, &Reply
, sizeof(CSRSS_API_REQUEST
), sizeof(CSRSS_API_REPLY
));
1725 if(!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
1727 SetLastErrorByStatus(Status
);
1728 RtlFreeHeap(GetProcessHeap(), 0, Request
);
1729 CsrReleaseParameterBuffer(BufferBase
);
1733 SizeX
= Reply
.Data
.ReadConsoleOutputReply
.ReadRegion
.Right
- Reply
.Data
.ReadConsoleOutputReply
.ReadRegion
.Left
+ 1;
1734 SizeY
= Reply
.Data
.ReadConsoleOutputReply
.ReadRegion
.Bottom
- Reply
.Data
.ReadConsoleOutputReply
.ReadRegion
.Top
+ 1;
1736 memcpy(lpBuffer
, BufferBase
, sizeof(CHAR_INFO
) * SizeX
* SizeY
);
1737 *lpReadRegion
= Reply
.Data
.ReadConsoleOutputReply
.ReadRegion
;
1739 RtlFreeHeap(GetProcessHeap(), 0, Request
);
1740 CsrReleaseParameterBuffer(BufferBase
);
1746 /*--------------------------------------------------------------
1747 * ReadConsoleOutputW
1754 HANDLE hConsoleOutput
,
1755 PCHAR_INFO lpBuffer
,
1757 COORD dwBufferCoord
,
1758 PSMALL_RECT lpReadRegion
1765 /*--------------------------------------------------------------
1766 * WriteConsoleOutputA
1771 WriteConsoleOutputA(HANDLE hConsoleOutput
,
1772 CONST CHAR_INFO
*lpBuffer
,
1774 COORD dwBufferCoord
,
1775 PSMALL_RECT lpWriteRegion
)
1777 PCSRSS_API_REQUEST Request
;
1778 CSRSS_API_REPLY Reply
;
1782 PVOID BufferTargetBase
;
1784 Size
= dwBufferSize
.Y
* dwBufferSize
.X
* sizeof(CHAR_INFO
);
1786 Status
= CsrCaptureParameterBuffer((PVOID
)lpBuffer
,
1790 if (!NT_SUCCESS(Status
))
1792 SetLastErrorByStatus(Status
);
1796 Request
= RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY
,
1797 sizeof(CSRSS_API_REQUEST
));
1798 if (Request
== NULL
)
1800 CsrReleaseParameterBuffer(BufferBase
);
1801 SetLastError(ERROR_OUTOFMEMORY
);
1804 Request
->Type
= CSRSS_WRITE_CONSOLE_OUTPUT
;
1805 Request
->Data
.WriteConsoleOutputRequest
.ConsoleHandle
= hConsoleOutput
;
1806 Request
->Data
.WriteConsoleOutputRequest
.BufferSize
= dwBufferSize
;
1807 Request
->Data
.WriteConsoleOutputRequest
.BufferCoord
= dwBufferCoord
;
1808 Request
->Data
.WriteConsoleOutputRequest
.WriteRegion
= *lpWriteRegion
;
1809 Request
->Data
.WriteConsoleOutputRequest
.CharInfo
=
1810 (CHAR_INFO
*)BufferTargetBase
;
1812 Status
= CsrClientCallServer(Request
, &Reply
,
1813 sizeof(CSRSS_API_REQUEST
),
1814 sizeof(CSRSS_API_REPLY
));
1815 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
1817 CsrReleaseParameterBuffer(BufferBase
);
1818 RtlFreeHeap(GetProcessHeap(), 0, Request
);
1819 SetLastErrorByStatus(Status
);
1823 *lpWriteRegion
= Reply
.Data
.WriteConsoleOutputReply
.WriteRegion
;
1824 RtlFreeHeap(GetProcessHeap(), 0, Request
);
1825 CsrReleaseParameterBuffer(BufferBase
);
1830 /*--------------------------------------------------------------
1831 * WriteConsoleOutputW
1837 WriteConsoleOutputW(
1838 HANDLE hConsoleOutput
,
1839 CONST CHAR_INFO
*lpBuffer
,
1841 COORD dwBufferCoord
,
1842 PSMALL_RECT lpWriteRegion
1850 /*--------------------------------------------------------------
1851 * ReadConsoleOutputCharacterA
1857 ReadConsoleOutputCharacterA(
1858 HANDLE hConsoleOutput
,
1862 LPDWORD lpNumberOfCharsRead
1865 CSRSS_API_REQUEST Request
;
1866 PCSRSS_API_REPLY Reply
;
1870 Reply
= RtlAllocateHeap(GetProcessHeap(),
1872 sizeof(CSRSS_API_REPLY
) + CSRSS_MAX_READ_CONSOLE_OUTPUT_CHAR
);
1875 SetLastError(ERROR_OUTOFMEMORY
);
1879 if (lpNumberOfCharsRead
!= NULL
)
1880 *lpNumberOfCharsRead
= nLength
;
1882 Request
.Type
= CSRSS_READ_CONSOLE_OUTPUT_CHAR
;
1883 Request
.Data
.ReadConsoleOutputCharRequest
.ConsoleHandle
= hConsoleOutput
;
1884 Request
.Data
.ReadConsoleOutputCharRequest
.ReadCoord
= dwReadCoord
;
1886 while (nLength
!= 0)
1888 if (nLength
> CSRSS_MAX_READ_CONSOLE_OUTPUT_CHAR
)
1889 Size
= CSRSS_MAX_READ_CONSOLE_OUTPUT_CHAR
;
1893 Request
.Data
.ReadConsoleOutputCharRequest
.NumCharsToRead
= Size
;
1895 Status
= CsrClientCallServer(&Request
,
1897 sizeof(CSRSS_API_REQUEST
),
1898 sizeof(CSRSS_API_REPLY
) + Size
);
1899 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Reply
->Status
))
1901 RtlFreeHeap(GetProcessHeap(), 0, Reply
);
1902 SetLastErrorByStatus(Status
);
1906 memcpy(lpCharacter
, &Reply
->Data
.ReadConsoleOutputCharReply
.String
[0], Size
);
1907 lpCharacter
+= Size
;
1909 Request
.Data
.ReadConsoleOutputCharRequest
.ReadCoord
= Reply
->Data
.ReadConsoleOutputCharReply
.EndCoord
;
1912 RtlFreeHeap(GetProcessHeap(), 0, Reply
);
1918 /*--------------------------------------------------------------
1919 * ReadConsoleOutputCharacterW
1925 ReadConsoleOutputCharacterW(
1926 HANDLE hConsoleOutput
,
1930 LPDWORD lpNumberOfCharsRead
1938 /*--------------------------------------------------------------
1939 * ReadConsoleOutputAttribute
1945 ReadConsoleOutputAttribute(
1946 HANDLE hConsoleOutput
,
1950 LPDWORD lpNumberOfAttrsRead
1953 CSRSS_API_REQUEST Request
;
1954 PCSRSS_API_REPLY Reply
;
1958 Reply
= RtlAllocateHeap(GetProcessHeap(),
1960 sizeof(CSRSS_API_REPLY
) + CSRSS_MAX_READ_CONSOLE_OUTPUT_ATTRIB
);
1963 SetLastError(ERROR_OUTOFMEMORY
);
1967 if (lpNumberOfAttrsRead
!= NULL
)
1968 *lpNumberOfAttrsRead
= nLength
;
1970 Request
.Type
= CSRSS_READ_CONSOLE_OUTPUT_ATTRIB
;
1971 Request
.Data
.ReadConsoleOutputAttribRequest
.ConsoleHandle
= hConsoleOutput
;
1972 Request
.Data
.ReadConsoleOutputAttribRequest
.ReadCoord
= dwReadCoord
;
1974 while (nLength
!= 0)
1976 if (nLength
> CSRSS_MAX_READ_CONSOLE_OUTPUT_ATTRIB
)
1977 Size
= CSRSS_MAX_READ_CONSOLE_OUTPUT_ATTRIB
;
1981 Request
.Data
.ReadConsoleOutputAttribRequest
.NumAttrsToRead
= Size
;
1983 Status
= CsrClientCallServer(&Request
,
1985 sizeof(CSRSS_API_REQUEST
),
1986 sizeof(CSRSS_API_REPLY
) + Size
);
1987 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Reply
->Status
))
1989 RtlFreeHeap(GetProcessHeap(), 0, Reply
);
1990 SetLastErrorByStatus(Status
);
1994 // Convert CHARs to WORDs
1995 for(i
= 0; i
< Size
; ++i
)
1996 *lpAttribute
++ = Reply
->Data
.ReadConsoleOutputAttribReply
.String
[i
];
1999 Request
.Data
.ReadConsoleOutputAttribRequest
.ReadCoord
= Reply
->Data
.ReadConsoleOutputAttribReply
.EndCoord
;
2002 RtlFreeHeap(GetProcessHeap(), 0, Reply
);
2008 /*--------------------------------------------------------------
2009 * WriteConsoleOutputCharacterA
2014 WriteConsoleOutputCharacterA(HANDLE hConsoleOutput
,
2018 LPDWORD lpNumberOfCharsWritten
)
2020 PCSRSS_API_REQUEST Request
;
2021 CSRSS_API_REPLY Reply
;
2025 Request
= RtlAllocateHeap(GetProcessHeap(),
2027 sizeof(CSRSS_API_REQUEST
) + CSRSS_MAX_WRITE_CONSOLE_OUTPUT_CHAR
);
2030 SetLastError( ERROR_OUTOFMEMORY
);
2033 Request
->Type
= CSRSS_WRITE_CONSOLE_OUTPUT_CHAR
;
2034 Request
->Data
.WriteConsoleOutputCharRequest
.ConsoleHandle
= hConsoleOutput
;
2035 Request
->Data
.WriteConsoleOutputCharRequest
.Coord
= dwWriteCoord
;
2036 if( lpNumberOfCharsWritten
)
2037 *lpNumberOfCharsWritten
= nLength
;
2040 Size
= nLength
> CSRSS_MAX_WRITE_CONSOLE_OUTPUT_CHAR
? CSRSS_MAX_WRITE_CONSOLE_OUTPUT_CHAR
: nLength
;
2041 Request
->Data
.WriteConsoleOutputCharRequest
.Length
= Size
;
2042 memcpy( &Request
->Data
.WriteConsoleOutputCharRequest
.String
[0],
2045 Status
= CsrClientCallServer( Request
, &Reply
, sizeof( CSRSS_API_REQUEST
) + Size
, sizeof( CSRSS_API_REPLY
) );
2046 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
2048 RtlFreeHeap( GetProcessHeap(), 0, Request
);
2049 SetLastErrorByStatus ( Status
);
2053 lpCharacter
+= Size
;
2054 Request
->Data
.WriteConsoleOutputCharRequest
.Coord
= Reply
.Data
.WriteConsoleOutputCharReply
.EndCoord
;
2057 RtlFreeHeap( GetProcessHeap(), 0, Request
);
2062 /*--------------------------------------------------------------
2063 * WriteConsoleOutputCharacterW
2068 WriteConsoleOutputCharacterW(HANDLE hConsoleOutput
,
2069 LPCWSTR lpCharacter
,
2072 LPDWORD lpNumberOfCharsWritten
)
2074 PCSRSS_API_REQUEST Request
;
2075 CSRSS_API_REPLY Reply
;
2079 Request
= RtlAllocateHeap(GetProcessHeap(),
2081 sizeof(CSRSS_API_REQUEST
) + CSRSS_MAX_WRITE_CONSOLE_OUTPUT_CHAR
);
2084 SetLastError( ERROR_OUTOFMEMORY
);
2087 Request
->Type
= CSRSS_WRITE_CONSOLE_OUTPUT_CHAR
;
2088 Request
->Data
.WriteConsoleOutputCharRequest
.ConsoleHandle
= hConsoleOutput
;
2089 Request
->Data
.WriteConsoleOutputCharRequest
.Coord
= dwWriteCoord
;
2090 if( lpNumberOfCharsWritten
)
2091 *lpNumberOfCharsWritten
= nLength
;
2094 Size
= nLength
> CSRSS_MAX_WRITE_CONSOLE_OUTPUT_CHAR
? CSRSS_MAX_WRITE_CONSOLE_OUTPUT_CHAR
: nLength
;
2095 Request
->Data
.WriteConsoleOutputCharRequest
.Length
= Size
;
2096 Status
= RtlUnicodeToOemN (&Request
->Data
.WriteConsoleOutputCharRequest
.String
[0],
2099 (PWCHAR
)lpCharacter
,
2100 Size
* sizeof(WCHAR
));
2101 if (!NT_SUCCESS(Status
))
2103 RtlFreeHeap (GetProcessHeap(), 0, Request
);
2104 SetLastErrorByStatus (Status
);
2108 Status
= CsrClientCallServer( Request
, &Reply
, sizeof( CSRSS_API_REQUEST
) + Size
, sizeof( CSRSS_API_REPLY
) );
2109 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
2111 RtlFreeHeap( GetProcessHeap(), 0, Request
);
2112 SetLastErrorByStatus ( Status
);
2116 lpCharacter
+= Size
;
2117 Request
->Data
.WriteConsoleOutputCharRequest
.Coord
= Reply
.Data
.WriteConsoleOutputCharReply
.EndCoord
;
2120 RtlFreeHeap( GetProcessHeap(), 0, Request
);
2125 /*--------------------------------------------------------------
2126 * WriteConsoleOutputAttribute
2132 WriteConsoleOutputAttribute(
2133 HANDLE hConsoleOutput
,
2134 CONST WORD
*lpAttribute
,
2137 LPDWORD lpNumberOfAttrsWritten
2140 PCSRSS_API_REQUEST Request
;
2141 CSRSS_API_REPLY Reply
;
2146 Request
= RtlAllocateHeap(GetProcessHeap(),
2148 sizeof(CSRSS_API_REQUEST
) + CSRSS_MAX_WRITE_CONSOLE_OUTPUT_ATTRIB
);
2151 SetLastError( ERROR_OUTOFMEMORY
);
2154 Request
->Type
= CSRSS_WRITE_CONSOLE_OUTPUT_ATTRIB
;
2155 Request
->Data
.WriteConsoleOutputAttribRequest
.ConsoleHandle
= hConsoleOutput
;
2156 Request
->Data
.WriteConsoleOutputAttribRequest
.Coord
= dwWriteCoord
;
2157 if( lpNumberOfAttrsWritten
)
2158 *lpNumberOfAttrsWritten
= nLength
;
2161 Size
= nLength
> CSRSS_MAX_WRITE_CONSOLE_OUTPUT_ATTRIB
? CSRSS_MAX_WRITE_CONSOLE_OUTPUT_ATTRIB
: nLength
;
2162 Request
->Data
.WriteConsoleOutputAttribRequest
.Length
= Size
;
2163 for( c
= 0; c
< ( Size
* 2 ); c
++ )
2164 Request
->Data
.WriteConsoleOutputAttribRequest
.String
[c
] = (char)lpAttribute
[c
];
2165 Status
= CsrClientCallServer( Request
, &Reply
, sizeof( CSRSS_API_REQUEST
) + (Size
* 2), sizeof( CSRSS_API_REPLY
) );
2166 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
2168 RtlFreeHeap( GetProcessHeap(), 0, Request
);
2169 SetLastErrorByStatus ( Status
);
2173 lpAttribute
+= Size
;
2174 Request
->Data
.WriteConsoleOutputAttribRequest
.Coord
= Reply
.Data
.WriteConsoleOutputAttribReply
.EndCoord
;
2177 RtlFreeHeap( GetProcessHeap(), 0, Request
);
2182 /*--------------------------------------------------------------
2183 * FillConsoleOutputAttribute
2189 FillConsoleOutputAttribute(
2190 HANDLE hConsoleOutput
,
2194 LPDWORD lpNumberOfAttrsWritten
2197 CSRSS_API_REQUEST Request
;
2198 CSRSS_API_REPLY Reply
;
2201 Request
.Type
= CSRSS_FILL_OUTPUT_ATTRIB
;
2202 Request
.Data
.FillOutputAttribRequest
.ConsoleHandle
= hConsoleOutput
;
2203 Request
.Data
.FillOutputAttribRequest
.Attribute
= wAttribute
;
2204 Request
.Data
.FillOutputAttribRequest
.Coord
= dwWriteCoord
;
2205 Request
.Data
.FillOutputAttribRequest
.Length
= nLength
;
2206 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
2207 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
2209 SetLastErrorByStatus ( Status
);
2212 if( lpNumberOfAttrsWritten
)
2213 *lpNumberOfAttrsWritten
= nLength
;
2218 /*--------------------------------------------------------------
2226 HANDLE hConsoleHandle
,
2230 CSRSS_API_REQUEST Request
;
2231 CSRSS_API_REPLY Reply
;
2234 Request
.Type
= CSRSS_GET_CONSOLE_MODE
;
2235 Request
.Data
.GetConsoleModeRequest
.ConsoleHandle
= hConsoleHandle
;
2236 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
2237 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
2239 SetLastErrorByStatus ( Status
);
2242 *lpMode
= Reply
.Data
.GetConsoleModeReply
.ConsoleMode
;
2247 /*--------------------------------------------------------------
2248 * GetNumberOfConsoleInputEvents
2254 GetNumberOfConsoleInputEvents(
2255 HANDLE hConsoleInput
,
2256 LPDWORD lpNumberOfEvents
2259 CSRSS_API_REQUEST Request
;
2260 CSRSS_API_REPLY Reply
;
2263 if(lpNumberOfEvents
== NULL
)
2265 SetLastError(ERROR_INVALID_PARAMETER
);
2269 Request
.Type
= CSRSS_GET_NUM_INPUT_EVENTS
;
2270 Request
.Data
.GetNumInputEventsRequest
.ConsoleHandle
= hConsoleInput
;
2271 Status
= CsrClientCallServer(&Request
, &Reply
, sizeof(CSRSS_API_REQUEST
), sizeof(CSRSS_API_REPLY
));
2272 if(!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
2274 SetLastErrorByStatus(Status
);
2278 *lpNumberOfEvents
= Reply
.Data
.GetNumInputEventsReply
.NumInputEvents
;
2284 /*--------------------------------------------------------------
2285 * GetLargestConsoleWindowSize
2291 GetLargestConsoleWindowSize(
2292 HANDLE hConsoleOutput
2296 COORD Coord
= {80,25};
2304 /*--------------------------------------------------------------
2305 * GetConsoleCursorInfo
2311 GetConsoleCursorInfo(
2312 HANDLE hConsoleOutput
,
2313 PCONSOLE_CURSOR_INFO lpConsoleCursorInfo
2316 CSRSS_API_REQUEST Request
;
2317 CSRSS_API_REPLY Reply
;
2320 Request
.Type
= CSRSS_GET_CURSOR_INFO
;
2321 Request
.Data
.GetCursorInfoRequest
.ConsoleHandle
= hConsoleOutput
;
2322 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
2324 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
2326 SetLastErrorByStatus ( Status
);
2329 *lpConsoleCursorInfo
= Reply
.Data
.GetCursorInfoReply
.Info
;
2334 /*--------------------------------------------------------------
2335 * GetNumberOfConsoleMouseButtons
2341 GetNumberOfConsoleMouseButtons(
2342 LPDWORD lpNumberOfMouseButtons
2350 /*--------------------------------------------------------------
2358 HANDLE hConsoleHandle
,
2362 CSRSS_API_REQUEST Request
;
2363 CSRSS_API_REPLY Reply
;
2366 Request
.Type
= CSRSS_SET_CONSOLE_MODE
;
2367 Request
.Data
.SetConsoleModeRequest
.ConsoleHandle
= hConsoleHandle
;
2368 Request
.Data
.SetConsoleModeRequest
.Mode
= dwMode
;
2369 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
2370 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
2372 SetLastErrorByStatus ( Status
);
2379 /*--------------------------------------------------------------
2380 * SetConsoleActiveScreenBuffer
2386 SetConsoleActiveScreenBuffer(
2387 HANDLE hConsoleOutput
2390 CSRSS_API_REQUEST Request
;
2391 CSRSS_API_REPLY Reply
;
2394 Request
.Type
= CSRSS_SET_SCREEN_BUFFER
;
2395 Request
.Data
.SetScreenBufferRequest
.OutputHandle
= hConsoleOutput
;
2396 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
2397 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
2399 SetLastErrorByStatus ( Status
);
2406 /*--------------------------------------------------------------
2407 * FlushConsoleInputBuffer
2413 FlushConsoleInputBuffer(
2414 HANDLE hConsoleInput
2417 CSRSS_API_REQUEST Request
;
2418 CSRSS_API_REPLY Reply
;
2421 Request
.Type
= CSRSS_FLUSH_INPUT_BUFFER
;
2422 Request
.Data
.FlushInputBufferRequest
.ConsoleInput
= hConsoleInput
;
2423 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
2424 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
2426 SetLastErrorByStatus ( Status
);
2433 /*--------------------------------------------------------------
2434 * SetConsoleScreenBufferSize
2440 SetConsoleScreenBufferSize(
2441 HANDLE hConsoleOutput
,
2449 /*--------------------------------------------------------------
2450 * SetConsoleCursorInfo
2456 SetConsoleCursorInfo(
2457 HANDLE hConsoleOutput
,
2458 CONST CONSOLE_CURSOR_INFO
*lpConsoleCursorInfo
2461 CSRSS_API_REQUEST Request
;
2462 CSRSS_API_REPLY Reply
;
2465 Request
.Type
= CSRSS_SET_CURSOR_INFO
;
2466 Request
.Data
.SetCursorInfoRequest
.ConsoleHandle
= hConsoleOutput
;
2467 Request
.Data
.SetCursorInfoRequest
.Info
= *lpConsoleCursorInfo
;
2468 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
2470 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
2472 SetLastErrorByStatus ( Status
);
2479 /*--------------------------------------------------------------
2480 * ScrollConsoleScreenBufferA
2486 ScrollConsoleScreenBufferA(
2487 HANDLE hConsoleOutput
,
2488 CONST SMALL_RECT
*lpScrollRectangle
,
2489 CONST SMALL_RECT
*lpClipRectangle
,
2490 COORD dwDestinationOrigin
,
2491 CONST CHAR_INFO
*lpFill
2494 CSRSS_API_REQUEST Request
;
2495 CSRSS_API_REPLY Reply
;
2498 Request
.Type
= CSRSS_SCROLL_CONSOLE_SCREEN_BUFFER
;
2499 Request
.Data
.ScrollConsoleScreenBufferRequest
.ConsoleHandle
= hConsoleOutput
;
2500 Request
.Data
.ScrollConsoleScreenBufferRequest
.ScrollRectangle
= *lpScrollRectangle
;
2502 if (lpClipRectangle
!= NULL
)
2504 Request
.Data
.ScrollConsoleScreenBufferRequest
.UseClipRectangle
= TRUE
;
2505 Request
.Data
.ScrollConsoleScreenBufferRequest
.ClipRectangle
= *lpClipRectangle
;
2509 Request
.Data
.ScrollConsoleScreenBufferRequest
.UseClipRectangle
= FALSE
;
2512 Request
.Data
.ScrollConsoleScreenBufferRequest
.DestinationOrigin
= dwDestinationOrigin
;
2513 Request
.Data
.ScrollConsoleScreenBufferRequest
.Fill
= *lpFill
;
2514 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
2516 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
2518 SetLastErrorByStatus ( Status
);
2525 /*--------------------------------------------------------------
2526 * ScrollConsoleScreenBufferW
2532 ScrollConsoleScreenBufferW(
2533 HANDLE hConsoleOutput
,
2534 CONST SMALL_RECT
*lpScrollRectangle
,
2535 CONST SMALL_RECT
*lpClipRectangle
,
2536 COORD dwDestinationOrigin
,
2537 CONST CHAR_INFO
*lpFill
2545 /*--------------------------------------------------------------
2546 * SetConsoleWindowInfo
2552 SetConsoleWindowInfo(
2553 HANDLE hConsoleOutput
,
2555 CONST SMALL_RECT
*lpConsoleWindow
2563 /*--------------------------------------------------------------
2564 * SetConsoleTextAttribute
2570 SetConsoleTextAttribute(
2571 HANDLE hConsoleOutput
,
2575 CSRSS_API_REQUEST Request
;
2576 CSRSS_API_REPLY Reply
;
2579 Request
.Type
= CSRSS_SET_ATTRIB
;
2580 Request
.Data
.SetAttribRequest
.ConsoleHandle
= hConsoleOutput
;
2581 Request
.Data
.SetAttribRequest
.Attrib
= wAttributes
;
2582 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
2583 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
2585 SetLastErrorByStatus ( Status
);
2593 AddConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine
)
2595 if (HandlerRoutine
== NULL
)
2597 IgnoreCtrlEvents
= TRUE
;
2604 RtlReAllocateHeap(RtlGetProcessHeap(),
2606 (PVOID
)CtrlHandlers
,
2607 NrCtrlHandlers
* sizeof(PHANDLER_ROUTINE
));
2608 if (CtrlHandlers
== NULL
)
2611 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2614 CtrlHandlers
[NrCtrlHandlers
- 1] = HandlerRoutine
;
2621 RemoveConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine
)
2625 if (HandlerRoutine
== NULL
)
2627 IgnoreCtrlEvents
= FALSE
;
2632 for (i
= 0; i
< NrCtrlHandlers
; i
++)
2634 if ( ((void*)(CtrlHandlers
[i
])) == (void*)HandlerRoutine
)
2637 memmove(CtrlHandlers
+ i
, CtrlHandlers
+ i
+ 1,
2638 (NrCtrlHandlers
- i
) * sizeof(PHANDLER_ROUTINE
));
2640 RtlReAllocateHeap(RtlGetProcessHeap(),
2642 (PVOID
)CtrlHandlers
,
2643 NrCtrlHandlers
* sizeof(PHANDLER_ROUTINE
));
2656 SetConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine
,
2661 RtlEnterCriticalSection(&DllLock
);
2664 Ret
= AddConsoleCtrlHandler(HandlerRoutine
);
2668 Ret
= RemoveConsoleCtrlHandler(HandlerRoutine
);
2670 RtlLeaveCriticalSection(&DllLock
);
2675 /*--------------------------------------------------------------
2676 * GenerateConsoleCtrlEvent
2681 GenerateConsoleCtrlEvent(
2683 DWORD dwProcessGroupId
2691 /*--------------------------------------------------------------
2699 LPWSTR lpConsoleTitle
,
2703 CSRSS_API_REQUEST Request
;
2704 PCSRSS_API_REPLY Reply
;
2708 hConsole
= CreateFileW(L
"CONIN$", GENERIC_READ
, 0, NULL
, OPEN_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
2709 if (hConsole
== INVALID_HANDLE_VALUE
)
2714 Reply
= RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CSRSS_API_REPLY
) + CSRSS_MAX_TITLE_LENGTH
* sizeof(WCHAR
));
2717 CloseHandle(hConsole
);
2718 SetLastError(ERROR_OUTOFMEMORY
);
2722 Request
.Type
= CSRSS_GET_TITLE
;
2723 Request
.Data
.GetTitleRequest
.ConsoleHandle
= hConsole
;
2725 Status
= CsrClientCallServer(&Request
, Reply
, sizeof(CSRSS_API_REQUEST
), sizeof(CSRSS_API_REPLY
) + CSRSS_MAX_TITLE_LENGTH
* sizeof(WCHAR
));
2726 CloseHandle(hConsole
);
2727 if(!NT_SUCCESS(Status
) || !(NT_SUCCESS(Status
= Reply
->Status
)))
2729 SetLastErrorByStatus(Status
);
2730 RtlFreeHeap(GetProcessHeap(), 0, Reply
);
2734 if(nSize
* sizeof(WCHAR
) < Reply
->Data
.GetTitleReply
.Length
)
2736 wcsncpy(lpConsoleTitle
, Reply
->Data
.GetTitleReply
.Title
, nSize
- 1);
2737 lpConsoleTitle
[nSize
--] = L
'\0';
2741 nSize
= Reply
->Data
.GetTitleReply
.Length
/ sizeof (WCHAR
);
2742 wcscpy(lpConsoleTitle
, Reply
->Data
.GetTitleReply
.Title
);
2743 lpConsoleTitle
[nSize
] = L
'\0';
2746 RtlFreeHeap(GetProcessHeap(), 0, Reply
);
2751 /*--------------------------------------------------------------
2761 LPSTR lpConsoleTitle
,
2765 wchar_t WideTitle
[CSRSS_MAX_TITLE_LENGTH
];
2766 DWORD nWideTitle
= sizeof WideTitle
;
2769 if (!lpConsoleTitle
|| !nSize
) return 0;
2770 nWideTitle
= GetConsoleTitleW( (LPWSTR
) WideTitle
, nWideTitle
);
2771 if (!nWideTitle
) return 0;
2773 if ( (nWritten
= WideCharToMultiByte(
2774 CP_ACP
, // ANSI code page
2775 0, // performance and mapping flags
2776 (LPWSTR
) WideTitle
, // address of wide-character string
2777 nWideTitle
, // number of characters in string
2778 lpConsoleTitle
, // address of buffer for new string
2779 nSize
, // size of buffer
2784 lpConsoleTitle
[nWritten
] = '\0';
2792 /*--------------------------------------------------------------
2800 LPCWSTR lpConsoleTitle
2803 PCSRSS_API_REQUEST Request
;
2804 CSRSS_API_REPLY Reply
;
2809 hConsole
= CreateFileW(L
"CONIN$", GENERIC_WRITE
, 0, NULL
, OPEN_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
2810 if (hConsole
== INVALID_HANDLE_VALUE
)
2815 Request
= RtlAllocateHeap(GetProcessHeap(),
2817 sizeof(CSRSS_API_REQUEST
) + CSRSS_MAX_SET_TITLE_REQUEST
);
2818 if (Request
== NULL
)
2820 CloseHandle(hConsole
);
2821 SetLastError(ERROR_OUTOFMEMORY
);
2825 Request
->Type
= CSRSS_SET_TITLE
;
2826 Request
->Data
.SetTitleRequest
.Console
= hConsole
;
2828 for( c
= 0; lpConsoleTitle
[c
] && c
< CSRSS_MAX_TITLE_LENGTH
; c
++ )
2829 Request
->Data
.SetTitleRequest
.Title
[c
] = lpConsoleTitle
[c
];
2831 Request
->Data
.SetTitleRequest
.Title
[c
] = 0;
2832 Request
->Data
.SetTitleRequest
.Length
= c
;
2833 Status
= CsrClientCallServer(Request
,
2835 sizeof(CSRSS_API_REQUEST
) +
2837 sizeof(CSRSS_API_REPLY
));
2838 CloseHandle(hConsole
);
2839 if (!NT_SUCCESS(Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
2841 RtlFreeHeap( GetProcessHeap(), 0, Request
);
2842 SetLastErrorByStatus (Status
);
2845 RtlFreeHeap( GetProcessHeap(), 0, Request
);
2850 /*--------------------------------------------------------------
2860 LPCSTR lpConsoleTitle
2863 PCSRSS_API_REQUEST Request
;
2864 CSRSS_API_REPLY Reply
;
2869 hConsole
= CreateFileW(L
"CONIN$", GENERIC_WRITE
, 0, NULL
, OPEN_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
2870 if (hConsole
== INVALID_HANDLE_VALUE
)
2875 Request
= RtlAllocateHeap(GetProcessHeap(),
2877 sizeof(CSRSS_API_REQUEST
) + CSRSS_MAX_SET_TITLE_REQUEST
);
2878 if (Request
== NULL
)
2880 CloseHandle(hConsole
);
2881 SetLastError(ERROR_OUTOFMEMORY
);
2885 Request
->Type
= CSRSS_SET_TITLE
;
2886 Request
->Data
.SetTitleRequest
.Console
= hConsole
;
2888 for( c
= 0; lpConsoleTitle
[c
] && c
< CSRSS_MAX_TITLE_LENGTH
; c
++ )
2889 Request
->Data
.SetTitleRequest
.Title
[c
] = lpConsoleTitle
[c
];
2891 Request
->Data
.SetTitleRequest
.Title
[c
] = 0;
2892 Request
->Data
.SetTitleRequest
.Length
= c
;
2893 Status
= CsrClientCallServer(Request
,
2895 sizeof(CSRSS_API_REQUEST
) +
2897 sizeof(CSRSS_API_REPLY
));
2898 CloseHandle(hConsole
);
2899 if (!NT_SUCCESS(Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
2901 RtlFreeHeap( GetProcessHeap(), 0, Request
);
2902 SetLastErrorByStatus (Status
);
2905 RtlFreeHeap( GetProcessHeap(), 0, Request
);
2910 /*--------------------------------------------------------------
2918 HANDLE hConsoleInput
,
2920 DWORD nNumberOfCharsToRead
,
2921 LPDWORD lpNumberOfCharsRead
,
2930 /*--------------------------------------------------------------
2938 HANDLE hConsoleOutput
,
2939 CONST VOID
*lpBuffer
,
2940 DWORD nNumberOfCharsToWrite
,
2941 LPDWORD lpNumberOfCharsWritten
,
2946 PCSRSS_API_REQUEST Request
;
2947 CSRSS_API_REPLY Reply
;
2950 Request
= RtlAllocateHeap(GetProcessHeap(),
2952 sizeof(CSRSS_API_REQUEST
) + nNumberOfCharsToWrite
* sizeof(WCHAR
));
2953 if (Request
== NULL
)
2955 SetLastError(ERROR_OUTOFMEMORY
);
2959 Request
->Type
= CSRSS_WRITE_CONSOLE
;
2960 Request
->Data
.WriteConsoleRequest
.ConsoleHandle
= hConsoleOutput
;
2961 Request
->Data
.WriteConsoleRequest
.NrCharactersToWrite
=
2962 nNumberOfCharsToWrite
;
2963 // DbgPrint("nNumberOfCharsToWrite %d\n", nNumberOfCharsToWrite);
2964 // DbgPrint("Buffer %s\n", Request->Data.WriteConsoleRequest.Buffer);
2965 memcpy(Request
->Data
.WriteConsoleRequest
.Buffer
,
2967 nNumberOfCharsToWrite
* sizeof(WCHAR
));
2969 Status
= CsrClientCallServer(Request
,
2971 sizeof(CSRSS_API_REQUEST
) + nNumberOfCharsToWrite
,
2972 sizeof(CSRSS_API_REPLY
));
2974 RtlFreeHeap(GetProcessHeap(),
2978 if (!NT_SUCCESS(Status
))
2983 if (lpNumberOfCharsWritten
!= NULL
)
2985 *lpNumberOfCharsWritten
=
2986 Reply
.Data
.WriteConsoleReply
.NrCharactersWritten
;
2995 /*--------------------------------------------------------------
2996 * CreateConsoleScreenBuffer
3002 CreateConsoleScreenBuffer(
3003 DWORD dwDesiredAccess
,
3005 CONST SECURITY_ATTRIBUTES
*lpSecurityAttributes
,
3007 LPVOID lpScreenBufferData
3010 // FIXME: don't ignore access, share mode, and security
3011 CSRSS_API_REQUEST Request
;
3012 CSRSS_API_REPLY Reply
;
3015 Request
.Type
= CSRSS_CREATE_SCREEN_BUFFER
;
3016 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
3017 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
3019 SetLastErrorByStatus ( Status
);
3022 return Reply
.Data
.CreateScreenBufferReply
.OutputHandle
;
3026 /*--------------------------------------------------------------
3033 GetConsoleCP( VOID
)
3036 return CP_OEMCP
; /* FIXME */
3040 /*--------------------------------------------------------------
3056 /*--------------------------------------------------------------
3057 * GetConsoleOutputCP
3063 GetConsoleOutputCP( VOID
)
3066 return 0; /* FIXME */
3070 /*--------------------------------------------------------------
3071 * SetConsoleOutputCP
3086 /*--------------------------------------------------------------
3087 * GetConsoleProcessList
3092 GetConsoleProcessList(LPDWORD lpdwProcessList
,
3093 DWORD dwProcessCount
)
3095 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3101 /*--------------------------------------------------------------
3102 * GetConsoleSelectionInfo
3107 GetConsoleSelectionInfo(PCONSOLE_SELECTION_INFO lpConsoleSelectionInfo
)
3109 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3115 /*--------------------------------------------------------------
3121 AttachConsole(DWORD dwProcessId
)
3123 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3127 /*--------------------------------------------------------------
3133 GetConsoleWindow (VOID
)
3135 CSRSS_API_REQUEST Request
;
3136 CSRSS_API_REPLY Reply
;
3139 Request
.Data
.ConsoleWindowRequest
.ConsoleHandle
=
3140 OpenConsoleW (L
"CONOUT$", (GENERIC_READ
|GENERIC_WRITE
), FALSE
, OPEN_EXISTING
);
3141 if (INVALID_HANDLE_VALUE
== Request
.Data
.ConsoleWindowRequest
.ConsoleHandle
)
3145 Request
.Type
= CSRSS_GET_CONSOLE_WINDOW
;
3146 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
3147 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
3149 SetLastErrorByStatus (Status
);
3152 return Reply
.Data
.ConsoleWindowReply
.WindowHandle
;
3156 /*--------------------------------------------------------------
3160 BOOL STDCALL
SetConsoleIcon(HICON hicon
)
3162 CSRSS_API_REQUEST Request
;
3163 CSRSS_API_REPLY Reply
;
3166 Request
.Data
.ConsoleSetWindowIconRequest
.ConsoleHandle
=
3167 OpenConsoleW (L
"CONOUT$", (GENERIC_READ
|GENERIC_WRITE
), FALSE
, OPEN_EXISTING
);
3168 if (INVALID_HANDLE_VALUE
== Request
.Data
.ConsoleSetWindowIconRequest
.ConsoleHandle
)
3172 Request
.Type
= CSRSS_SET_CONSOLE_ICON
;
3173 Request
.Data
.ConsoleSetWindowIconRequest
.WindowIcon
= hicon
;
3174 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
3175 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
3177 SetLastErrorByStatus (Status
);
3180 return NT_SUCCESS(Status
);