1 /* $Id: console.c,v 1.81 2004/09/14 22:30:56 hbirr 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");
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 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
160 AddConsoleAliasW (LPWSTR Source
,
164 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
173 ConsoleMenuControl (HANDLE hConsole
,
180 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
189 DuplicateConsoleHandle (HANDLE hConsole
,
190 DWORD dwDesiredAccess
,
194 CSRSS_API_REQUEST Request
;
195 CSRSS_API_REPLY Reply
;
198 if (IsConsoleHandle (hConsole
) == FALSE
)
200 SetLastError (ERROR_INVALID_PARAMETER
);
201 return INVALID_HANDLE_VALUE
;
204 Request
.Type
= CSRSS_DUPLICATE_HANDLE
;
205 Request
.Data
.DuplicateHandleRequest
.Handle
= hConsole
;
206 Request
.Data
.DuplicateHandleRequest
.ProcessId
= GetCurrentProcessId();
207 Status
= CsrClientCallServer(&Request
,
209 sizeof(CSRSS_API_REQUEST
),
210 sizeof(CSRSS_API_REPLY
));
211 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
=Reply
.Status
))
213 SetLastErrorByStatus(Status
);
214 return INVALID_HANDLE_VALUE
;
216 return Reply
.Data
.DuplicateHandleReply
.Handle
;
224 ExpungeConsoleCommandHistoryW (DWORD Unknown0
)
229 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
238 ExpungeConsoleCommandHistoryA (DWORD Unknown0
)
243 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
252 GetConsoleAliasW (DWORD Unknown0
,
260 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
269 GetConsoleAliasA (DWORD Unknown0
,
277 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
286 GetConsoleAliasExesW (DWORD Unknown0
,
292 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
301 GetConsoleAliasExesA (DWORD Unknown0
,
307 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
316 GetConsoleAliasExesLengthA (VOID
)
321 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
330 GetConsoleAliasExesLengthW (VOID
)
335 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
344 GetConsoleAliasesW (DWORD Unknown0
,
351 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
360 GetConsoleAliasesA (DWORD Unknown0
,
367 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
376 GetConsoleAliasesLengthW (DWORD Unknown0
)
381 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
390 GetConsoleAliasesLengthA (DWORD Unknown0
)
395 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
404 GetConsoleCommandHistoryW (DWORD Unknown0
,
411 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
420 GetConsoleCommandHistoryA (DWORD Unknown0
,
427 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
436 GetConsoleCommandHistoryLengthW (DWORD Unknown0
)
441 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
450 GetConsoleCommandHistoryLengthA (DWORD Unknown0
)
455 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
463 GetConsoleDisplayMode (LPDWORD lpdwMode
)
465 * FUNCTION: Get the console display mode
467 * lpdwMode - Address of variable that receives the current value
469 * STATUS: Undocumented
472 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
481 GetConsoleFontInfo (DWORD Unknown0
,
489 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
498 GetConsoleFontSize(HANDLE hConsoleOutput
,
501 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
510 GetConsoleHardwareState (HANDLE hConsole
,
517 CSRSS_API_REQUEST Request
;
518 CSRSS_API_REPLY Reply
;
521 Request
.Type
= CSRSS_SETGET_CONSOLE_HW_STATE
;
522 Request
.Data
.ConsoleHardwareStateRequest
.ConsoleHandle
= hConsole
;
523 Request
.Data
.ConsoleHardwareStateRequest
.SetGet
= CONSOLE_HARDWARE_STATE_GET
;
525 Status
= CsrClientCallServer(& Request
,
527 sizeof(CSRSS_API_REQUEST
),
528 sizeof(CSRSS_API_REPLY
));
529 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
531 SetLastErrorByStatus(Status
);
534 *State
= Reply
.Data
.ConsoleHardwareStateReply
.State
;
543 GetConsoleInputWaitHandle (VOID
)
548 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
557 GetCurrentConsoleFont(HANDLE hConsoleOutput
,
559 PCONSOLE_FONT_INFO lpConsoleCurrentFont
)
561 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
570 GetNumberOfConsoleFonts (VOID
)
575 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
576 return 1; /* FIXME: call csrss.exe */
584 InvalidateConsoleDIBits (DWORD Unknown0
,
590 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
599 OpenConsoleW (LPWSTR wsName
,
600 DWORD dwDesiredAccess
,
602 DWORD dwCreationDistribution
)
607 CSRSS_API_REQUEST Request
;
608 CSRSS_API_REPLY Reply
;
609 PHANDLE phConsole
= NULL
;
610 NTSTATUS Status
= STATUS_SUCCESS
;
613 if(0 == _wcsicmp(wsName
, L
"CONIN$"))
615 Request
.Type
= CSRSS_GET_INPUT_HANDLE
;
616 phConsole
= & Reply
.Data
.GetInputHandleReply
.InputHandle
;
618 else if (0 == _wcsicmp(wsName
, L
"CONOUT$"))
620 Request
.Type
= CSRSS_GET_OUTPUT_HANDLE
;
621 phConsole
= & Reply
.Data
.GetOutputHandleReply
.OutputHandle
;
625 SetLastError(ERROR_INVALID_PARAMETER
);
626 return(INVALID_HANDLE_VALUE
);
628 if ((GENERIC_READ
|GENERIC_WRITE
) != dwDesiredAccess
)
630 SetLastError(ERROR_INVALID_PARAMETER
);
631 return(INVALID_HANDLE_VALUE
);
633 if (OPEN_EXISTING
!= dwCreationDistribution
)
635 SetLastError(ERROR_INVALID_PARAMETER
);
636 return(INVALID_HANDLE_VALUE
);
638 Status
= CsrClientCallServer(& Request
,
640 sizeof(CSRSS_API_REQUEST
),
641 sizeof(CSRSS_API_REPLY
));
642 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
644 SetLastErrorByStatus(Status
);
645 return INVALID_HANDLE_VALUE
;
655 SetConsoleCommandHistoryMode (DWORD dwMode
)
660 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
669 SetConsoleCursor (DWORD Unknown0
,
675 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
684 SetConsoleDisplayMode (HANDLE hOut
,
688 * FUNCTION: Set the console display mode.
690 * hOut - Standard output handle.
691 * dwNewMode - New mode.
692 * lpdwOldMode - Address of a variable that receives the old mode.
695 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
704 SetConsoleFont (DWORD Unknown0
,
710 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
719 SetConsoleHardwareState (HANDLE hConsole
,
726 CSRSS_API_REQUEST Request
;
727 CSRSS_API_REPLY Reply
;
730 Request
.Type
= CSRSS_SETGET_CONSOLE_HW_STATE
;
731 Request
.Data
.ConsoleHardwareStateRequest
.ConsoleHandle
= hConsole
;
732 Request
.Data
.ConsoleHardwareStateRequest
.SetGet
= CONSOLE_HARDWARE_STATE_SET
;
733 Request
.Data
.ConsoleHardwareStateRequest
.State
= State
;
735 Status
= CsrClientCallServer(& Request
,
737 sizeof(CSRSS_API_REQUEST
),
738 sizeof(CSRSS_API_REPLY
));
739 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
741 SetLastErrorByStatus(Status
);
752 SetConsoleKeyShortcuts (DWORD Unknown0
,
760 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
769 SetConsoleMaximumWindowSize (DWORD Unknown0
,
775 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
784 SetConsoleMenuClose (DWORD Unknown0
)
789 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
798 SetConsoleNumberOfCommandsA (DWORD Unknown0
,
804 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
813 SetConsoleNumberOfCommandsW (DWORD Unknown0
,
819 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
828 SetConsolePalette (DWORD Unknown0
,
835 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
844 SetLastConsoleEventActive (VOID
)
849 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
858 ShowConsoleCursor (DWORD Unknown0
,
864 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
870 * FUNCTION: Checks whether the given handle is a valid console handle.
872 * Handle - Handle to be checked
874 * TRUE: Handle is a valid console handle
875 * FALSE: Handle is not a valid console handle.
876 * STATUS: Officially undocumented
881 VerifyConsoleIoHandle(HANDLE Handle
)
883 CSRSS_API_REQUEST Request
;
884 CSRSS_API_REPLY Reply
;
887 Request
.Type
= CSRSS_VERIFY_HANDLE
;
888 Request
.Data
.VerifyHandleRequest
.Handle
= Handle
;
889 Status
= CsrClientCallServer(&Request
,
891 sizeof(CSRSS_API_REQUEST
),
892 sizeof(CSRSS_API_REPLY
));
893 if (!NT_SUCCESS(Status
))
895 SetLastErrorByStatus(Status
);
899 return (BOOL
)NT_SUCCESS(Reply
.Status
);
907 WriteConsoleInputVDMA (DWORD Unknown0
,
912 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
921 WriteConsoleInputVDMW (DWORD Unknown0
,
926 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
935 CloseConsoleHandle(HANDLE Handle
)
940 CSRSS_API_REQUEST Request
;
941 CSRSS_API_REPLY Reply
;
944 if (IsConsoleHandle (Handle
) == FALSE
)
946 SetLastError (ERROR_INVALID_PARAMETER
);
950 Request
.Type
= CSRSS_CLOSE_HANDLE
;
951 Request
.Data
.CloseHandleRequest
.Handle
= Handle
;
952 Status
= CsrClientCallServer(&Request
,
954 sizeof(CSRSS_API_REQUEST
),
955 sizeof(CSRSS_API_REPLY
));
956 if (!NT_SUCCESS(Status
))
958 SetLastErrorByStatus(Status
);
970 IsConsoleHandle(HANDLE Handle
)
972 if ((((ULONG
)Handle
) & 0x10000003) == 0x3)
984 GetStdHandle(DWORD nStdHandle
)
986 * FUNCTION: Get a handle for the standard input, standard output
987 * and a standard error device.
989 * nStdHandle - Specifies the device for which to return the handle.
990 * RETURNS: If the function succeeds, the return value is the handle
991 * of the specified device. Otherwise the value is INVALID_HANDLE_VALUE.
994 PRTL_USER_PROCESS_PARAMETERS Ppb
;
996 Ppb
= NtCurrentPeb()->ProcessParameters
;
999 case STD_INPUT_HANDLE
:
1000 return Ppb
->hStdInput
;
1002 case STD_OUTPUT_HANDLE
:
1003 return Ppb
->hStdOutput
;
1005 case STD_ERROR_HANDLE
:
1006 return Ppb
->hStdError
;
1009 SetLastError (ERROR_INVALID_PARAMETER
);
1010 return INVALID_HANDLE_VALUE
;
1018 SetStdHandle(DWORD nStdHandle
,
1021 * FUNCTION: Set the handle for the standard input, standard output or
1022 * the standard error device.
1024 * nStdHandle - Specifies the handle to be set.
1025 * hHandle - The handle to set.
1026 * RETURNS: TRUE if the function succeeds, FALSE otherwise.
1029 PRTL_USER_PROCESS_PARAMETERS Ppb
;
1031 /* no need to check if hHandle == INVALID_HANDLE_VALUE */
1033 Ppb
= NtCurrentPeb()->ProcessParameters
;
1037 case STD_INPUT_HANDLE
:
1038 Ppb
->hStdInput
= hHandle
;
1041 case STD_OUTPUT_HANDLE
:
1042 Ppb
->hStdOutput
= hHandle
;
1045 case STD_ERROR_HANDLE
:
1046 Ppb
->hStdError
= hHandle
;
1050 /* windows for whatever reason sets the last error to ERROR_INVALID_HANDLE here */
1051 SetLastError (ERROR_INVALID_HANDLE
);
1056 /*--------------------------------------------------------------
1062 WriteConsoleA(HANDLE hConsoleOutput
,
1063 CONST VOID
*lpBuffer
,
1064 DWORD nNumberOfCharsToWrite
,
1065 LPDWORD lpNumberOfCharsWritten
,
1068 PCSRSS_API_REQUEST Request
;
1069 CSRSS_API_REPLY Reply
;
1074 Request
= RtlAllocateHeap(GetProcessHeap(), 0,
1075 sizeof(CSRSS_API_REQUEST
) +
1076 min(nNumberOfCharsToWrite
,
1077 CSRSS_MAX_WRITE_CONSOLE_REQUEST
));
1078 if (Request
== NULL
)
1080 SetLastError(ERROR_OUTOFMEMORY
);
1084 Request
->Type
= CSRSS_WRITE_CONSOLE
;
1085 Request
->Data
.WriteConsoleRequest
.ConsoleHandle
= hConsoleOutput
;
1086 if (lpNumberOfCharsWritten
!= NULL
)
1087 *lpNumberOfCharsWritten
= nNumberOfCharsToWrite
;
1088 while (nNumberOfCharsToWrite
)
1090 if (nNumberOfCharsToWrite
> CSRSS_MAX_WRITE_CONSOLE_REQUEST
)
1092 Size
= CSRSS_MAX_WRITE_CONSOLE_REQUEST
;
1096 Size
= nNumberOfCharsToWrite
;
1098 Request
->Data
.WriteConsoleRequest
.NrCharactersToWrite
= Size
;
1100 memcpy(Request
->Data
.WriteConsoleRequest
.Buffer
, lpBuffer
, Size
);
1102 MessageSize
= CSRSS_REQUEST_HEADER_SIZE
+
1103 sizeof(CSRSS_WRITE_CONSOLE_REQUEST
) + Size
;
1104 Status
= CsrClientCallServer(Request
,
1107 sizeof(CSRSS_API_REPLY
));
1109 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
1111 RtlFreeHeap(GetProcessHeap(), 0, Request
);
1112 SetLastErrorByStatus(Status
);
1115 nNumberOfCharsToWrite
-= Size
;
1119 RtlFreeHeap(GetProcessHeap(), 0, Request
);
1125 /*--------------------------------------------------------------
1130 BOOL STDCALL
ReadConsoleA(HANDLE hConsoleInput
,
1132 DWORD nNumberOfCharsToRead
,
1133 LPDWORD lpNumberOfCharsRead
,
1136 CSRSS_API_REQUEST Request
;
1137 PCSRSS_API_REPLY Reply
;
1139 ULONG CharsRead
= 0;
1141 Reply
= RtlAllocateHeap(GetProcessHeap(), 0,
1142 sizeof(CSRSS_API_REPLY
) + nNumberOfCharsToRead
);
1145 SetLastError(ERROR_OUTOFMEMORY
);
1149 Request
.Type
= CSRSS_READ_CONSOLE
;
1150 Request
.Data
.ReadConsoleRequest
.ConsoleHandle
= hConsoleInput
;
1151 Request
.Data
.ReadConsoleRequest
.NrCharactersToRead
= nNumberOfCharsToRead
> CSRSS_MAX_READ_CONSOLE_REQUEST
? CSRSS_MAX_READ_CONSOLE_REQUEST
: nNumberOfCharsToRead
;
1152 Request
.Data
.ReadConsoleRequest
.nCharsCanBeDeleted
= 0;
1153 Status
= CsrClientCallServer(&Request
,
1155 sizeof(CSRSS_API_REQUEST
),
1156 sizeof(CSRSS_API_REPLY
) +
1157 Request
.Data
.ReadConsoleRequest
.NrCharactersToRead
);
1158 if (!NT_SUCCESS(Status
) || !NT_SUCCESS( Status
= Reply
->Status
))
1160 DbgPrint( "CSR returned error in ReadConsole\n" );
1161 SetLastErrorByStatus ( Status
);
1162 RtlFreeHeap( GetProcessHeap(), 0, Reply
);
1165 if( Reply
->Status
== STATUS_NOTIFY_CLEANUP
)
1166 Reply
->Status
= STATUS_PENDING
; // ignore backspace because we have no chars to backspace
1167 /* There may not be any chars or lines to read yet, so wait */
1168 while( Reply
->Status
== STATUS_PENDING
)
1170 /* some chars may have been returned, but not a whole line yet, so recompute buffer and try again */
1171 nNumberOfCharsToRead
-= Reply
->Data
.ReadConsoleReply
.NrCharactersRead
;
1172 /* don't overflow caller's buffer, even if you still don't have a complete line */
1173 if( !nNumberOfCharsToRead
)
1175 Request
.Data
.ReadConsoleRequest
.NrCharactersToRead
= nNumberOfCharsToRead
> CSRSS_MAX_READ_CONSOLE_REQUEST
? CSRSS_MAX_READ_CONSOLE_REQUEST
: nNumberOfCharsToRead
;
1176 /* copy any chars already read to buffer */
1177 memcpy( lpBuffer
+ CharsRead
, Reply
->Data
.ReadConsoleReply
.Buffer
, Reply
->Data
.ReadConsoleReply
.NrCharactersRead
);
1178 CharsRead
+= Reply
->Data
.ReadConsoleReply
.NrCharactersRead
;
1179 /* wait for csrss to signal there is more data to read, but not if we got STATUS_NOTIFY_CLEANUP for backspace */
1180 Status
= NtWaitForSingleObject( Reply
->Data
.ReadConsoleReply
.EventHandle
, FALSE
, 0 );
1181 if( !NT_SUCCESS( Status
) )
1183 DbgPrint( "Wait for console input failed!\n" );
1184 RtlFreeHeap( GetProcessHeap(), 0, Reply
);
1187 Request
.Data
.ReadConsoleRequest
.nCharsCanBeDeleted
= CharsRead
;
1188 Status
= CsrClientCallServer( &Request
, Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) + Request
.Data
.ReadConsoleRequest
.NrCharactersToRead
);
1189 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
->Status
) )
1191 SetLastErrorByStatus ( Status
);
1192 RtlFreeHeap( GetProcessHeap(), 0, Reply
);
1195 if( Reply
->Status
== STATUS_NOTIFY_CLEANUP
)
1201 nNumberOfCharsToRead
++;
1203 Reply
->Status
= STATUS_PENDING
; // retry
1206 /* copy data to buffer, count total returned, and return */
1207 memcpy( lpBuffer
+ CharsRead
, Reply
->Data
.ReadConsoleReply
.Buffer
, Reply
->Data
.ReadConsoleReply
.NrCharactersRead
);
1208 CharsRead
+= Reply
->Data
.ReadConsoleReply
.NrCharactersRead
;
1209 if (lpNumberOfCharsRead
!= NULL
)
1210 *lpNumberOfCharsRead
= CharsRead
;
1211 RtlFreeHeap(GetProcessHeap(),
1219 /*--------------------------------------------------------------
1224 BOOL STDCALL
AllocConsole(VOID
)
1226 CSRSS_API_REQUEST Request
;
1227 CSRSS_API_REPLY Reply
;
1231 if(NtCurrentPeb()->ProcessParameters
->hConsole
)
1233 DPRINT("AllocConsole: Allocate duplicate console to the same Process\n");
1234 SetLastErrorByStatus (STATUS_OBJECT_NAME_EXISTS
);
1238 Request
.Data
.AllocConsoleRequest
.CtrlDispatcher
= (PCONTROLDISPATCHER
) &ConsoleControlDispatcher
;
1240 Request
.Type
= CSRSS_ALLOC_CONSOLE
;
1241 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
1242 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
1244 SetLastErrorByStatus ( Status
);
1247 NtCurrentPeb()->ProcessParameters
->hConsole
= Reply
.Data
.AllocConsoleReply
.Console
;
1248 SetStdHandle( STD_INPUT_HANDLE
, Reply
.Data
.AllocConsoleReply
.InputHandle
);
1249 SetStdHandle( STD_OUTPUT_HANDLE
, Reply
.Data
.AllocConsoleReply
.OutputHandle
);
1250 hStdError
= DuplicateConsoleHandle(Reply
.Data
.AllocConsoleReply
.OutputHandle
,
1253 DUPLICATE_SAME_ACCESS
);
1254 SetStdHandle( STD_ERROR_HANDLE
, hStdError
);
1259 /*--------------------------------------------------------------
1264 BOOL STDCALL
FreeConsole(VOID
)
1266 // AG: I'm not sure if this is correct (what happens to std handles?)
1267 // but I just tried to reverse what AllocConsole() does...
1269 CSRSS_API_REQUEST Request
;
1270 CSRSS_API_REPLY Reply
;
1273 Request
.Type
= CSRSS_FREE_CONSOLE
;
1274 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
1275 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
1277 SetLastErrorByStatus ( Status
);
1285 /*--------------------------------------------------------------
1286 * GetConsoleScreenBufferInfo
1292 GetConsoleScreenBufferInfo(
1293 HANDLE hConsoleOutput
,
1294 PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo
1297 CSRSS_API_REQUEST Request
;
1298 CSRSS_API_REPLY Reply
;
1301 Request
.Type
= CSRSS_SCREEN_BUFFER_INFO
;
1302 Request
.Data
.ScreenBufferInfoRequest
.ConsoleHandle
= hConsoleOutput
;
1303 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
1304 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
1306 SetLastErrorByStatus ( Status
);
1309 *lpConsoleScreenBufferInfo
= Reply
.Data
.ScreenBufferInfoReply
.Info
;
1314 /*--------------------------------------------------------------
1315 * SetConsoleCursorPosition
1321 SetConsoleCursorPosition(
1322 HANDLE hConsoleOutput
,
1323 COORD dwCursorPosition
1326 CSRSS_API_REQUEST Request
;
1327 CSRSS_API_REPLY Reply
;
1330 Request
.Type
= CSRSS_SET_CURSOR
;
1331 Request
.Data
.SetCursorRequest
.ConsoleHandle
= hConsoleOutput
;
1332 Request
.Data
.SetCursorRequest
.Position
= dwCursorPosition
;
1333 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
1334 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
1336 SetLastErrorByStatus ( Status
);
1343 /*--------------------------------------------------------------
1344 * FillConsoleOutputCharacterA
1349 FillConsoleOutputCharacterA(
1350 HANDLE hConsoleOutput
,
1354 LPDWORD lpNumberOfCharsWritten
1357 CSRSS_API_REQUEST Request
;
1358 CSRSS_API_REPLY Reply
;
1361 Request
.Type
= CSRSS_FILL_OUTPUT
;
1362 Request
.Data
.FillOutputRequest
.ConsoleHandle
= hConsoleOutput
;
1363 Request
.Data
.FillOutputRequest
.Char
= cCharacter
;
1364 Request
.Data
.FillOutputRequest
.Position
= dwWriteCoord
;
1365 Request
.Data
.FillOutputRequest
.Length
= nLength
;
1366 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
1367 if ( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
1369 SetLastErrorByStatus(Status
);
1372 if (lpNumberOfCharsWritten
!= NULL
)
1373 *lpNumberOfCharsWritten
= nLength
;
1378 /*--------------------------------------------------------------
1379 * FillConsoleOutputCharacterW
1385 FillConsoleOutputCharacterW(
1386 HANDLE hConsoleOutput
,
1390 LPDWORD lpNumberOfCharsWritten
1394 DbgPrint("%s unimplemented\n", __FUNCTION__
);
1399 /*--------------------------------------------------------------
1400 * IntPeekConsoleInput
1406 IntPeekConsoleInput(
1407 HANDLE hConsoleInput
,
1408 PINPUT_RECORD lpBuffer
,
1410 LPDWORD lpNumberOfEventsRead
,
1414 PCSRSS_API_REQUEST Request
;
1415 CSRSS_API_REPLY Reply
;
1418 PVOID BufferTargetBase
;
1421 if(lpBuffer
== NULL
)
1423 SetLastError(ERROR_INVALID_PARAMETER
);
1427 Size
= nLength
* sizeof(INPUT_RECORD
);
1429 Status
= CsrCaptureParameterBuffer((PVOID
)lpBuffer
, Size
, &BufferBase
, &BufferTargetBase
);
1430 if(!NT_SUCCESS(Status
))
1432 SetLastErrorByStatus(Status
);
1436 Request
= RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CSRSS_API_REQUEST
));
1439 CsrReleaseParameterBuffer(BufferBase
);
1440 SetLastError(ERROR_OUTOFMEMORY
);
1444 Request
->Type
= CSRSS_PEEK_CONSOLE_INPUT
;
1445 Request
->Data
.PeekConsoleInputRequest
.ConsoleHandle
= hConsoleInput
;
1446 Request
->Data
.PeekConsoleInputRequest
.Unicode
= bUnicode
;
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
);
1470 /*--------------------------------------------------------------
1478 HANDLE hConsoleInput
,
1479 PINPUT_RECORD lpBuffer
,
1481 LPDWORD lpNumberOfEventsRead
1484 return IntPeekConsoleInput(hConsoleInput
, lpBuffer
, nLength
,
1485 lpNumberOfEventsRead
, FALSE
);
1489 /*--------------------------------------------------------------
1497 HANDLE hConsoleInput
,
1498 PINPUT_RECORD lpBuffer
,
1500 LPDWORD lpNumberOfEventsRead
1503 return IntPeekConsoleInput(hConsoleInput
, lpBuffer
, nLength
,
1504 lpNumberOfEventsRead
, TRUE
);
1508 /*--------------------------------------------------------------
1509 * IntReadConsoleInput
1514 IntReadConsoleInput(HANDLE hConsoleInput
,
1515 PINPUT_RECORD lpBuffer
,
1517 LPDWORD lpNumberOfEventsRead
,
1520 CSRSS_API_REQUEST Request
;
1521 CSRSS_API_REPLY Reply
;
1522 DWORD NumEventsRead
;
1525 Request
.Type
= CSRSS_READ_INPUT
;
1526 Request
.Data
.ReadInputRequest
.ConsoleHandle
= hConsoleInput
;
1527 Status
= CsrClientCallServer(&Request
, &Reply
, sizeof(CSRSS_API_REQUEST
),
1528 sizeof(CSRSS_API_REPLY
));
1529 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
1531 SetLastErrorByStatus(Status
);
1535 while (Status
== STATUS_PENDING
)
1537 Status
= NtWaitForSingleObject(Reply
.Data
.ReadInputReply
.Event
, FALSE
,
1539 if(!NT_SUCCESS(Status
))
1541 SetLastErrorByStatus(Status
);
1545 Request
.Type
= CSRSS_READ_INPUT
;
1546 Request
.Data
.ReadInputRequest
.ConsoleHandle
= hConsoleInput
;
1547 Request
.Data
.ReadInputRequest
.Unicode
= bUnicode
;
1548 Status
= CsrClientCallServer(&Request
, &Reply
, sizeof(CSRSS_API_REQUEST
),
1549 sizeof(CSRSS_API_REPLY
));
1550 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
1552 SetLastErrorByStatus(Status
);
1558 *lpBuffer
= Reply
.Data
.ReadInputReply
.Input
;
1561 while ((NumEventsRead
< nLength
) && (Reply
.Data
.ReadInputReply
.MoreEvents
))
1563 Status
= CsrClientCallServer(&Request
, &Reply
, sizeof(CSRSS_API_REQUEST
),
1564 sizeof(CSRSS_API_REPLY
));
1565 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
1567 SetLastErrorByStatus(Status
);
1571 if (Status
== STATUS_PENDING
)
1576 *lpBuffer
= Reply
.Data
.ReadInputReply
.Input
;
1581 *lpNumberOfEventsRead
= NumEventsRead
;
1587 /*--------------------------------------------------------------
1593 ReadConsoleInputA(HANDLE hConsoleInput
,
1594 PINPUT_RECORD lpBuffer
,
1596 LPDWORD lpNumberOfEventsRead
)
1598 return IntReadConsoleInput(hConsoleInput
, lpBuffer
, nLength
,
1599 lpNumberOfEventsRead
, FALSE
);
1603 /*--------------------------------------------------------------
1611 HANDLE hConsoleInput
,
1612 PINPUT_RECORD lpBuffer
,
1614 LPDWORD lpNumberOfEventsRead
1617 return IntReadConsoleInput(hConsoleInput
, lpBuffer
, nLength
,
1618 lpNumberOfEventsRead
, TRUE
);
1622 /*--------------------------------------------------------------
1623 * WriteConsoleInputA
1630 HANDLE hConsoleInput
,
1631 CONST INPUT_RECORD
*lpBuffer
,
1633 LPDWORD lpNumberOfEventsWritten
1636 PCSRSS_API_REQUEST Request
;
1637 CSRSS_API_REPLY Reply
;
1638 PVOID BufferBase
, BufferTargetBase
;
1642 if(lpBuffer
== NULL
)
1644 SetLastError(ERROR_INVALID_PARAMETER
);
1648 Size
= nLength
* sizeof(INPUT_RECORD
);
1650 Status
= CsrCaptureParameterBuffer((PVOID
)lpBuffer
, Size
, &BufferBase
, &BufferTargetBase
);
1651 if(!NT_SUCCESS(Status
))
1653 SetLastErrorByStatus(Status
);
1657 Request
= RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CSRSS_API_REQUEST
));
1660 SetLastError(ERROR_OUTOFMEMORY
);
1661 CsrReleaseParameterBuffer(BufferBase
);
1665 Request
->Type
= CSRSS_WRITE_CONSOLE_INPUT
;
1666 Request
->Data
.WriteConsoleInputRequest
.ConsoleHandle
= hConsoleInput
;
1667 Request
->Data
.WriteConsoleInputRequest
.Length
= nLength
;
1668 Request
->Data
.WriteConsoleInputRequest
.InputRecord
= (PINPUT_RECORD
)BufferTargetBase
;
1670 Status
= CsrClientCallServer(Request
, &Reply
, sizeof(CSRSS_API_REQUEST
), sizeof(CSRSS_API_REPLY
));
1671 if(!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
1673 RtlFreeHeap(GetProcessHeap(), 0, Request
);
1674 CsrReleaseParameterBuffer(BufferBase
);
1678 if(lpNumberOfEventsWritten
!= NULL
)
1679 *lpNumberOfEventsWritten
= Reply
.Data
.WriteConsoleInputReply
.Length
;
1681 RtlFreeHeap(GetProcessHeap(), 0, Request
);
1682 CsrReleaseParameterBuffer(BufferBase
);
1688 /*--------------------------------------------------------------
1689 * WriteConsoleInputW
1696 HANDLE hConsoleInput
,
1697 CONST INPUT_RECORD
*lpBuffer
,
1699 LPDWORD lpNumberOfEventsWritten
1703 DbgPrint("%s unimplemented\n", __FUNCTION__
);
1708 /*--------------------------------------------------------------
1709 * IntReadConsoleOutput
1715 IntReadConsoleOutput(
1716 HANDLE hConsoleOutput
,
1717 PCHAR_INFO lpBuffer
,
1719 COORD dwBufferCoord
,
1720 PSMALL_RECT lpReadRegion
,
1724 PCSRSS_API_REQUEST Request
;
1725 CSRSS_API_REPLY Reply
;
1727 PVOID BufferTargetBase
;
1729 DWORD Size
, SizeX
, SizeY
;
1731 if(lpBuffer
== NULL
)
1733 SetLastError(ERROR_INVALID_PARAMETER
);
1737 Size
= dwBufferSize
.X
* dwBufferSize
.Y
* sizeof(CHAR_INFO
);
1739 Status
= CsrCaptureParameterBuffer((PVOID
)lpBuffer
, Size
, &BufferBase
, &BufferTargetBase
);
1740 if(!NT_SUCCESS(Status
))
1742 SetLastErrorByStatus(Status
);
1746 Request
= RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CSRSS_API_REQUEST
));
1749 SetLastError(ERROR_OUTOFMEMORY
);
1750 CsrReleaseParameterBuffer(BufferBase
);
1754 Request
->Type
= CSRSS_READ_CONSOLE_OUTPUT
;
1755 Request
->Data
.ReadConsoleOutputRequest
.ConsoleHandle
= hConsoleOutput
;
1756 Request
->Data
.ReadConsoleOutputRequest
.Unicode
= bUnicode
;
1757 Request
->Data
.ReadConsoleOutputRequest
.BufferSize
= dwBufferSize
;
1758 Request
->Data
.ReadConsoleOutputRequest
.BufferCoord
= dwBufferCoord
;
1759 Request
->Data
.ReadConsoleOutputRequest
.ReadRegion
= *lpReadRegion
;
1760 Request
->Data
.ReadConsoleOutputRequest
.CharInfo
= (PCHAR_INFO
)BufferTargetBase
;
1762 Status
= CsrClientCallServer(Request
, &Reply
, sizeof(CSRSS_API_REQUEST
), sizeof(CSRSS_API_REPLY
));
1763 if(!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
1765 SetLastErrorByStatus(Status
);
1766 RtlFreeHeap(GetProcessHeap(), 0, Request
);
1767 CsrReleaseParameterBuffer(BufferBase
);
1771 SizeX
= Reply
.Data
.ReadConsoleOutputReply
.ReadRegion
.Right
- Reply
.Data
.ReadConsoleOutputReply
.ReadRegion
.Left
+ 1;
1772 SizeY
= Reply
.Data
.ReadConsoleOutputReply
.ReadRegion
.Bottom
- Reply
.Data
.ReadConsoleOutputReply
.ReadRegion
.Top
+ 1;
1774 memcpy(lpBuffer
, BufferBase
, sizeof(CHAR_INFO
) * SizeX
* SizeY
);
1775 *lpReadRegion
= Reply
.Data
.ReadConsoleOutputReply
.ReadRegion
;
1777 RtlFreeHeap(GetProcessHeap(), 0, Request
);
1778 CsrReleaseParameterBuffer(BufferBase
);
1783 /*--------------------------------------------------------------
1784 * ReadConsoleOutputA
1791 HANDLE hConsoleOutput
,
1792 PCHAR_INFO lpBuffer
,
1794 COORD dwBufferCoord
,
1795 PSMALL_RECT lpReadRegion
1798 return IntReadConsoleOutput(hConsoleOutput
, lpBuffer
, dwBufferSize
,
1799 dwBufferCoord
, lpReadRegion
, FALSE
);
1803 /*--------------------------------------------------------------
1804 * ReadConsoleOutputW
1811 HANDLE hConsoleOutput
,
1812 PCHAR_INFO lpBuffer
,
1814 COORD dwBufferCoord
,
1815 PSMALL_RECT lpReadRegion
1818 return IntReadConsoleOutput(hConsoleOutput
, lpBuffer
, dwBufferSize
,
1819 dwBufferCoord
, lpReadRegion
, TRUE
);
1823 /*--------------------------------------------------------------
1824 * IntWriteConsoleOutput
1829 IntWriteConsoleOutput(HANDLE hConsoleOutput
,
1830 CONST CHAR_INFO
*lpBuffer
,
1832 COORD dwBufferCoord
,
1833 PSMALL_RECT lpWriteRegion
,
1836 PCSRSS_API_REQUEST Request
;
1837 CSRSS_API_REPLY Reply
;
1841 PVOID BufferTargetBase
;
1843 Size
= dwBufferSize
.Y
* dwBufferSize
.X
* sizeof(CHAR_INFO
);
1845 Status
= CsrCaptureParameterBuffer((PVOID
)lpBuffer
,
1849 if (!NT_SUCCESS(Status
))
1851 SetLastErrorByStatus(Status
);
1855 Request
= RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY
,
1856 sizeof(CSRSS_API_REQUEST
));
1857 if (Request
== NULL
)
1859 CsrReleaseParameterBuffer(BufferBase
);
1860 SetLastError(ERROR_OUTOFMEMORY
);
1863 Request
->Type
= CSRSS_WRITE_CONSOLE_OUTPUT
;
1864 Request
->Data
.WriteConsoleOutputRequest
.ConsoleHandle
= hConsoleOutput
;
1865 Request
->Data
.WriteConsoleOutputRequest
.Unicode
= bUnicode
;
1866 Request
->Data
.WriteConsoleOutputRequest
.BufferSize
= dwBufferSize
;
1867 Request
->Data
.WriteConsoleOutputRequest
.BufferCoord
= dwBufferCoord
;
1868 Request
->Data
.WriteConsoleOutputRequest
.WriteRegion
= *lpWriteRegion
;
1869 Request
->Data
.WriteConsoleOutputRequest
.CharInfo
=
1870 (CHAR_INFO
*)BufferTargetBase
;
1872 Status
= CsrClientCallServer(Request
, &Reply
,
1873 sizeof(CSRSS_API_REQUEST
),
1874 sizeof(CSRSS_API_REPLY
));
1875 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
1877 CsrReleaseParameterBuffer(BufferBase
);
1878 RtlFreeHeap(GetProcessHeap(), 0, Request
);
1879 SetLastErrorByStatus(Status
);
1883 *lpWriteRegion
= Reply
.Data
.WriteConsoleOutputReply
.WriteRegion
;
1884 RtlFreeHeap(GetProcessHeap(), 0, Request
);
1885 CsrReleaseParameterBuffer(BufferBase
);
1889 /*--------------------------------------------------------------
1890 * WriteConsoleOutputA
1895 WriteConsoleOutputA(HANDLE hConsoleOutput
,
1896 CONST CHAR_INFO
*lpBuffer
,
1898 COORD dwBufferCoord
,
1899 PSMALL_RECT lpWriteRegion
)
1901 return IntWriteConsoleOutput(hConsoleOutput
, lpBuffer
, dwBufferSize
,
1902 dwBufferCoord
, lpWriteRegion
, FALSE
);
1906 /*--------------------------------------------------------------
1907 * WriteConsoleOutputW
1913 WriteConsoleOutputW(
1914 HANDLE hConsoleOutput
,
1915 CONST CHAR_INFO
*lpBuffer
,
1917 COORD dwBufferCoord
,
1918 PSMALL_RECT lpWriteRegion
1921 return IntWriteConsoleOutput(hConsoleOutput
, lpBuffer
, dwBufferSize
,
1922 dwBufferCoord
, lpWriteRegion
, TRUE
);
1926 /*--------------------------------------------------------------
1927 * ReadConsoleOutputCharacterA
1933 ReadConsoleOutputCharacterA(
1934 HANDLE hConsoleOutput
,
1938 LPDWORD lpNumberOfCharsRead
1941 CSRSS_API_REQUEST Request
;
1942 PCSRSS_API_REPLY Reply
;
1946 Reply
= RtlAllocateHeap(GetProcessHeap(), 0,
1947 sizeof(CSRSS_API_REPLY
) +
1948 min(nLength
, CSRSS_MAX_READ_CONSOLE_OUTPUT_CHAR
));
1951 SetLastError(ERROR_OUTOFMEMORY
);
1955 if (lpNumberOfCharsRead
!= NULL
)
1956 *lpNumberOfCharsRead
= nLength
;
1958 Request
.Type
= CSRSS_READ_CONSOLE_OUTPUT_CHAR
;
1959 Request
.Data
.ReadConsoleOutputCharRequest
.ConsoleHandle
= hConsoleOutput
;
1960 Request
.Data
.ReadConsoleOutputCharRequest
.ReadCoord
= dwReadCoord
;
1962 while (nLength
!= 0)
1964 if (nLength
> CSRSS_MAX_READ_CONSOLE_OUTPUT_CHAR
)
1965 Size
= CSRSS_MAX_READ_CONSOLE_OUTPUT_CHAR
;
1969 Request
.Data
.ReadConsoleOutputCharRequest
.NumCharsToRead
= Size
;
1971 Status
= CsrClientCallServer(&Request
,
1973 sizeof(CSRSS_API_REQUEST
),
1974 sizeof(CSRSS_API_REPLY
) + Size
);
1975 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Reply
->Status
))
1977 RtlFreeHeap(GetProcessHeap(), 0, Reply
);
1978 SetLastErrorByStatus(Status
);
1982 memcpy(lpCharacter
, &Reply
->Data
.ReadConsoleOutputCharReply
.String
[0], Size
);
1983 lpCharacter
+= Size
;
1985 Request
.Data
.ReadConsoleOutputCharRequest
.ReadCoord
= Reply
->Data
.ReadConsoleOutputCharReply
.EndCoord
;
1988 RtlFreeHeap(GetProcessHeap(), 0, Reply
);
1994 /*--------------------------------------------------------------
1995 * ReadConsoleOutputCharacterW
2001 ReadConsoleOutputCharacterW(
2002 HANDLE hConsoleOutput
,
2006 LPDWORD lpNumberOfCharsRead
2010 DbgPrint("%s unimplemented\n", __FUNCTION__
);
2015 /*--------------------------------------------------------------
2016 * ReadConsoleOutputAttribute
2022 ReadConsoleOutputAttribute(
2023 HANDLE hConsoleOutput
,
2027 LPDWORD lpNumberOfAttrsRead
2030 CSRSS_API_REQUEST Request
;
2031 PCSRSS_API_REPLY Reply
;
2035 Reply
= RtlAllocateHeap(GetProcessHeap(), 0,
2036 sizeof(CSRSS_API_REPLY
) +
2037 min(nLength
, CSRSS_MAX_READ_CONSOLE_OUTPUT_ATTRIB
));
2040 SetLastError(ERROR_OUTOFMEMORY
);
2044 if (lpNumberOfAttrsRead
!= NULL
)
2045 *lpNumberOfAttrsRead
= nLength
;
2047 Request
.Type
= CSRSS_READ_CONSOLE_OUTPUT_ATTRIB
;
2048 Request
.Data
.ReadConsoleOutputAttribRequest
.ConsoleHandle
= hConsoleOutput
;
2049 Request
.Data
.ReadConsoleOutputAttribRequest
.ReadCoord
= dwReadCoord
;
2051 while (nLength
!= 0)
2053 if (nLength
> CSRSS_MAX_READ_CONSOLE_OUTPUT_ATTRIB
)
2054 Size
= CSRSS_MAX_READ_CONSOLE_OUTPUT_ATTRIB
;
2058 Request
.Data
.ReadConsoleOutputAttribRequest
.NumAttrsToRead
= Size
;
2060 Status
= CsrClientCallServer(&Request
,
2062 sizeof(CSRSS_API_REQUEST
),
2063 sizeof(CSRSS_API_REPLY
) + Size
);
2064 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Reply
->Status
))
2066 RtlFreeHeap(GetProcessHeap(), 0, Reply
);
2067 SetLastErrorByStatus(Status
);
2071 // Convert CHARs to WORDs
2072 for(i
= 0; i
< Size
; ++i
)
2073 *lpAttribute
++ = Reply
->Data
.ReadConsoleOutputAttribReply
.String
[i
];
2076 Request
.Data
.ReadConsoleOutputAttribRequest
.ReadCoord
= Reply
->Data
.ReadConsoleOutputAttribReply
.EndCoord
;
2079 RtlFreeHeap(GetProcessHeap(), 0, Reply
);
2085 /*--------------------------------------------------------------
2086 * WriteConsoleOutputCharacterA
2091 WriteConsoleOutputCharacterA(HANDLE hConsoleOutput
,
2095 LPDWORD lpNumberOfCharsWritten
)
2097 PCSRSS_API_REQUEST Request
;
2098 CSRSS_API_REPLY Reply
;
2102 Request
= RtlAllocateHeap(GetProcessHeap(), 0,
2103 sizeof(CSRSS_API_REQUEST
) +
2104 min(nLength
, CSRSS_MAX_WRITE_CONSOLE_OUTPUT_CHAR
));
2107 SetLastError( ERROR_OUTOFMEMORY
);
2110 Request
->Type
= CSRSS_WRITE_CONSOLE_OUTPUT_CHAR
;
2111 Request
->Data
.WriteConsoleOutputCharRequest
.ConsoleHandle
= hConsoleOutput
;
2112 Request
->Data
.WriteConsoleOutputCharRequest
.Coord
= dwWriteCoord
;
2113 if( lpNumberOfCharsWritten
)
2114 *lpNumberOfCharsWritten
= nLength
;
2117 Size
= nLength
> CSRSS_MAX_WRITE_CONSOLE_OUTPUT_CHAR
? CSRSS_MAX_WRITE_CONSOLE_OUTPUT_CHAR
: nLength
;
2118 Request
->Data
.WriteConsoleOutputCharRequest
.Length
= Size
;
2119 memcpy( &Request
->Data
.WriteConsoleOutputCharRequest
.String
[0],
2122 Status
= CsrClientCallServer( Request
, &Reply
, sizeof( CSRSS_API_REQUEST
) + Size
, sizeof( CSRSS_API_REPLY
) );
2123 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
2125 RtlFreeHeap( GetProcessHeap(), 0, Request
);
2126 SetLastErrorByStatus ( Status
);
2130 lpCharacter
+= Size
;
2131 Request
->Data
.WriteConsoleOutputCharRequest
.Coord
= Reply
.Data
.WriteConsoleOutputCharReply
.EndCoord
;
2134 RtlFreeHeap( GetProcessHeap(), 0, Request
);
2139 /*--------------------------------------------------------------
2140 * WriteConsoleOutputCharacterW
2145 WriteConsoleOutputCharacterW(HANDLE hConsoleOutput
,
2146 LPCWSTR lpCharacter
,
2149 LPDWORD lpNumberOfCharsWritten
)
2151 PCSRSS_API_REQUEST Request
;
2152 CSRSS_API_REPLY Reply
;
2156 Request
= RtlAllocateHeap(GetProcessHeap(), 0,
2157 sizeof(CSRSS_API_REQUEST
) +
2158 min(nLength
, CSRSS_MAX_WRITE_CONSOLE_OUTPUT_CHAR
));
2161 SetLastError( ERROR_OUTOFMEMORY
);
2164 Request
->Type
= CSRSS_WRITE_CONSOLE_OUTPUT_CHAR
;
2165 Request
->Data
.WriteConsoleOutputCharRequest
.ConsoleHandle
= hConsoleOutput
;
2166 Request
->Data
.WriteConsoleOutputCharRequest
.Coord
= dwWriteCoord
;
2167 if( lpNumberOfCharsWritten
)
2168 *lpNumberOfCharsWritten
= nLength
;
2171 Size
= nLength
> CSRSS_MAX_WRITE_CONSOLE_OUTPUT_CHAR
? CSRSS_MAX_WRITE_CONSOLE_OUTPUT_CHAR
: nLength
;
2172 Request
->Data
.WriteConsoleOutputCharRequest
.Length
= Size
;
2173 Status
= RtlUnicodeToOemN (&Request
->Data
.WriteConsoleOutputCharRequest
.String
[0],
2176 (PWCHAR
)lpCharacter
,
2177 Size
* sizeof(WCHAR
));
2178 if (!NT_SUCCESS(Status
))
2180 RtlFreeHeap (GetProcessHeap(), 0, Request
);
2181 SetLastErrorByStatus (Status
);
2185 Status
= CsrClientCallServer( Request
, &Reply
, sizeof( CSRSS_API_REQUEST
) + Size
, sizeof( CSRSS_API_REPLY
) );
2186 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
2188 RtlFreeHeap( GetProcessHeap(), 0, Request
);
2189 SetLastErrorByStatus ( Status
);
2193 lpCharacter
+= Size
;
2194 Request
->Data
.WriteConsoleOutputCharRequest
.Coord
= Reply
.Data
.WriteConsoleOutputCharReply
.EndCoord
;
2197 RtlFreeHeap( GetProcessHeap(), 0, Request
);
2202 /*--------------------------------------------------------------
2203 * WriteConsoleOutputAttribute
2209 WriteConsoleOutputAttribute(
2210 HANDLE hConsoleOutput
,
2211 CONST WORD
*lpAttribute
,
2214 LPDWORD lpNumberOfAttrsWritten
2217 PCSRSS_API_REQUEST Request
;
2218 CSRSS_API_REPLY Reply
;
2223 Request
= RtlAllocateHeap(GetProcessHeap(), 0,
2224 sizeof(CSRSS_API_REQUEST
) +
2225 min(nLength
, CSRSS_MAX_WRITE_CONSOLE_OUTPUT_ATTRIB
));
2228 SetLastError( ERROR_OUTOFMEMORY
);
2231 Request
->Type
= CSRSS_WRITE_CONSOLE_OUTPUT_ATTRIB
;
2232 Request
->Data
.WriteConsoleOutputAttribRequest
.ConsoleHandle
= hConsoleOutput
;
2233 Request
->Data
.WriteConsoleOutputAttribRequest
.Coord
= dwWriteCoord
;
2234 if( lpNumberOfAttrsWritten
)
2235 *lpNumberOfAttrsWritten
= nLength
;
2238 Size
= nLength
> CSRSS_MAX_WRITE_CONSOLE_OUTPUT_ATTRIB
? CSRSS_MAX_WRITE_CONSOLE_OUTPUT_ATTRIB
: nLength
;
2239 Request
->Data
.WriteConsoleOutputAttribRequest
.Length
= Size
;
2240 for( c
= 0; c
< Size
; c
++ )
2241 Request
->Data
.WriteConsoleOutputAttribRequest
.String
[c
] = (char)lpAttribute
[c
];
2242 Status
= CsrClientCallServer( Request
, &Reply
, sizeof( CSRSS_API_REQUEST
) + (Size
* 2), sizeof( CSRSS_API_REPLY
) );
2243 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
2245 RtlFreeHeap( GetProcessHeap(), 0, Request
);
2246 SetLastErrorByStatus ( Status
);
2250 lpAttribute
+= Size
;
2251 Request
->Data
.WriteConsoleOutputAttribRequest
.Coord
= Reply
.Data
.WriteConsoleOutputAttribReply
.EndCoord
;
2254 RtlFreeHeap( GetProcessHeap(), 0, Request
);
2259 /*--------------------------------------------------------------
2260 * FillConsoleOutputAttribute
2266 FillConsoleOutputAttribute(
2267 HANDLE hConsoleOutput
,
2271 LPDWORD lpNumberOfAttrsWritten
2274 CSRSS_API_REQUEST Request
;
2275 CSRSS_API_REPLY Reply
;
2278 Request
.Type
= CSRSS_FILL_OUTPUT_ATTRIB
;
2279 Request
.Data
.FillOutputAttribRequest
.ConsoleHandle
= hConsoleOutput
;
2280 Request
.Data
.FillOutputAttribRequest
.Attribute
= wAttribute
;
2281 Request
.Data
.FillOutputAttribRequest
.Coord
= dwWriteCoord
;
2282 Request
.Data
.FillOutputAttribRequest
.Length
= nLength
;
2283 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
2284 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
2286 SetLastErrorByStatus ( Status
);
2289 if( lpNumberOfAttrsWritten
)
2290 *lpNumberOfAttrsWritten
= nLength
;
2295 /*--------------------------------------------------------------
2303 HANDLE hConsoleHandle
,
2307 CSRSS_API_REQUEST Request
;
2308 CSRSS_API_REPLY Reply
;
2311 Request
.Type
= CSRSS_GET_CONSOLE_MODE
;
2312 Request
.Data
.GetConsoleModeRequest
.ConsoleHandle
= hConsoleHandle
;
2313 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
2314 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
2316 SetLastErrorByStatus ( Status
);
2319 *lpMode
= Reply
.Data
.GetConsoleModeReply
.ConsoleMode
;
2324 /*--------------------------------------------------------------
2325 * GetNumberOfConsoleInputEvents
2331 GetNumberOfConsoleInputEvents(
2332 HANDLE hConsoleInput
,
2333 LPDWORD lpNumberOfEvents
2336 CSRSS_API_REQUEST Request
;
2337 CSRSS_API_REPLY Reply
;
2340 if(lpNumberOfEvents
== NULL
)
2342 SetLastError(ERROR_INVALID_PARAMETER
);
2346 Request
.Type
= CSRSS_GET_NUM_INPUT_EVENTS
;
2347 Request
.Data
.GetNumInputEventsRequest
.ConsoleHandle
= hConsoleInput
;
2348 Status
= CsrClientCallServer(&Request
, &Reply
, sizeof(CSRSS_API_REQUEST
), sizeof(CSRSS_API_REPLY
));
2349 if(!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
2351 SetLastErrorByStatus(Status
);
2355 *lpNumberOfEvents
= Reply
.Data
.GetNumInputEventsReply
.NumInputEvents
;
2361 /*--------------------------------------------------------------
2362 * GetLargestConsoleWindowSize
2368 GetLargestConsoleWindowSize(
2369 HANDLE hConsoleOutput
2373 COORD Coord
= {80,25};
2381 /*--------------------------------------------------------------
2382 * GetConsoleCursorInfo
2388 GetConsoleCursorInfo(
2389 HANDLE hConsoleOutput
,
2390 PCONSOLE_CURSOR_INFO lpConsoleCursorInfo
2393 CSRSS_API_REQUEST Request
;
2394 CSRSS_API_REPLY Reply
;
2397 Request
.Type
= CSRSS_GET_CURSOR_INFO
;
2398 Request
.Data
.GetCursorInfoRequest
.ConsoleHandle
= hConsoleOutput
;
2399 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
2401 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
2403 SetLastErrorByStatus ( Status
);
2406 *lpConsoleCursorInfo
= Reply
.Data
.GetCursorInfoReply
.Info
;
2411 /*--------------------------------------------------------------
2412 * GetNumberOfConsoleMouseButtons
2418 GetNumberOfConsoleMouseButtons(
2419 LPDWORD lpNumberOfMouseButtons
2427 /*--------------------------------------------------------------
2435 HANDLE hConsoleHandle
,
2439 CSRSS_API_REQUEST Request
;
2440 CSRSS_API_REPLY Reply
;
2443 Request
.Type
= CSRSS_SET_CONSOLE_MODE
;
2444 Request
.Data
.SetConsoleModeRequest
.ConsoleHandle
= hConsoleHandle
;
2445 Request
.Data
.SetConsoleModeRequest
.Mode
= dwMode
;
2446 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
2447 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
2449 SetLastErrorByStatus ( Status
);
2456 /*--------------------------------------------------------------
2457 * SetConsoleActiveScreenBuffer
2463 SetConsoleActiveScreenBuffer(
2464 HANDLE hConsoleOutput
2467 CSRSS_API_REQUEST Request
;
2468 CSRSS_API_REPLY Reply
;
2471 Request
.Type
= CSRSS_SET_SCREEN_BUFFER
;
2472 Request
.Data
.SetScreenBufferRequest
.OutputHandle
= hConsoleOutput
;
2473 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
2474 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
2476 SetLastErrorByStatus ( Status
);
2483 /*--------------------------------------------------------------
2484 * FlushConsoleInputBuffer
2490 FlushConsoleInputBuffer(
2491 HANDLE hConsoleInput
2494 CSRSS_API_REQUEST Request
;
2495 CSRSS_API_REPLY Reply
;
2498 Request
.Type
= CSRSS_FLUSH_INPUT_BUFFER
;
2499 Request
.Data
.FlushInputBufferRequest
.ConsoleInput
= hConsoleInput
;
2500 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
2501 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
2503 SetLastErrorByStatus ( Status
);
2510 /*--------------------------------------------------------------
2511 * SetConsoleScreenBufferSize
2517 SetConsoleScreenBufferSize(
2518 HANDLE hConsoleOutput
,
2523 DbgPrint("%s unimplemented\n", __FUNCTION__
);
2527 /*--------------------------------------------------------------
2528 * SetConsoleCursorInfo
2534 SetConsoleCursorInfo(
2535 HANDLE hConsoleOutput
,
2536 CONST CONSOLE_CURSOR_INFO
*lpConsoleCursorInfo
2539 CSRSS_API_REQUEST Request
;
2540 CSRSS_API_REPLY Reply
;
2543 Request
.Type
= CSRSS_SET_CURSOR_INFO
;
2544 Request
.Data
.SetCursorInfoRequest
.ConsoleHandle
= hConsoleOutput
;
2545 Request
.Data
.SetCursorInfoRequest
.Info
= *lpConsoleCursorInfo
;
2546 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
2548 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
2550 SetLastErrorByStatus ( Status
);
2557 /*--------------------------------------------------------------
2558 * ScrollConsoleScreenBufferA
2564 ScrollConsoleScreenBufferA(
2565 HANDLE hConsoleOutput
,
2566 CONST SMALL_RECT
*lpScrollRectangle
,
2567 CONST SMALL_RECT
*lpClipRectangle
,
2568 COORD dwDestinationOrigin
,
2569 CONST CHAR_INFO
*lpFill
2572 CSRSS_API_REQUEST Request
;
2573 CSRSS_API_REPLY Reply
;
2576 Request
.Type
= CSRSS_SCROLL_CONSOLE_SCREEN_BUFFER
;
2577 Request
.Data
.ScrollConsoleScreenBufferRequest
.ConsoleHandle
= hConsoleOutput
;
2578 Request
.Data
.ScrollConsoleScreenBufferRequest
.ScrollRectangle
= *lpScrollRectangle
;
2580 if (lpClipRectangle
!= NULL
)
2582 Request
.Data
.ScrollConsoleScreenBufferRequest
.UseClipRectangle
= TRUE
;
2583 Request
.Data
.ScrollConsoleScreenBufferRequest
.ClipRectangle
= *lpClipRectangle
;
2587 Request
.Data
.ScrollConsoleScreenBufferRequest
.UseClipRectangle
= FALSE
;
2590 Request
.Data
.ScrollConsoleScreenBufferRequest
.DestinationOrigin
= dwDestinationOrigin
;
2591 Request
.Data
.ScrollConsoleScreenBufferRequest
.Fill
= *lpFill
;
2592 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
2594 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
2596 SetLastErrorByStatus ( Status
);
2603 /*--------------------------------------------------------------
2604 * ScrollConsoleScreenBufferW
2610 ScrollConsoleScreenBufferW(
2611 HANDLE hConsoleOutput
,
2612 CONST SMALL_RECT
*lpScrollRectangle
,
2613 CONST SMALL_RECT
*lpClipRectangle
,
2614 COORD dwDestinationOrigin
,
2615 CONST CHAR_INFO
*lpFill
2619 DbgPrint("%s unimplemented\n", __FUNCTION__
);
2624 /*--------------------------------------------------------------
2625 * SetConsoleWindowInfo
2631 SetConsoleWindowInfo(
2632 HANDLE hConsoleOutput
,
2634 CONST SMALL_RECT
*lpConsoleWindow
2638 DbgPrint("%s unimplemented\n", __FUNCTION__
);
2643 /*--------------------------------------------------------------
2644 * SetConsoleTextAttribute
2650 SetConsoleTextAttribute(
2651 HANDLE hConsoleOutput
,
2655 CSRSS_API_REQUEST Request
;
2656 CSRSS_API_REPLY Reply
;
2659 Request
.Type
= CSRSS_SET_ATTRIB
;
2660 Request
.Data
.SetAttribRequest
.ConsoleHandle
= hConsoleOutput
;
2661 Request
.Data
.SetAttribRequest
.Attrib
= wAttributes
;
2662 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
2663 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
2665 SetLastErrorByStatus ( Status
);
2673 AddConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine
)
2675 if (HandlerRoutine
== NULL
)
2677 IgnoreCtrlEvents
= TRUE
;
2683 if (CtrlHandlers
== NULL
)
2685 CtrlHandlers
= RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY
,
2686 NrCtrlHandlers
* sizeof(PHANDLER_ROUTINE
));
2690 CtrlHandlers
= RtlReAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY
,
2691 (PVOID
)CtrlHandlers
,
2692 NrCtrlHandlers
* sizeof(PHANDLER_ROUTINE
));
2694 if (CtrlHandlers
== NULL
)
2697 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2700 CtrlHandlers
[NrCtrlHandlers
- 1] = HandlerRoutine
;
2707 RemoveConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine
)
2711 if (HandlerRoutine
== NULL
)
2713 IgnoreCtrlEvents
= FALSE
;
2718 for (i
= 0; i
< NrCtrlHandlers
; i
++)
2720 if ( ((void*)(CtrlHandlers
[i
])) == (void*)HandlerRoutine
)
2723 memmove(CtrlHandlers
+ i
, CtrlHandlers
+ i
+ 1,
2724 (NrCtrlHandlers
- i
) * sizeof(PHANDLER_ROUTINE
));
2726 RtlReAllocateHeap(RtlGetProcessHeap(),
2728 (PVOID
)CtrlHandlers
,
2729 NrCtrlHandlers
* sizeof(PHANDLER_ROUTINE
));
2742 SetConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine
,
2747 RtlEnterCriticalSection(&DllLock
);
2750 Ret
= AddConsoleCtrlHandler(HandlerRoutine
);
2754 Ret
= RemoveConsoleCtrlHandler(HandlerRoutine
);
2756 RtlLeaveCriticalSection(&DllLock
);
2761 /*--------------------------------------------------------------
2762 * GenerateConsoleCtrlEvent
2767 GenerateConsoleCtrlEvent(
2769 DWORD dwProcessGroupId
2777 /*--------------------------------------------------------------
2785 LPWSTR lpConsoleTitle
,
2789 CSRSS_API_REQUEST Request
;
2790 PCSRSS_API_REPLY Reply
;
2794 hConsole
= CreateFileW(L
"CONIN$", GENERIC_READ
, 0, NULL
, OPEN_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
2795 if (hConsole
== INVALID_HANDLE_VALUE
)
2800 Reply
= RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CSRSS_API_REPLY
) + CSRSS_MAX_TITLE_LENGTH
* sizeof(WCHAR
));
2803 CloseHandle(hConsole
);
2804 SetLastError(ERROR_OUTOFMEMORY
);
2808 Request
.Type
= CSRSS_GET_TITLE
;
2809 Request
.Data
.GetTitleRequest
.ConsoleHandle
= hConsole
;
2811 Status
= CsrClientCallServer(&Request
, Reply
, sizeof(CSRSS_API_REQUEST
), sizeof(CSRSS_API_REPLY
) + CSRSS_MAX_TITLE_LENGTH
* sizeof(WCHAR
));
2812 CloseHandle(hConsole
);
2813 if(!NT_SUCCESS(Status
) || !(NT_SUCCESS(Status
= Reply
->Status
)))
2815 SetLastErrorByStatus(Status
);
2816 RtlFreeHeap(GetProcessHeap(), 0, Reply
);
2820 if(nSize
* sizeof(WCHAR
) < Reply
->Data
.GetTitleReply
.Length
)
2822 wcsncpy(lpConsoleTitle
, Reply
->Data
.GetTitleReply
.Title
, nSize
- 1);
2823 lpConsoleTitle
[nSize
--] = L
'\0';
2827 nSize
= Reply
->Data
.GetTitleReply
.Length
/ sizeof (WCHAR
);
2828 wcscpy(lpConsoleTitle
, Reply
->Data
.GetTitleReply
.Title
);
2829 lpConsoleTitle
[nSize
] = L
'\0';
2832 RtlFreeHeap(GetProcessHeap(), 0, Reply
);
2837 /*--------------------------------------------------------------
2847 LPSTR lpConsoleTitle
,
2851 wchar_t WideTitle
[CSRSS_MAX_TITLE_LENGTH
];
2852 DWORD nWideTitle
= sizeof WideTitle
;
2855 if (!lpConsoleTitle
|| !nSize
) return 0;
2856 nWideTitle
= GetConsoleTitleW( (LPWSTR
) WideTitle
, nWideTitle
);
2857 if (!nWideTitle
) return 0;
2859 if ( (nWritten
= WideCharToMultiByte(
2860 CP_ACP
, // ANSI code page
2861 0, // performance and mapping flags
2862 (LPWSTR
) WideTitle
, // address of wide-character string
2863 nWideTitle
, // number of characters in string
2864 lpConsoleTitle
, // address of buffer for new string
2865 nSize
, // size of buffer
2870 lpConsoleTitle
[nWritten
] = '\0';
2878 /*--------------------------------------------------------------
2886 LPCWSTR lpConsoleTitle
2889 PCSRSS_API_REQUEST Request
;
2890 CSRSS_API_REPLY Reply
;
2895 hConsole
= CreateFileW(L
"CONIN$", GENERIC_WRITE
, 0, NULL
, OPEN_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
2896 if (hConsole
== INVALID_HANDLE_VALUE
)
2901 Request
= RtlAllocateHeap(GetProcessHeap(),
2903 sizeof(CSRSS_API_REQUEST
) + CSRSS_MAX_SET_TITLE_REQUEST
);
2904 if (Request
== NULL
)
2906 CloseHandle(hConsole
);
2907 SetLastError(ERROR_OUTOFMEMORY
);
2911 Request
->Type
= CSRSS_SET_TITLE
;
2912 Request
->Data
.SetTitleRequest
.Console
= hConsole
;
2914 for( c
= 0; lpConsoleTitle
[c
] && c
< CSRSS_MAX_TITLE_LENGTH
; c
++ )
2915 Request
->Data
.SetTitleRequest
.Title
[c
] = lpConsoleTitle
[c
];
2917 Request
->Data
.SetTitleRequest
.Title
[c
] = 0;
2918 Request
->Data
.SetTitleRequest
.Length
= c
;
2919 Status
= CsrClientCallServer(Request
,
2921 sizeof(CSRSS_API_REQUEST
) +
2923 sizeof(CSRSS_API_REPLY
));
2924 CloseHandle(hConsole
);
2925 if (!NT_SUCCESS(Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
2927 RtlFreeHeap( GetProcessHeap(), 0, Request
);
2928 SetLastErrorByStatus (Status
);
2931 RtlFreeHeap( GetProcessHeap(), 0, Request
);
2936 /*--------------------------------------------------------------
2946 LPCSTR lpConsoleTitle
2949 PCSRSS_API_REQUEST Request
;
2950 CSRSS_API_REPLY Reply
;
2955 hConsole
= CreateFileW(L
"CONIN$", GENERIC_WRITE
, 0, NULL
, OPEN_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
2956 if (hConsole
== INVALID_HANDLE_VALUE
)
2961 Request
= RtlAllocateHeap(GetProcessHeap(),
2963 sizeof(CSRSS_API_REQUEST
) + CSRSS_MAX_SET_TITLE_REQUEST
);
2964 if (Request
== NULL
)
2966 CloseHandle(hConsole
);
2967 SetLastError(ERROR_OUTOFMEMORY
);
2971 Request
->Type
= CSRSS_SET_TITLE
;
2972 Request
->Data
.SetTitleRequest
.Console
= hConsole
;
2974 for( c
= 0; lpConsoleTitle
[c
] && c
< CSRSS_MAX_TITLE_LENGTH
; c
++ )
2975 Request
->Data
.SetTitleRequest
.Title
[c
] = lpConsoleTitle
[c
];
2977 Request
->Data
.SetTitleRequest
.Title
[c
] = 0;
2978 Request
->Data
.SetTitleRequest
.Length
= c
;
2979 Status
= CsrClientCallServer(Request
,
2981 sizeof(CSRSS_API_REQUEST
) +
2983 sizeof(CSRSS_API_REPLY
));
2984 CloseHandle(hConsole
);
2985 if (!NT_SUCCESS(Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
2987 RtlFreeHeap( GetProcessHeap(), 0, Request
);
2988 SetLastErrorByStatus (Status
);
2991 RtlFreeHeap( GetProcessHeap(), 0, Request
);
2996 /*--------------------------------------------------------------
3004 HANDLE hConsoleInput
,
3006 DWORD nNumberOfCharsToRead
,
3007 LPDWORD lpNumberOfCharsRead
,
3012 DbgPrint("%s unimplemented\n", __FUNCTION__
);
3017 /*--------------------------------------------------------------
3025 HANDLE hConsoleOutput
,
3026 CONST VOID
*lpBuffer
,
3027 DWORD nNumberOfCharsToWrite
,
3028 LPDWORD lpNumberOfCharsWritten
,
3032 DbgPrint("%s unimplemented\n", __FUNCTION__
);
3034 PCSRSS_API_REQUEST Request
;
3035 CSRSS_API_REPLY Reply
;
3038 Request
= RtlAllocateHeap(GetProcessHeap(),
3040 sizeof(CSRSS_API_REQUEST
) + nNumberOfCharsToWrite
* sizeof(WCHAR
));
3041 if (Request
== NULL
)
3043 SetLastError(ERROR_OUTOFMEMORY
);
3047 Request
->Type
= CSRSS_WRITE_CONSOLE
;
3048 Request
->Data
.WriteConsoleRequest
.ConsoleHandle
= hConsoleOutput
;
3049 Request
->Data
.WriteConsoleRequest
.NrCharactersToWrite
=
3050 nNumberOfCharsToWrite
;
3051 // DbgPrint("nNumberOfCharsToWrite %d\n", nNumberOfCharsToWrite);
3052 // DbgPrint("Buffer %s\n", Request->Data.WriteConsoleRequest.Buffer);
3053 memcpy(Request
->Data
.WriteConsoleRequest
.Buffer
,
3055 nNumberOfCharsToWrite
* sizeof(WCHAR
));
3057 Status
= CsrClientCallServer(Request
,
3059 sizeof(CSRSS_API_REQUEST
) + nNumberOfCharsToWrite
,
3060 sizeof(CSRSS_API_REPLY
));
3062 RtlFreeHeap(GetProcessHeap(),
3066 if (!NT_SUCCESS(Status
))
3071 if (lpNumberOfCharsWritten
!= NULL
)
3073 *lpNumberOfCharsWritten
=
3074 Reply
.Data
.WriteConsoleReply
.NrCharactersWritten
;
3083 /*--------------------------------------------------------------
3084 * CreateConsoleScreenBuffer
3090 CreateConsoleScreenBuffer(
3091 DWORD dwDesiredAccess
,
3093 CONST SECURITY_ATTRIBUTES
*lpSecurityAttributes
,
3095 LPVOID lpScreenBufferData
3098 // FIXME: don't ignore access, share mode, and security
3099 CSRSS_API_REQUEST Request
;
3100 CSRSS_API_REPLY Reply
;
3103 Request
.Type
= CSRSS_CREATE_SCREEN_BUFFER
;
3104 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
3105 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
3107 SetLastErrorByStatus ( Status
);
3110 return Reply
.Data
.CreateScreenBufferReply
.OutputHandle
;
3114 /*--------------------------------------------------------------
3121 GetConsoleCP( VOID
)
3123 CSRSS_API_REQUEST Request
;
3124 CSRSS_API_REPLY Reply
;
3127 Request
.Type
= CSRSS_GET_CONSOLE_CP
;
3128 Status
= CsrClientCallServer(&Request
, &Reply
, sizeof(CSRSS_API_REQUEST
),
3129 sizeof(CSRSS_API_REPLY
));
3130 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
3132 SetLastErrorByStatus (Status
);
3135 return Reply
.Data
.GetConsoleCodePage
.CodePage
;
3139 /*--------------------------------------------------------------
3150 CSRSS_API_REQUEST Request
;
3151 CSRSS_API_REPLY Reply
;
3154 Request
.Type
= CSRSS_SET_CONSOLE_CP
;
3155 Request
.Data
.SetConsoleCodePage
.CodePage
= wCodePageID
;
3156 Status
= CsrClientCallServer(&Request
, &Reply
, sizeof(CSRSS_API_REQUEST
),
3157 sizeof(CSRSS_API_REPLY
));
3158 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
3160 SetLastErrorByStatus (Status
);
3162 return NT_SUCCESS(Status
);
3166 /*--------------------------------------------------------------
3167 * GetConsoleOutputCP
3173 GetConsoleOutputCP( VOID
)
3175 CSRSS_API_REQUEST Request
;
3176 CSRSS_API_REPLY Reply
;
3179 Request
.Type
= CSRSS_GET_CONSOLE_OUTPUT_CP
;
3180 Status
= CsrClientCallServer(&Request
, &Reply
, sizeof(CSRSS_API_REQUEST
),
3181 sizeof(CSRSS_API_REPLY
));
3182 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
3184 SetLastErrorByStatus (Status
);
3187 return Reply
.Data
.GetConsoleOutputCodePage
.CodePage
;
3191 /*--------------------------------------------------------------
3192 * SetConsoleOutputCP
3202 CSRSS_API_REQUEST Request
;
3203 CSRSS_API_REPLY Reply
;
3206 Request
.Type
= CSRSS_SET_CONSOLE_OUTPUT_CP
;
3207 Request
.Data
.SetConsoleOutputCodePage
.CodePage
= wCodePageID
;
3208 Status
= CsrClientCallServer(&Request
, &Reply
, sizeof(CSRSS_API_REQUEST
),
3209 sizeof(CSRSS_API_REPLY
));
3210 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
3212 SetLastErrorByStatus (Status
);
3214 return NT_SUCCESS(Status
);
3218 /*--------------------------------------------------------------
3219 * GetConsoleProcessList
3224 GetConsoleProcessList(LPDWORD lpdwProcessList
,
3225 DWORD dwProcessCount
)
3227 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3233 /*--------------------------------------------------------------
3234 * GetConsoleSelectionInfo
3239 GetConsoleSelectionInfo(PCONSOLE_SELECTION_INFO lpConsoleSelectionInfo
)
3241 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3247 /*--------------------------------------------------------------
3253 AttachConsole(DWORD dwProcessId
)
3255 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3259 /*--------------------------------------------------------------
3265 GetConsoleWindow (VOID
)
3267 CSRSS_API_REQUEST Request
;
3268 CSRSS_API_REPLY Reply
;
3271 Request
.Type
= CSRSS_GET_CONSOLE_WINDOW
;
3272 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
3273 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
3275 SetLastErrorByStatus (Status
);
3278 return Reply
.Data
.GetConsoleWindowReply
.WindowHandle
;
3282 /*--------------------------------------------------------------
3287 BOOL STDCALL
SetConsoleIcon(HICON hicon
)
3289 CSRSS_API_REQUEST Request
;
3290 CSRSS_API_REPLY Reply
;
3293 Request
.Type
= CSRSS_SET_CONSOLE_ICON
;
3294 Request
.Data
.SetConsoleIconRequest
.WindowIcon
= hicon
;
3295 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
3296 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
3298 SetLastErrorByStatus (Status
);
3301 return NT_SUCCESS(Status
);