1 /* $Id: console.c,v 1.42 2002/09/07 15:12:27 chorns 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
10 * 19990204 EA SetConsoleTitleA
14 /* INCLUDES ******************************************************************/
17 #define NTOS_USER_MODE
21 #include <csrss/csrss.h>
24 #include <kernel32/kernel32.h>
25 #include <kernel32/error.h>
27 /* GLOBALS *******************************************************************/
29 static BOOL IgnoreCtrlEvents
= FALSE
;
30 static ULONG NrCtrlHandlers
= 0;
31 static PHANDLER_ROUTINE
* CtrlHandlers
= NULL
;
33 /* FUNCTIONS *****************************************************************/
36 AddConsoleAliasA (DWORD a0
,
43 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
48 AddConsoleAliasW (DWORD a0
,
55 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
60 ConsoleMenuControl (HANDLE hConsole
,
67 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
72 DuplicateConsoleHandle (HANDLE hConsole
,
80 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
85 ExpungeConsoleCommandHistoryW (DWORD Unknown0
)
90 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
96 ExpungeConsoleCommandHistoryA (DWORD Unknown0
)
101 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
106 GetConsoleAliasW (DWORD Unknown0
,
114 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
120 GetConsoleAliasA (DWORD Unknown0
,
128 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
133 GetConsoleAliasExesW (DWORD Unknown0
,
139 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
146 GetConsoleAliasExesA (DWORD Unknown0
,
152 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
159 GetConsoleAliasExesLengthA (VOID
)
164 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
169 GetConsoleAliasExesLengthW (VOID
)
174 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
179 GetConsoleAliasesW (DWORD Unknown0
,
186 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
191 GetConsoleAliasesA (DWORD Unknown0
,
198 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
203 GetConsoleAliasesLengthW (DWORD Unknown0
)
208 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
213 GetConsoleAliasesLengthA (DWORD Unknown0
)
218 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
223 GetConsoleCommandHistoryW (DWORD Unknown0
,
230 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
235 GetConsoleCommandHistoryA (DWORD Unknown0
,
242 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
247 GetConsoleCommandHistoryLengthW (DWORD Unknown0
)
252 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
257 GetConsoleCommandHistoryLengthA (DWORD Unknown0
)
262 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
267 GetConsoleDisplayMode (LPDWORD lpdwMode
)
269 * FUNCTION: Get the console display mode
271 * lpdwMode - Address of variable that receives the current value
273 * STATUS: Undocumented
276 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
281 GetConsoleFontInfo (DWORD Unknown0
,
289 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
294 GetConsoleFontSize(HANDLE hConsoleOutput
,
297 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
302 GetConsoleHardwareState (DWORD Unknown0
,
309 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
314 GetConsoleInputWaitHandle (VOID
)
319 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
324 GetCurrentConsoleFont(HANDLE hConsoleOutput
,
326 PCONSOLE_FONT_INFO lpConsoleCurrentFont
)
328 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
333 GetNumberOfConsoleFonts (VOID
)
338 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
339 return 1; /* FIXME: call csrss.exe */
343 InvalidateConsoleDIBits (DWORD Unknown0
,
349 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
354 OpenConsoleW (DWORD Unknown0
,
362 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
367 SetConsoleCommandHistoryMode (DWORD dwMode
)
372 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
377 SetConsoleCursor (DWORD Unknown0
,
383 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
388 SetConsoleDisplayMode (HANDLE hOut
,
392 * FUNCTION: Set the console display mode.
394 * hOut - Standard output handle.
395 * dwNewMode - New mode.
396 * lpdwOldMode - Address of a variable that receives the old mode.
399 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
404 SetConsoleFont (DWORD Unknown0
,
410 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
415 SetConsoleHardwareState (DWORD Unknown0
,
422 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
427 SetConsoleKeyShortcuts (DWORD Unknown0
,
435 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
440 SetConsoleMaximumWindowSize (DWORD Unknown0
,
446 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
451 SetConsoleMenuClose (DWORD Unknown0
)
456 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
461 SetConsoleNumberOfCommandsA (DWORD Unknown0
,
467 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
472 SetConsoleNumberOfCommandsW (DWORD Unknown0
,
478 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
483 SetConsolePalette (DWORD Unknown0
,
490 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
495 SetLastConsoleEventActive (VOID
)
500 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
505 ShowConsoleCursor (DWORD Unknown0
,
511 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
516 VerifyConsoleIoHandle (DWORD Unknown0
)
521 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
526 WriteConsoleInputVDMA (DWORD Unknown0
,
531 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
536 WriteConsoleInputVDMW (DWORD Unknown0
,
541 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
546 CloseConsoleHandle(HANDLE Handle
)
551 if (IsConsoleHandle (Handle
) == FALSE
)
553 SetLastError (ERROR_INVALID_PARAMETER
);
556 /* FIXME: call CSRSS */
557 return TRUE
/*FALSE*/;
561 IsConsoleHandle(HANDLE Handle
)
563 if ((((ULONG
)Handle
) & 0x10000003) == 0x3)
571 GetStdHandle(DWORD nStdHandle
)
573 * FUNCTION: Get a handle for the standard input, standard output
574 * and a standard error device.
576 * nStdHandle - Specifies the device for which to return the handle.
577 * RETURNS: If the function succeeds, the return value is the handle
578 * of the specified device. Otherwise the value is INVALID_HANDLE_VALUE.
581 PRTL_ROS_USER_PROCESS_PARAMETERS Ppb
;
583 Ppb
= NtCurrentPeb()->ProcessParameters
;
586 case STD_INPUT_HANDLE
: return Ppb
->InputHandle
;
587 case STD_OUTPUT_HANDLE
: return Ppb
->OutputHandle
;
588 case STD_ERROR_HANDLE
: return Ppb
->ErrorHandle
;
590 SetLastError (ERROR_INVALID_PARAMETER
);
591 return INVALID_HANDLE_VALUE
;
594 WINBASEAPI BOOL WINAPI
595 SetStdHandle(DWORD nStdHandle
,
598 * FUNCTION: Set the handle for the standard input, standard output or
599 * the standard error device.
601 * nStdHandle - Specifies the handle to be set.
602 * hHandle - The handle to set.
603 * RETURNS: TRUE if the function succeeds, FALSE otherwise.
606 PRTL_ROS_USER_PROCESS_PARAMETERS Ppb
;
608 Ppb
= NtCurrentPeb()->ProcessParameters
;
610 /* More checking needed? */
611 if (hHandle
== INVALID_HANDLE_VALUE
)
613 SetLastError (ERROR_INVALID_HANDLE
);
617 SetLastError(ERROR_SUCCESS
); /* OK */
620 case STD_INPUT_HANDLE
:
621 Ppb
->InputHandle
= hHandle
;
623 case STD_OUTPUT_HANDLE
:
624 Ppb
->OutputHandle
= hHandle
;
626 case STD_ERROR_HANDLE
:
627 Ppb
->ErrorHandle
= hHandle
;
630 SetLastError (ERROR_INVALID_PARAMETER
);
635 /*--------------------------------------------------------------
639 WriteConsoleA(HANDLE hConsoleOutput
,
640 CONST VOID
*lpBuffer
,
641 DWORD nNumberOfCharsToWrite
,
642 LPDWORD lpNumberOfCharsWritten
,
645 PCSRSS_API_REQUEST Request
;
646 CSRSS_API_REPLY Reply
;
651 Request
= RtlAllocateHeap(GetProcessHeap(),
653 sizeof(CSRSS_API_REQUEST
) +
654 CSRSS_MAX_WRITE_CONSOLE_REQUEST
);
657 SetLastError(ERROR_OUTOFMEMORY
);
661 Request
->Type
= CSRSS_WRITE_CONSOLE
;
662 Request
->Data
.WriteConsoleRequest
.ConsoleHandle
= hConsoleOutput
;
663 if (lpNumberOfCharsWritten
!= NULL
)
664 *lpNumberOfCharsWritten
= nNumberOfCharsToWrite
;
665 while (nNumberOfCharsToWrite
)
667 if (nNumberOfCharsToWrite
> CSRSS_MAX_WRITE_CONSOLE_REQUEST
)
669 Size
= CSRSS_MAX_WRITE_CONSOLE_REQUEST
;
673 Size
= nNumberOfCharsToWrite
;
675 Request
->Data
.WriteConsoleRequest
.NrCharactersToWrite
= Size
;
677 memcpy(Request
->Data
.WriteConsoleRequest
.Buffer
, lpBuffer
, Size
);
679 MessageSize
= CSRSS_REQUEST_HEADER_SIZE
+
680 sizeof(CSRSS_WRITE_CONSOLE_REQUEST
) + Size
;
681 Status
= CsrClientCallServer(Request
,
684 sizeof(CSRSS_API_REPLY
));
686 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
688 RtlFreeHeap(GetProcessHeap(), 0, Request
);
689 SetLastErrorByStatus(Status
);
692 nNumberOfCharsToWrite
-= Size
;
695 RtlFreeHeap(GetProcessHeap(), 0, Request
);
700 /*--------------------------------------------------------------
703 WINBOOL STDCALL
ReadConsoleA(HANDLE hConsoleInput
,
705 DWORD nNumberOfCharsToRead
,
706 LPDWORD lpNumberOfCharsRead
,
709 CSRSS_API_REQUEST Request
;
710 PCSRSS_API_REPLY Reply
;
714 Reply
= RtlAllocateHeap(GetProcessHeap(),
716 sizeof(CSRSS_API_REPLY
) + nNumberOfCharsToRead
);
719 SetLastError(ERROR_OUTOFMEMORY
);
723 Request
.Type
= CSRSS_READ_CONSOLE
;
724 Request
.Data
.ReadConsoleRequest
.ConsoleHandle
= hConsoleInput
;
725 Request
.Data
.ReadConsoleRequest
.NrCharactersToRead
= nNumberOfCharsToRead
> CSRSS_MAX_READ_CONSOLE_REQUEST
? CSRSS_MAX_READ_CONSOLE_REQUEST
: nNumberOfCharsToRead
;
726 Request
.Data
.ReadConsoleRequest
.nCharsCanBeDeleted
= 0;
727 Status
= CsrClientCallServer(&Request
,
729 sizeof(CSRSS_API_REQUEST
),
730 sizeof(CSRSS_API_REPLY
) +
731 Request
.Data
.ReadConsoleRequest
.NrCharactersToRead
);
732 if (!NT_SUCCESS(Status
) || !NT_SUCCESS( Status
= Reply
->Status
))
734 DbgPrint( "CSR returned error in ReadConsole\n" );
735 SetLastErrorByStatus ( Status
);
736 RtlFreeHeap( GetProcessHeap(), 0, Reply
);
739 if( Reply
->Status
== STATUS_NOTIFY_CLEANUP
)
740 Reply
->Status
= STATUS_PENDING
; // ignore backspace because we have no chars to backspace
741 /* There may not be any chars or lines to read yet, so wait */
742 while( Reply
->Status
== STATUS_PENDING
)
744 /* some chars may have been returned, but not a whole line yet, so recompute buffer and try again */
745 nNumberOfCharsToRead
-= Reply
->Data
.ReadConsoleReply
.NrCharactersRead
;
746 /* don't overflow caller's buffer, even if you still don't have a complete line */
747 if( !nNumberOfCharsToRead
)
749 Request
.Data
.ReadConsoleRequest
.NrCharactersToRead
= nNumberOfCharsToRead
> CSRSS_MAX_READ_CONSOLE_REQUEST
? CSRSS_MAX_READ_CONSOLE_REQUEST
: nNumberOfCharsToRead
;
750 /* copy any chars already read to buffer */
751 memcpy( lpBuffer
+ CharsRead
, Reply
->Data
.ReadConsoleReply
.Buffer
, Reply
->Data
.ReadConsoleReply
.NrCharactersRead
);
752 CharsRead
+= Reply
->Data
.ReadConsoleReply
.NrCharactersRead
;
753 /* wait for csrss to signal there is more data to read, but not if we got STATUS_NOTIFY_CLEANUP for backspace */
754 Status
= NtWaitForSingleObject( Reply
->Data
.ReadConsoleReply
.EventHandle
, FALSE
, 0 );
755 if( !NT_SUCCESS( Status
) )
757 DbgPrint( "Wait for console input failed!\n" );
758 RtlFreeHeap( GetProcessHeap(), 0, Reply
);
761 Request
.Data
.ReadConsoleRequest
.nCharsCanBeDeleted
= CharsRead
;
762 Status
= CsrClientCallServer( &Request
, Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) + Request
.Data
.ReadConsoleRequest
.NrCharactersToRead
);
763 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
->Status
) )
765 SetLastErrorByStatus ( Status
);
766 RtlFreeHeap( GetProcessHeap(), 0, Reply
);
769 if( Reply
->Status
== STATUS_NOTIFY_CLEANUP
)
775 nNumberOfCharsToRead
++;
777 Reply
->Status
= STATUS_PENDING
; // retry
780 /* copy data to buffer, count total returned, and return */
781 memcpy( lpBuffer
+ CharsRead
, Reply
->Data
.ReadConsoleReply
.Buffer
, Reply
->Data
.ReadConsoleReply
.NrCharactersRead
);
782 CharsRead
+= Reply
->Data
.ReadConsoleReply
.NrCharactersRead
;
783 if (lpNumberOfCharsRead
!= NULL
)
784 *lpNumberOfCharsRead
= CharsRead
;
785 RtlFreeHeap(GetProcessHeap(),
793 /*--------------------------------------------------------------
796 WINBOOL STDCALL
AllocConsole(VOID
)
798 CSRSS_API_REQUEST Request
;
799 CSRSS_API_REPLY Reply
;
802 Request
.Type
= CSRSS_ALLOC_CONSOLE
;
803 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
804 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
806 SetLastErrorByStatus ( Status
);
809 SetStdHandle( STD_INPUT_HANDLE
, Reply
.Data
.AllocConsoleReply
.InputHandle
);
810 SetStdHandle( STD_OUTPUT_HANDLE
, Reply
.Data
.AllocConsoleReply
.OutputHandle
);
811 SetStdHandle( STD_ERROR_HANDLE
, Reply
.Data
.AllocConsoleReply
.OutputHandle
);
816 /*--------------------------------------------------------------
819 WINBOOL STDCALL
FreeConsole(VOID
)
821 DbgPrint("FreeConsole() is unimplemented\n");
826 /*--------------------------------------------------------------
827 * GetConsoleScreenBufferInfo
831 GetConsoleScreenBufferInfo(
832 HANDLE hConsoleOutput
,
833 PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo
836 CSRSS_API_REQUEST Request
;
837 CSRSS_API_REPLY Reply
;
840 Request
.Type
= CSRSS_SCREEN_BUFFER_INFO
;
841 Request
.Data
.ScreenBufferInfoRequest
.ConsoleHandle
= hConsoleOutput
;
842 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
843 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
845 SetLastErrorByStatus ( Status
);
848 *lpConsoleScreenBufferInfo
= Reply
.Data
.ScreenBufferInfoReply
.Info
;
853 /*--------------------------------------------------------------
854 * SetConsoleCursorPosition
858 SetConsoleCursorPosition(
859 HANDLE hConsoleOutput
,
860 COORD dwCursorPosition
863 CSRSS_API_REQUEST Request
;
864 CSRSS_API_REPLY Reply
;
867 Request
.Type
= CSRSS_SET_CURSOR
;
868 Request
.Data
.SetCursorRequest
.ConsoleHandle
= hConsoleOutput
;
869 Request
.Data
.SetCursorRequest
.Position
= dwCursorPosition
;
870 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
871 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
873 SetLastErrorByStatus ( Status
);
880 /*--------------------------------------------------------------
881 * FillConsoleOutputCharacterA
884 FillConsoleOutputCharacterA(
885 HANDLE hConsoleOutput
,
889 LPDWORD lpNumberOfCharsWritten
892 CSRSS_API_REQUEST Request
;
893 CSRSS_API_REPLY Reply
;
896 Request
.Type
= CSRSS_FILL_OUTPUT
;
897 Request
.Data
.FillOutputRequest
.ConsoleHandle
= hConsoleOutput
;
898 Request
.Data
.FillOutputRequest
.Char
= cCharacter
;
899 Request
.Data
.FillOutputRequest
.Position
= dwWriteCoord
;
900 Request
.Data
.FillOutputRequest
.Length
= nLength
;
901 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
902 if ( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
904 SetLastErrorByStatus(Status
);
907 if (lpNumberOfCharsWritten
!= NULL
)
908 *lpNumberOfCharsWritten
= nLength
;
913 /*--------------------------------------------------------------
914 * FillConsoleOutputCharacterW
918 FillConsoleOutputCharacterW(
919 HANDLE hConsoleOutput
,
923 LPDWORD lpNumberOfCharsWritten
931 /*--------------------------------------------------------------
938 HANDLE hConsoleInput
,
939 PINPUT_RECORD lpBuffer
,
941 LPDWORD lpNumberOfEventsRead
949 /*--------------------------------------------------------------
956 HANDLE hConsoleInput
,
957 PINPUT_RECORD lpBuffer
,
959 LPDWORD lpNumberOfEventsRead
967 /*--------------------------------------------------------------
970 WINBASEAPI BOOL WINAPI
971 ReadConsoleInputA(HANDLE hConsoleInput
,
972 PINPUT_RECORD lpBuffer
,
974 LPDWORD lpNumberOfEventsRead
)
976 CSRSS_API_REQUEST Request
;
977 CSRSS_API_REPLY Reply
;
981 Request
.Type
= CSRSS_READ_INPUT
;
982 Request
.Data
.ReadInputRequest
.ConsoleHandle
= hConsoleInput
;
983 Status
= CsrClientCallServer(&Request
, &Reply
, sizeof(CSRSS_API_REQUEST
),
984 sizeof(CSRSS_API_REPLY
));
985 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
987 SetLastErrorByStatus(Status
);
991 while (Status
== STATUS_PENDING
)
993 Status
= NtWaitForSingleObject(Reply
.Data
.ReadInputReply
.Event
, FALSE
,
995 if(!NT_SUCCESS(Status
))
997 SetLastErrorByStatus(Status
);
1001 Request
.Type
= CSRSS_READ_INPUT
;
1002 Request
.Data
.ReadInputRequest
.ConsoleHandle
= hConsoleInput
;
1003 Status
= CsrClientCallServer(&Request
, &Reply
, sizeof(CSRSS_API_REQUEST
),
1004 sizeof(CSRSS_API_REPLY
));
1005 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
1007 SetLastErrorByStatus(Status
);
1013 *lpBuffer
= Reply
.Data
.ReadInputReply
.Input
;
1017 while ((NumEventsRead
< nLength
) && (Reply
.Data
.ReadInputReply
.MoreEvents
))
1019 Status
= CsrClientCallServer(&Request
, &Reply
, sizeof(CSRSS_API_REQUEST
),
1020 sizeof(CSRSS_API_REPLY
));
1021 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
1023 SetLastErrorByStatus(Status
);
1027 if (Status
== STATUS_PENDING
)
1032 *lpBuffer
= Reply
.Data
.ReadInputReply
.Input
;
1037 *lpNumberOfEventsRead
= NumEventsRead
;
1043 /*--------------------------------------------------------------
1050 HANDLE hConsoleInput
,
1051 PINPUT_RECORD lpBuffer
,
1053 LPDWORD lpNumberOfEventsRead
1061 /*--------------------------------------------------------------
1062 * WriteConsoleInputA
1068 HANDLE hConsoleInput
,
1069 CONST INPUT_RECORD
*lpBuffer
,
1071 LPDWORD lpNumberOfEventsWritten
1079 /*--------------------------------------------------------------
1080 * WriteConsoleInputW
1086 HANDLE hConsoleInput
,
1087 CONST INPUT_RECORD
*lpBuffer
,
1089 LPDWORD lpNumberOfEventsWritten
1097 /*--------------------------------------------------------------
1098 * ReadConsoleOutputA
1104 HANDLE hConsoleOutput
,
1105 PCHAR_INFO lpBuffer
,
1107 COORD dwBufferCoord
,
1108 PSMALL_RECT lpReadRegion
1116 /*--------------------------------------------------------------
1117 * ReadConsoleOutputW
1123 HANDLE hConsoleOutput
,
1124 PCHAR_INFO lpBuffer
,
1126 COORD dwBufferCoord
,
1127 PSMALL_RECT lpReadRegion
1134 /*--------------------------------------------------------------
1135 * WriteConsoleOutputA
1137 WINBASEAPI BOOL WINAPI
1138 WriteConsoleOutputA(HANDLE hConsoleOutput
,
1139 CONST CHAR_INFO
*lpBuffer
,
1141 COORD dwBufferCoord
,
1142 PSMALL_RECT lpWriteRegion
)
1144 PCSRSS_API_REQUEST Request
;
1145 CSRSS_API_REPLY Reply
;
1151 PVOID BufferTargetBase
;
1153 Size
= dwBufferSize
.Y
* dwBufferSize
.X
* sizeof(CHAR_INFO
);
1155 Status
= CsrCaptureParameterBuffer((PVOID
)lpBuffer
,
1159 if (!NT_SUCCESS(Status
))
1161 SetLastErrorByStatus(Status
);
1165 Request
= RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY
,
1166 sizeof(CSRSS_API_REQUEST
));
1167 if (Request
== NULL
)
1169 SetLastError(ERROR_OUTOFMEMORY
);
1172 Request
->Type
= CSRSS_WRITE_CONSOLE_OUTPUT
;
1173 Request
->Data
.WriteConsoleOutputRequest
.ConsoleHandle
= hConsoleOutput
;
1174 Request
->Data
.WriteConsoleOutputRequest
.BufferSize
= dwBufferSize
;
1175 Request
->Data
.WriteConsoleOutputRequest
.BufferCoord
= dwBufferCoord
;
1176 Request
->Data
.WriteConsoleOutputRequest
.WriteRegion
= *lpWriteRegion
;
1177 Request
->Data
.WriteConsoleOutputRequest
.CharInfo
=
1178 (CHAR_INFO
*)BufferTargetBase
;
1180 Status
= CsrClientCallServer(Request
, &Reply
,
1181 sizeof(CSRSS_API_REQUEST
),
1182 sizeof(CSRSS_API_REPLY
));
1183 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
1185 RtlFreeHeap(GetProcessHeap(), 0, Request
);
1186 SetLastErrorByStatus(Status
);
1190 *lpWriteRegion
= Reply
.Data
.WriteConsoleOutputReply
.WriteRegion
;
1191 RtlFreeHeap(GetProcessHeap(), 0, Request
);
1192 CsrReleaseParameterBuffer(BufferBase
);
1197 /*--------------------------------------------------------------
1198 * WriteConsoleOutputW
1203 WriteConsoleOutputW(
1204 HANDLE hConsoleOutput
,
1205 CONST CHAR_INFO
*lpBuffer
,
1207 COORD dwBufferCoord
,
1208 PSMALL_RECT lpWriteRegion
1216 /*--------------------------------------------------------------
1217 * ReadConsoleOutputCharacterA
1222 ReadConsoleOutputCharacterA(
1223 HANDLE hConsoleOutput
,
1227 LPDWORD lpNumberOfCharsRead
1230 CSRSS_API_REQUEST Request
;
1231 PCSRSS_API_REPLY Reply
;
1235 Reply
= RtlAllocateHeap(GetProcessHeap(),
1237 sizeof(CSRSS_API_REPLY
) + CSRSS_MAX_READ_CONSOLE_OUTPUT_CHAR
);
1240 SetLastError(ERROR_OUTOFMEMORY
);
1244 if (lpNumberOfCharsRead
!= NULL
)
1245 *lpNumberOfCharsRead
= Size
;
1247 Request
.Type
= CSRSS_READ_CONSOLE_OUTPUT_CHAR
;
1248 Request
.Data
.ReadConsoleOutputCharRequest
.ConsoleHandle
= hConsoleOutput
;
1249 Request
.Data
.ReadConsoleOutputCharRequest
.ReadCoord
= dwReadCoord
;
1251 while (nLength
!= 0)
1253 if (nLength
> CSRSS_MAX_READ_CONSOLE_OUTPUT_CHAR
)
1254 Size
= CSRSS_MAX_READ_CONSOLE_OUTPUT_CHAR
;
1258 Request
.Data
.ReadConsoleOutputCharRequest
.NumCharsToRead
= Size
;
1260 Status
= CsrClientCallServer(&Request
,
1262 sizeof(CSRSS_API_REQUEST
),
1263 sizeof(CSRSS_API_REPLY
) + Size
);
1264 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Reply
->Status
))
1266 RtlFreeHeap(GetProcessHeap(), 0, Reply
);
1267 SetLastErrorByStatus(Status
);
1271 memcpy(lpCharacter
, &Reply
->Data
.ReadConsoleOutputCharReply
.String
[0], Size
);
1272 lpCharacter
+= Size
;
1274 Request
.Data
.ReadConsoleOutputCharRequest
.ReadCoord
= Reply
->Data
.ReadConsoleOutputCharReply
.EndCoord
;
1277 RtlFreeHeap(GetProcessHeap(), 0, Reply
);
1283 /*--------------------------------------------------------------
1284 * ReadConsoleOutputCharacterW
1289 ReadConsoleOutputCharacterW(
1290 HANDLE hConsoleOutput
,
1294 LPDWORD lpNumberOfCharsRead
1302 /*--------------------------------------------------------------
1303 * ReadConsoleOutputAttribute
1308 ReadConsoleOutputAttribute(
1309 HANDLE hConsoleOutput
,
1313 LPDWORD lpNumberOfAttrsRead
1316 SetLastError( ERROR_CALL_NOT_IMPLEMENTED
);
1321 /*--------------------------------------------------------------
1322 * WriteConsoleOutputCharacterA
1324 WINBASEAPI BOOL WINAPI
1325 WriteConsoleOutputCharacterA(HANDLE hConsoleOutput
,
1329 LPDWORD lpNumberOfCharsWritten
)
1331 PCSRSS_API_REQUEST Request
;
1332 CSRSS_API_REPLY Reply
;
1336 Request
= RtlAllocateHeap(GetProcessHeap(),
1338 sizeof(CSRSS_API_REQUEST
) + CSRSS_MAX_WRITE_CONSOLE_OUTPUT_CHAR
);
1341 SetLastError( ERROR_OUTOFMEMORY
);
1344 Request
->Type
= CSRSS_WRITE_CONSOLE_OUTPUT_CHAR
;
1345 Request
->Data
.WriteConsoleOutputCharRequest
.ConsoleHandle
= hConsoleOutput
;
1346 Request
->Data
.WriteConsoleOutputCharRequest
.Coord
= dwWriteCoord
;
1347 if( lpNumberOfCharsWritten
)
1348 *lpNumberOfCharsWritten
= nLength
;
1351 Size
= nLength
> CSRSS_MAX_WRITE_CONSOLE_OUTPUT_CHAR
? CSRSS_MAX_WRITE_CONSOLE_OUTPUT_CHAR
: nLength
;
1352 Request
->Data
.WriteConsoleOutputCharRequest
.Length
= Size
;
1353 memcpy( &Request
->Data
.WriteConsoleOutputCharRequest
.String
[0],
1356 Status
= CsrClientCallServer( Request
, &Reply
, sizeof( CSRSS_API_REQUEST
) + Size
, sizeof( CSRSS_API_REPLY
) );
1357 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
1359 RtlFreeHeap( GetProcessHeap(), 0, Request
);
1360 SetLastErrorByStatus ( Status
);
1364 lpCharacter
+= Size
;
1365 Request
->Data
.WriteConsoleOutputCharRequest
.Coord
= Reply
.Data
.WriteConsoleOutputCharReply
.EndCoord
;
1371 /*--------------------------------------------------------------
1372 * WriteConsoleOutputCharacterW
1377 WriteConsoleOutputCharacterW(
1378 HANDLE hConsoleOutput
,
1379 LPCWSTR lpCharacter
,
1382 LPDWORD lpNumberOfCharsWritten
1391 /*--------------------------------------------------------------
1392 * WriteConsoleOutputAttribute
1397 WriteConsoleOutputAttribute(
1398 HANDLE hConsoleOutput
,
1399 CONST WORD
*lpAttribute
,
1402 LPDWORD lpNumberOfAttrsWritten
1405 PCSRSS_API_REQUEST Request
;
1406 CSRSS_API_REPLY Reply
;
1411 Request
= RtlAllocateHeap(GetProcessHeap(),
1413 sizeof(CSRSS_API_REQUEST
) + CSRSS_MAX_WRITE_CONSOLE_OUTPUT_ATTRIB
);
1416 SetLastError( ERROR_OUTOFMEMORY
);
1419 Request
->Type
= CSRSS_WRITE_CONSOLE_OUTPUT_ATTRIB
;
1420 Request
->Data
.WriteConsoleOutputAttribRequest
.ConsoleHandle
= hConsoleOutput
;
1421 Request
->Data
.WriteConsoleOutputAttribRequest
.Coord
= dwWriteCoord
;
1422 if( lpNumberOfAttrsWritten
)
1423 *lpNumberOfAttrsWritten
= nLength
;
1426 Size
= nLength
> CSRSS_MAX_WRITE_CONSOLE_OUTPUT_ATTRIB
? CSRSS_MAX_WRITE_CONSOLE_OUTPUT_ATTRIB
: nLength
;
1427 Request
->Data
.WriteConsoleOutputAttribRequest
.Length
= Size
;
1428 for( c
= 0; c
< ( Size
* 2 ); c
++ )
1429 Request
->Data
.WriteConsoleOutputAttribRequest
.String
[c
] = (char)lpAttribute
[c
];
1430 Status
= CsrClientCallServer( Request
, &Reply
, sizeof( CSRSS_API_REQUEST
) + (Size
* 2), sizeof( CSRSS_API_REPLY
) );
1431 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
1433 RtlFreeHeap( GetProcessHeap(), 0, Request
);
1434 SetLastErrorByStatus ( Status
);
1438 lpAttribute
+= Size
;
1439 Request
->Data
.WriteConsoleOutputAttribRequest
.Coord
= Reply
.Data
.WriteConsoleOutputAttribReply
.EndCoord
;
1445 /*--------------------------------------------------------------
1446 * FillConsoleOutputAttribute
1451 FillConsoleOutputAttribute(
1452 HANDLE hConsoleOutput
,
1456 LPDWORD lpNumberOfAttrsWritten
1459 CSRSS_API_REQUEST Request
;
1460 CSRSS_API_REPLY Reply
;
1463 Request
.Type
= CSRSS_FILL_OUTPUT_ATTRIB
;
1464 Request
.Data
.FillOutputAttribRequest
.ConsoleHandle
= hConsoleOutput
;
1465 Request
.Data
.FillOutputAttribRequest
.Attribute
= wAttribute
;
1466 Request
.Data
.FillOutputAttribRequest
.Coord
= dwWriteCoord
;
1467 Request
.Data
.FillOutputAttribRequest
.Length
= nLength
;
1468 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
1469 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
1471 SetLastErrorByStatus ( Status
);
1474 if( lpNumberOfAttrsWritten
)
1475 *lpNumberOfAttrsWritten
= nLength
;
1480 /*--------------------------------------------------------------
1487 HANDLE hConsoleHandle
,
1491 CSRSS_API_REQUEST Request
;
1492 CSRSS_API_REPLY Reply
;
1495 Request
.Type
= CSRSS_GET_MODE
;
1496 Request
.Data
.GetConsoleModeRequest
.ConsoleHandle
= hConsoleHandle
;
1497 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
1498 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
1500 SetLastErrorByStatus ( Status
);
1503 *lpMode
= Reply
.Data
.GetConsoleModeReply
.ConsoleMode
;
1508 /*--------------------------------------------------------------
1509 * GetNumberOfConsoleInputEvents
1514 GetNumberOfConsoleInputEvents(
1515 HANDLE hConsoleInput
,
1516 LPDWORD lpNumberOfEvents
1524 /*--------------------------------------------------------------
1525 * GetLargestConsoleWindowSize
1530 GetLargestConsoleWindowSize(
1531 HANDLE hConsoleOutput
1535 COORD Coord
= {80,25};
1543 /*--------------------------------------------------------------
1544 * GetConsoleCursorInfo
1549 GetConsoleCursorInfo(
1550 HANDLE hConsoleOutput
,
1551 PCONSOLE_CURSOR_INFO lpConsoleCursorInfo
1554 CSRSS_API_REQUEST Request
;
1555 CSRSS_API_REPLY Reply
;
1558 Request
.Type
= CSRSS_GET_CURSOR_INFO
;
1559 Request
.Data
.GetCursorInfoRequest
.ConsoleHandle
= hConsoleOutput
;
1560 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
1562 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
1564 SetLastErrorByStatus ( Status
);
1567 *lpConsoleCursorInfo
= Reply
.Data
.GetCursorInfoReply
.Info
;
1572 /*--------------------------------------------------------------
1573 * GetNumberOfConsoleMouseButtons
1578 GetNumberOfConsoleMouseButtons(
1579 LPDWORD lpNumberOfMouseButtons
1587 /*--------------------------------------------------------------
1594 HANDLE hConsoleHandle
,
1598 CSRSS_API_REQUEST Request
;
1599 CSRSS_API_REPLY Reply
;
1602 Request
.Type
= CSRSS_SET_MODE
;
1603 Request
.Data
.SetConsoleModeRequest
.ConsoleHandle
= hConsoleHandle
;
1604 Request
.Data
.SetConsoleModeRequest
.Mode
= dwMode
;
1605 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
1606 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
1608 SetLastErrorByStatus ( Status
);
1615 /*--------------------------------------------------------------
1616 * SetConsoleActiveScreenBuffer
1621 SetConsoleActiveScreenBuffer(
1622 HANDLE hConsoleOutput
1625 CSRSS_API_REQUEST Request
;
1626 CSRSS_API_REPLY Reply
;
1629 Request
.Type
= CSRSS_SET_SCREEN_BUFFER
;
1630 Request
.Data
.SetActiveScreenBufferRequest
.OutputHandle
= hConsoleOutput
;
1631 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
1632 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
1634 SetLastErrorByStatus ( Status
);
1641 /*--------------------------------------------------------------
1642 * FlushConsoleInputBuffer
1647 FlushConsoleInputBuffer(
1648 HANDLE hConsoleInput
1651 CSRSS_API_REQUEST Request
;
1652 CSRSS_API_REPLY Reply
;
1655 Request
.Type
= CSRSS_FLUSH_INPUT_BUFFER
;
1656 Request
.Data
.FlushInputBufferRequest
.ConsoleInput
= hConsoleInput
;
1657 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
1658 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
1660 SetLastErrorByStatus ( Status
);
1667 /*--------------------------------------------------------------
1668 * SetConsoleScreenBufferSize
1673 SetConsoleScreenBufferSize(
1674 HANDLE hConsoleOutput
,
1682 /*--------------------------------------------------------------
1683 * SetConsoleCursorInfo
1688 SetConsoleCursorInfo(
1689 HANDLE hConsoleOutput
,
1690 CONST CONSOLE_CURSOR_INFO
*lpConsoleCursorInfo
1693 CSRSS_API_REQUEST Request
;
1694 CSRSS_API_REPLY Reply
;
1697 Request
.Type
= CSRSS_SET_CURSOR_INFO
;
1698 Request
.Data
.SetCursorInfoRequest
.ConsoleHandle
= hConsoleOutput
;
1699 Request
.Data
.SetCursorInfoRequest
.Info
= *lpConsoleCursorInfo
;
1700 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
1702 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
1704 SetLastErrorByStatus ( Status
);
1711 /*--------------------------------------------------------------
1712 * ScrollConsoleScreenBufferA
1717 ScrollConsoleScreenBufferA(
1718 HANDLE hConsoleOutput
,
1719 CONST SMALL_RECT
*lpScrollRectangle
,
1720 CONST SMALL_RECT
*lpClipRectangle
,
1721 COORD dwDestinationOrigin
,
1722 CONST CHAR_INFO
*lpFill
1725 CSRSS_API_REQUEST Request
;
1726 CSRSS_API_REPLY Reply
;
1729 Request
.Type
= CSRSS_SCROLL_CONSOLE_SCREEN_BUFFER
;
1730 Request
.Data
.ScrollConsoleScreenBufferRequest
.ConsoleHandle
= hConsoleOutput
;
1731 Request
.Data
.ScrollConsoleScreenBufferRequest
.ScrollRectangle
= *lpScrollRectangle
;
1733 if (lpClipRectangle
!= NULL
)
1735 Request
.Data
.ScrollConsoleScreenBufferRequest
.UseClipRectangle
= TRUE
;
1736 Request
.Data
.ScrollConsoleScreenBufferRequest
.ClipRectangle
= *lpClipRectangle
;
1740 Request
.Data
.ScrollConsoleScreenBufferRequest
.UseClipRectangle
= FALSE
;
1743 Request
.Data
.ScrollConsoleScreenBufferRequest
.DestinationOrigin
= dwDestinationOrigin
;
1744 Request
.Data
.ScrollConsoleScreenBufferRequest
.Fill
= *lpFill
;
1745 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
1747 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
1749 SetLastErrorByStatus ( Status
);
1756 /*--------------------------------------------------------------
1757 * ScrollConsoleScreenBufferW
1762 ScrollConsoleScreenBufferW(
1763 HANDLE hConsoleOutput
,
1764 CONST SMALL_RECT
*lpScrollRectangle
,
1765 CONST SMALL_RECT
*lpClipRectangle
,
1766 COORD dwDestinationOrigin
,
1767 CONST CHAR_INFO
*lpFill
1775 /*--------------------------------------------------------------
1776 * SetConsoleWindowInfo
1781 SetConsoleWindowInfo(
1782 HANDLE hConsoleOutput
,
1784 CONST SMALL_RECT
*lpConsoleWindow
1792 /*--------------------------------------------------------------
1793 * SetConsoleTextAttribute
1798 SetConsoleTextAttribute(
1799 HANDLE hConsoleOutput
,
1803 CSRSS_API_REQUEST Request
;
1804 CSRSS_API_REPLY Reply
;
1807 Request
.Type
= CSRSS_SET_ATTRIB
;
1808 Request
.Data
.SetAttribRequest
.ConsoleHandle
= hConsoleOutput
;
1809 Request
.Data
.SetAttribRequest
.Attrib
= wAttributes
;
1810 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
1811 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
1813 SetLastErrorByStatus ( Status
);
1820 AddConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine
)
1822 if (HandlerRoutine
== NULL
)
1824 IgnoreCtrlEvents
= TRUE
;
1831 RtlReAllocateHeap(RtlGetProcessHeap(),
1833 (PVOID
)CtrlHandlers
,
1834 NrCtrlHandlers
* sizeof(PHANDLER_ROUTINE
));
1835 if (CtrlHandlers
== NULL
)
1837 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1840 CtrlHandlers
[NrCtrlHandlers
- 1] = HandlerRoutine
;
1846 RemoveConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine
)
1850 if (HandlerRoutine
== NULL
)
1852 IgnoreCtrlEvents
= FALSE
;
1857 for (i
= 0; i
< NrCtrlHandlers
; i
++)
1859 if (CtrlHandlers
[i
] == HandlerRoutine
)
1861 CtrlHandlers
[i
] = CtrlHandlers
[NrCtrlHandlers
- 1];
1864 RtlReAllocateHeap(RtlGetProcessHeap(),
1866 (PVOID
)CtrlHandlers
,
1867 NrCtrlHandlers
* sizeof(PHANDLER_ROUTINE
));
1875 WINBASEAPI BOOL WINAPI
1876 SetConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine
,
1881 RtlEnterCriticalSection(&DllLock
);
1884 Ret
= AddConsoleCtrlHandler(HandlerRoutine
);
1888 Ret
= RemoveConsoleCtrlHandler(HandlerRoutine
);
1890 RtlLeaveCriticalSection(&DllLock
);
1895 /*--------------------------------------------------------------
1896 * GenerateConsoleCtrlEvent
1898 WINBASEAPI BOOL WINAPI
1899 GenerateConsoleCtrlEvent(
1901 DWORD dwProcessGroupId
1909 /*--------------------------------------------------------------
1912 #define MAX_CONSOLE_TITLE_LENGTH 80
1918 LPWSTR lpConsoleTitle
,
1923 CSRSS_API_REQUEST quest
;
1924 CSRSS_API_REPLY ply
;
1929 Re
.quest
.Type
= CSRSS_GET_TITLE
;
1930 Re
.quest
.Data
.GetTitleRequest
.ConsoleHandle
=
1931 GetStdHandle (STD_INPUT_HANDLE
);
1934 Status
= CsrClientCallServer (
1937 (sizeof (CSRSS_GET_TITLE_REQUEST
) +
1938 sizeof (LPC_MESSAGE
) +
1940 sizeof (CSRSS_API_REPLY
)
1942 if ( !NT_SUCCESS(Status
)
1943 || !NT_SUCCESS (Status
= Re
.ply
.Status
)
1946 SetLastErrorByStatus (Status
);
1950 /* Convert size in characters to size in bytes */
1951 nSize
= sizeof (WCHAR
) * nSize
;
1953 /* Unmarshall data */
1954 if (nSize
< Re
.ply
.Data
.GetTitleReply
.Length
)
1956 DbgPrint ("%s: ret=%d\n", __FUNCTION__
, Re
.ply
.Data
.GetTitleReply
.Length
);
1957 nSize
/= sizeof (WCHAR
);
1962 Re
.ply
.Data
.GetTitleReply
.Title
,
1966 lpConsoleTitle
[nSize
--] = L
'\0';
1971 nSize
= Re
.ply
.Data
.GetTitleReply
.Length
/ sizeof (WCHAR
);
1972 wcscpy (lpConsoleTitle
, Re
.ply
.Data
.GetTitleReply
.Title
);
1979 /*--------------------------------------------------------------
1988 LPSTR lpConsoleTitle
,
1992 wchar_t WideTitle
[MAX_CONSOLE_TITLE_LENGTH
];
1993 DWORD nWideTitle
= sizeof WideTitle
;
1996 if (!lpConsoleTitle
|| !nSize
) return 0;
1997 nWideTitle
= GetConsoleTitleW( (LPWSTR
) WideTitle
, nWideTitle
);
1998 if (!nWideTitle
) return 0;
2000 if ( (nWritten
= WideCharToMultiByte(
2001 CP_ACP
, // ANSI code page
2002 0, // performance and mapping flags
2003 (LPWSTR
) WideTitle
, // address of wide-character string
2004 nWideTitle
, // number of characters in string
2005 lpConsoleTitle
, // address of buffer for new string
2006 nSize
, // size of buffer
2011 lpConsoleTitle
[nWritten
] = '\0';
2019 /*--------------------------------------------------------------
2026 LPCWSTR lpConsoleTitle
2029 PCSRSS_API_REQUEST Request
;
2030 CSRSS_API_REPLY Reply
;
2034 Request
= RtlAllocateHeap(GetProcessHeap(),
2036 sizeof(CSRSS_API_REQUEST
) + CSRSS_MAX_SET_TITLE_REQUEST
);
2037 if (Request
== NULL
)
2039 SetLastError(ERROR_OUTOFMEMORY
);
2043 Request
->Type
= CSRSS_SET_TITLE
;
2044 Request
->Data
.SetTitleRequest
.Console
= GetStdHandle( STD_INPUT_HANDLE
);
2046 for( c
= 0; lpConsoleTitle
[c
] && c
< CSRSS_MAX_TITLE_LENGTH
; c
++ )
2047 Request
->Data
.SetTitleRequest
.Title
[c
] = lpConsoleTitle
[c
];
2049 Request
->Data
.SetTitleRequest
.Title
[c
] = 0;
2050 Request
->Data
.SetTitleRequest
.Length
= c
;
2051 Status
= CsrClientCallServer(Request
,
2053 sizeof(CSRSS_SET_TITLE_REQUEST
) +
2055 sizeof( LPC_MESSAGE
) +
2057 sizeof(CSRSS_API_REPLY
));
2059 if (!NT_SUCCESS(Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
2061 RtlFreeHeap( GetProcessHeap(), 0, Request
);
2062 SetLastErrorByStatus (Status
);
2065 RtlFreeHeap( GetProcessHeap(), 0, Request
);
2070 /*--------------------------------------------------------------
2079 LPCSTR lpConsoleTitle
2082 PCSRSS_API_REQUEST Request
;
2083 CSRSS_API_REPLY Reply
;
2087 Request
= RtlAllocateHeap(GetProcessHeap(),
2089 sizeof(CSRSS_API_REQUEST
) + CSRSS_MAX_SET_TITLE_REQUEST
);
2090 if (Request
== NULL
)
2092 SetLastError(ERROR_OUTOFMEMORY
);
2096 Request
->Type
= CSRSS_SET_TITLE
;
2097 Request
->Data
.SetTitleRequest
.Console
= GetStdHandle( STD_INPUT_HANDLE
);
2099 for( c
= 0; lpConsoleTitle
[c
] && c
< CSRSS_MAX_TITLE_LENGTH
; c
++ )
2100 Request
->Data
.SetTitleRequest
.Title
[c
] = lpConsoleTitle
[c
];
2102 Request
->Data
.SetTitleRequest
.Title
[c
] = 0;
2103 Request
->Data
.SetTitleRequest
.Length
= c
;
2104 Status
= CsrClientCallServer(Request
,
2106 sizeof(CSRSS_SET_TITLE_REQUEST
) +
2108 sizeof( LPC_MESSAGE
) +
2110 sizeof(CSRSS_API_REPLY
));
2112 if (!NT_SUCCESS(Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
2114 RtlFreeHeap( GetProcessHeap(), 0, Request
);
2115 SetLastErrorByStatus (Status
);
2118 RtlFreeHeap( GetProcessHeap(), 0, Request
);
2123 /*--------------------------------------------------------------
2130 HANDLE hConsoleInput
,
2132 DWORD nNumberOfCharsToRead
,
2133 LPDWORD lpNumberOfCharsRead
,
2142 /*--------------------------------------------------------------
2149 HANDLE hConsoleOutput
,
2150 CONST VOID
*lpBuffer
,
2151 DWORD nNumberOfCharsToWrite
,
2152 LPDWORD lpNumberOfCharsWritten
,
2157 PCSRSS_API_REQUEST Request
;
2158 CSRSS_API_REPLY Reply
;
2161 Request
= RtlAllocateHeap(GetProcessHeap(),
2163 sizeof(CSRSS_API_REQUEST
) + nNumberOfCharsToWrite
* sizeof(WCHAR
));
2164 if (Request
== NULL
)
2166 SetLastError(ERROR_OUTOFMEMORY
);
2170 Request
->Type
= CSRSS_WRITE_CONSOLE
;
2171 Request
->Data
.WriteConsoleRequest
.ConsoleHandle
= hConsoleOutput
;
2172 Request
->Data
.WriteConsoleRequest
.NrCharactersToWrite
=
2173 nNumberOfCharsToWrite
;
2174 // DbgPrint("nNumberOfCharsToWrite %d\n", nNumberOfCharsToWrite);
2175 // DbgPrint("Buffer %s\n", Request->Data.WriteConsoleRequest.Buffer);
2176 memcpy(Request
->Data
.WriteConsoleRequest
.Buffer
,
2178 nNumberOfCharsToWrite
* sizeof(WCHAR
));
2180 Status
= CsrClientCallServer(Request
,
2182 sizeof(CSRSS_API_REQUEST
) + nNumberOfCharsToWrite
,
2183 sizeof(CSRSS_API_REPLY
));
2185 RtlFreeHeap(GetProcessHeap(),
2189 if (!NT_SUCCESS(Status
))
2194 if (lpNumberOfCharsWritten
!= NULL
)
2196 *lpNumberOfCharsWritten
=
2197 Reply
.Data
.WriteConsoleReply
.NrCharactersWritten
;
2205 /*--------------------------------------------------------------
2206 * CreateConsoleScreenBuffer
2211 CreateConsoleScreenBuffer(
2212 DWORD dwDesiredAccess
,
2214 CONST SECURITY_ATTRIBUTES
*lpSecurityAttributes
,
2216 LPVOID lpScreenBufferData
2219 // FIXME: don't ignore access, share mode, and security
2220 CSRSS_API_REQUEST Request
;
2221 CSRSS_API_REPLY Reply
;
2224 Request
.Type
= CSRSS_CREATE_SCREEN_BUFFER
;
2225 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
2226 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
2228 SetLastErrorByStatus ( Status
);
2231 return Reply
.Data
.CreateScreenBufferReply
.OutputHandle
;
2235 /*--------------------------------------------------------------
2241 GetConsoleCP( VOID
)
2244 return CP_OEMCP
; /* FIXME */
2248 /*--------------------------------------------------------------
2263 /*--------------------------------------------------------------
2264 * GetConsoleOutputCP
2269 GetConsoleOutputCP( VOID
)
2272 return 0; /* FIXME */
2276 /*--------------------------------------------------------------
2277 * SetConsoleOutputCP