1 /* $Id: console.c,v 1.37 2001/11/25 15:21:09 dwelch 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 ******************************************************************/
16 #include <ddk/ntddk.h>
17 #include <ddk/ntddblue.h>
22 #include <csrss/csrss.h>
23 #include <ntdll/csr.h>
26 #include <kernel32/kernel32.h>
27 #include <kernel32/error.h>
29 /* GLOBALS *******************************************************************/
31 static BOOL IgnoreCtrlEvents
= FALSE
;
32 static ULONG NrCtrlHandlers
= 0;
33 static PHANDLER_ROUTINE
* CtrlHandlers
= NULL
;
35 /* FUNCTIONS *****************************************************************/
38 AddConsoleAliasA (DWORD a0
,
45 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
50 AddConsoleAliasW (DWORD a0
,
57 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
62 ConsoleMenuControl (HANDLE hConsole
,
69 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
74 DuplicateConsoleHandle (HANDLE hConsole
,
82 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
87 ExpungeConsoleCommandHistoryW (DWORD Unknown0
)
92 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
98 ExpungeConsoleCommandHistoryA (DWORD Unknown0
)
103 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
108 GetConsoleAliasW (DWORD Unknown0
,
116 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
122 GetConsoleAliasA (DWORD Unknown0
,
130 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
135 GetConsoleAliasExesW (DWORD Unknown0
,
141 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
148 GetConsoleAliasExesA (DWORD Unknown0
,
154 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
161 GetConsoleAliasExesLengthA (VOID
)
166 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
171 GetConsoleAliasExesLengthW (VOID
)
176 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
181 GetConsoleAliasesW (DWORD Unknown0
,
188 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
193 GetConsoleAliasesA (DWORD Unknown0
,
200 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
205 GetConsoleAliasesLengthW (DWORD Unknown0
)
210 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
215 GetConsoleAliasesLengthA (DWORD Unknown0
)
220 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
225 GetConsoleCommandHistoryW (DWORD Unknown0
,
232 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
237 GetConsoleCommandHistoryA (DWORD Unknown0
,
244 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
249 GetConsoleCommandHistoryLengthW (DWORD Unknown0
)
254 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
259 GetConsoleCommandHistoryLengthA (DWORD Unknown0
)
264 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
269 GetConsoleDisplayMode (LPDWORD lpdwMode
)
271 * FUNCTION: Get the console display mode
273 * lpdwMode - Address of variable that receives the current value
275 * STATUS: Undocumented
278 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
283 GetConsoleFontInfo (DWORD Unknown0
,
291 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
296 GetConsoleFontSize (DWORD Unknown0
,
302 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
307 GetConsoleHardwareState (DWORD Unknown0
,
314 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
319 GetConsoleInputWaitHandle (VOID
)
324 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
329 GetCurrentConsoleFont (DWORD Unknown0
,
336 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
341 GetNumberOfConsoleFonts (VOID
)
346 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
347 return 1; /* FIXME: call csrss.exe */
351 InvalidateConsoleDIBits (DWORD Unknown0
,
357 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
362 OpenConsoleW (DWORD Unknown0
,
370 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
375 SetConsoleCommandHistoryMode (DWORD dwMode
)
380 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
385 SetConsoleCursor (DWORD Unknown0
,
391 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
396 SetConsoleDisplayMode (HANDLE hOut
,
400 * FUNCTION: Set the console display mode.
402 * hOut - Standard output handle.
403 * dwNewMode - New mode.
404 * lpdwOldMode - Address of a variable that receives the old mode.
407 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
412 SetConsoleFont (DWORD Unknown0
,
418 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
423 SetConsoleHardwareState (DWORD Unknown0
,
430 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
435 SetConsoleKeyShortcuts (DWORD Unknown0
,
443 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
448 SetConsoleMaximumWindowSize (DWORD Unknown0
,
454 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
459 SetConsoleMenuClose (DWORD Unknown0
)
464 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
469 SetConsoleNumberOfCommandsA (DWORD Unknown0
,
475 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
480 SetConsoleNumberOfCommandsW (DWORD Unknown0
,
486 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
491 SetConsolePalette (DWORD Unknown0
,
498 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
503 SetLastConsoleEventActive (VOID
)
508 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
513 ShowConsoleCursor (DWORD Unknown0
,
519 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
524 VerifyConsoleIoHandle (DWORD Unknown0
)
529 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
534 WriteConsoleInputVDMA (DWORD Unknown0
,
539 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
544 WriteConsoleInputVDMW (DWORD Unknown0
,
549 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
554 CloseConsoleHandle(HANDLE Handle
)
559 if (IsConsoleHandle (Handle
) == FALSE
)
561 SetLastError (ERROR_INVALID_PARAMETER
);
564 /* FIXME: call CSRSS */
569 IsConsoleHandle(HANDLE Handle
)
571 if ((((ULONG
)Handle
) & 0x10000003) == 0x3)
579 GetStdHandle(DWORD nStdHandle
)
581 * FUNCTION: Get a handle for the standard input, standard output
582 * and a standard error device.
584 * nStdHandle - Specifies the device for which to return the handle.
585 * RETURNS: If the function succeeds, the return value is the handle
586 * of the specified device. Otherwise the value is INVALID_HANDLE_VALUE.
589 PRTL_USER_PROCESS_PARAMETERS Ppb
;
591 Ppb
= NtCurrentPeb()->ProcessParameters
;
594 case STD_INPUT_HANDLE
: return Ppb
->InputHandle
;
595 case STD_OUTPUT_HANDLE
: return Ppb
->OutputHandle
;
596 case STD_ERROR_HANDLE
: return Ppb
->ErrorHandle
;
598 SetLastError (ERROR_INVALID_PARAMETER
);
599 return INVALID_HANDLE_VALUE
;
602 WINBASEAPI BOOL WINAPI
603 SetStdHandle(DWORD nStdHandle
,
606 * FUNCTION: Set the handle for the standard input, standard output or
607 * the standard error device.
609 * nStdHandle - Specifies the handle to be set.
610 * hHandle - The handle to set.
611 * RETURNS: TRUE if the function succeeds, FALSE otherwise.
614 PRTL_USER_PROCESS_PARAMETERS Ppb
;
616 Ppb
= NtCurrentPeb()->ProcessParameters
;
618 /* More checking needed? */
619 if (hHandle
== INVALID_HANDLE_VALUE
)
621 SetLastError (ERROR_INVALID_HANDLE
);
625 SetLastError(ERROR_SUCCESS
); /* OK */
628 case STD_INPUT_HANDLE
:
629 Ppb
->InputHandle
= hHandle
;
631 case STD_OUTPUT_HANDLE
:
632 Ppb
->OutputHandle
= hHandle
;
634 case STD_ERROR_HANDLE
:
635 Ppb
->ErrorHandle
= hHandle
;
638 SetLastError (ERROR_INVALID_PARAMETER
);
643 /*--------------------------------------------------------------
647 WriteConsoleA(HANDLE hConsoleOutput
,
648 CONST VOID
*lpBuffer
,
649 DWORD nNumberOfCharsToWrite
,
650 LPDWORD lpNumberOfCharsWritten
,
653 PCSRSS_API_REQUEST Request
;
654 CSRSS_API_REPLY Reply
;
659 Request
= RtlAllocateHeap(GetProcessHeap(),
661 sizeof(CSRSS_API_REQUEST
) +
662 CSRSS_MAX_WRITE_CONSOLE_REQUEST
);
668 Request
->Type
= CSRSS_WRITE_CONSOLE
;
669 Request
->Data
.WriteConsoleRequest
.ConsoleHandle
= hConsoleOutput
;
670 if (lpNumberOfCharsWritten
!= NULL
)
671 *lpNumberOfCharsWritten
= nNumberOfCharsToWrite
;
672 while (nNumberOfCharsToWrite
)
674 if (nNumberOfCharsToWrite
> CSRSS_MAX_WRITE_CONSOLE_REQUEST
)
676 Size
= CSRSS_MAX_WRITE_CONSOLE_REQUEST
;
680 Size
= nNumberOfCharsToWrite
;
682 Request
->Data
.WriteConsoleRequest
.NrCharactersToWrite
= Size
;
684 memcpy(Request
->Data
.WriteConsoleRequest
.Buffer
, lpBuffer
, Size
);
686 MessageSize
= CSRSS_REQUEST_HEADER_SIZE
+
687 sizeof(CSRSS_WRITE_CONSOLE_REQUEST
) + Size
;
688 Status
= CsrClientCallServer(Request
,
691 sizeof(CSRSS_API_REPLY
));
693 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
695 RtlFreeHeap(GetProcessHeap(), 0, Request
);
696 SetLastErrorByStatus(Status
);
699 nNumberOfCharsToWrite
-= Size
;
702 RtlFreeHeap(GetProcessHeap(), 0, Request
);
707 /*--------------------------------------------------------------
710 WINBOOL STDCALL
ReadConsoleA(HANDLE hConsoleInput
,
712 DWORD nNumberOfCharsToRead
,
713 LPDWORD lpNumberOfCharsRead
,
716 CSRSS_API_REQUEST Request
;
717 PCSRSS_API_REPLY Reply
;
721 Reply
= RtlAllocateHeap(GetProcessHeap(),
723 sizeof(CSRSS_API_REPLY
) + nNumberOfCharsToRead
);
729 Request
.Type
= CSRSS_READ_CONSOLE
;
730 Request
.Data
.ReadConsoleRequest
.ConsoleHandle
= hConsoleInput
;
731 Request
.Data
.ReadConsoleRequest
.NrCharactersToRead
= nNumberOfCharsToRead
> CSRSS_MAX_READ_CONSOLE_REQUEST
? CSRSS_MAX_READ_CONSOLE_REQUEST
: nNumberOfCharsToRead
;
732 Request
.Data
.ReadConsoleRequest
.nCharsCanBeDeleted
= 0;
733 Status
= CsrClientCallServer(&Request
,
735 sizeof(CSRSS_API_REQUEST
),
736 sizeof(CSRSS_API_REPLY
) +
737 Request
.Data
.ReadConsoleRequest
.NrCharactersToRead
);
738 if (!NT_SUCCESS(Status
) || !NT_SUCCESS( Status
= Reply
->Status
))
740 DbgPrint( "CSR returned error in ReadConsole\n" );
741 SetLastErrorByStatus ( Status
);
742 RtlFreeHeap( GetProcessHeap(), 0, Reply
);
745 if( Reply
->Status
== STATUS_NOTIFY_CLEANUP
)
746 Reply
->Status
= STATUS_PENDING
; // ignore backspace because we have no chars to backspace
747 /* There may not be any chars or lines to read yet, so wait */
748 while( Reply
->Status
== STATUS_PENDING
)
750 /* some chars may have been returned, but not a whole line yet, so recompute buffer and try again */
751 nNumberOfCharsToRead
-= Reply
->Data
.ReadConsoleReply
.NrCharactersRead
;
752 /* don't overflow caller's buffer, even if you still don't have a complete line */
753 if( !nNumberOfCharsToRead
)
755 Request
.Data
.ReadConsoleRequest
.NrCharactersToRead
= nNumberOfCharsToRead
> CSRSS_MAX_READ_CONSOLE_REQUEST
? CSRSS_MAX_READ_CONSOLE_REQUEST
: nNumberOfCharsToRead
;
756 /* copy any chars already read to buffer */
757 memcpy( lpBuffer
+ CharsRead
, Reply
->Data
.ReadConsoleReply
.Buffer
, Reply
->Data
.ReadConsoleReply
.NrCharactersRead
);
758 CharsRead
+= Reply
->Data
.ReadConsoleReply
.NrCharactersRead
;
759 /* wait for csrss to signal there is more data to read, but not if we got STATUS_NOTIFY_CLEANUP for backspace */
760 Status
= NtWaitForSingleObject( Reply
->Data
.ReadConsoleReply
.EventHandle
, FALSE
, 0 );
761 if( !NT_SUCCESS( Status
) )
763 DbgPrint( "Wait for console input failed!\n" );
764 RtlFreeHeap( GetProcessHeap(), 0, Reply
);
767 Request
.Data
.ReadConsoleRequest
.nCharsCanBeDeleted
= CharsRead
;
768 Status
= CsrClientCallServer( &Request
, Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) + Request
.Data
.ReadConsoleRequest
.NrCharactersToRead
);
769 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
->Status
) )
771 SetLastErrorByStatus ( Status
);
772 RtlFreeHeap( GetProcessHeap(), 0, Reply
);
775 if( Reply
->Status
== STATUS_NOTIFY_CLEANUP
)
781 nNumberOfCharsToRead
++;
783 Reply
->Status
= STATUS_PENDING
; // retry
786 /* copy data to buffer, count total returned, and return */
787 memcpy( lpBuffer
+ CharsRead
, Reply
->Data
.ReadConsoleReply
.Buffer
, Reply
->Data
.ReadConsoleReply
.NrCharactersRead
);
788 CharsRead
+= Reply
->Data
.ReadConsoleReply
.NrCharactersRead
;
789 if (lpNumberOfCharsRead
!= NULL
)
790 *lpNumberOfCharsRead
= CharsRead
;
791 RtlFreeHeap(GetProcessHeap(),
799 /*--------------------------------------------------------------
802 WINBOOL STDCALL
AllocConsole(VOID
)
804 CSRSS_API_REQUEST Request
;
805 CSRSS_API_REPLY Reply
;
808 Request
.Type
= CSRSS_ALLOC_CONSOLE
;
809 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
810 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
812 SetLastErrorByStatus ( Status
);
815 SetStdHandle( STD_INPUT_HANDLE
, Reply
.Data
.AllocConsoleReply
.InputHandle
);
816 SetStdHandle( STD_OUTPUT_HANDLE
, Reply
.Data
.AllocConsoleReply
.OutputHandle
);
817 SetStdHandle( STD_ERROR_HANDLE
, Reply
.Data
.AllocConsoleReply
.OutputHandle
);
822 /*--------------------------------------------------------------
825 WINBOOL STDCALL
FreeConsole(VOID
)
827 DbgPrint("FreeConsole() is unimplemented");
832 /*--------------------------------------------------------------
833 * GetConsoleScreenBufferInfo
837 GetConsoleScreenBufferInfo(
838 HANDLE hConsoleOutput
,
839 PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo
842 CSRSS_API_REQUEST Request
;
843 CSRSS_API_REPLY Reply
;
846 Request
.Type
= CSRSS_SCREEN_BUFFER_INFO
;
847 Request
.Data
.ScreenBufferInfoRequest
.ConsoleHandle
= hConsoleOutput
;
848 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
849 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
851 SetLastErrorByStatus ( Status
);
854 *lpConsoleScreenBufferInfo
= Reply
.Data
.ScreenBufferInfoReply
.Info
;
859 /*--------------------------------------------------------------
860 * SetConsoleCursorPosition
864 SetConsoleCursorPosition(
865 HANDLE hConsoleOutput
,
866 COORD dwCursorPosition
869 CSRSS_API_REQUEST Request
;
870 CSRSS_API_REPLY Reply
;
873 Request
.Type
= CSRSS_SET_CURSOR
;
874 Request
.Data
.SetCursorRequest
.ConsoleHandle
= hConsoleOutput
;
875 Request
.Data
.SetCursorRequest
.Position
= dwCursorPosition
;
876 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
877 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
879 SetLastErrorByStatus ( Status
);
886 /*--------------------------------------------------------------
887 * FillConsoleOutputCharacterA
891 FillConsoleOutputCharacterA(
892 HANDLE hConsoleOutput
,
896 LPDWORD lpNumberOfCharsWritten
899 CSRSS_API_REQUEST Request
;
900 CSRSS_API_REPLY Reply
;
903 Request
.Type
= CSRSS_FILL_OUTPUT
;
904 Request
.Data
.FillOutputRequest
.ConsoleHandle
= hConsoleOutput
;
905 Request
.Data
.FillOutputRequest
.Char
= cCharacter
;
906 Request
.Data
.FillOutputRequest
.Position
= dwWriteCoord
;
907 Request
.Data
.FillOutputRequest
.Length
= nLength
;
908 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
909 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
911 SetLastErrorByStatus ( Status
);
914 *lpNumberOfCharsWritten
= nLength
;
919 /*--------------------------------------------------------------
920 * FillConsoleOutputCharacterW
924 FillConsoleOutputCharacterW(
925 HANDLE hConsoleOutput
,
929 LPDWORD lpNumberOfCharsWritten
937 /*--------------------------------------------------------------
944 HANDLE hConsoleInput
,
945 PINPUT_RECORD lpBuffer
,
947 LPDWORD lpNumberOfEventsRead
955 /*--------------------------------------------------------------
962 HANDLE hConsoleInput
,
963 PINPUT_RECORD lpBuffer
,
965 LPDWORD lpNumberOfEventsRead
973 /*--------------------------------------------------------------
976 WINBASEAPI BOOL WINAPI
977 ReadConsoleInputA(HANDLE hConsoleInput
,
978 PINPUT_RECORD lpBuffer
,
980 LPDWORD lpNumberOfEventsRead
)
982 CSRSS_API_REQUEST Request
;
983 CSRSS_API_REPLY Reply
;
987 Request
.Type
= CSRSS_READ_INPUT
;
988 Request
.Data
.ReadInputRequest
.ConsoleHandle
= hConsoleInput
;
989 Status
= CsrClientCallServer(&Request
, &Reply
, sizeof(CSRSS_API_REQUEST
),
990 sizeof(CSRSS_API_REPLY
));
991 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
993 SetLastErrorByStatus(Status
);
997 while (Status
== STATUS_PENDING
)
999 Status
= NtWaitForSingleObject(Reply
.Data
.ReadInputReply
.Event
, FALSE
,
1001 if(!NT_SUCCESS(Status
))
1003 SetLastErrorByStatus(Status
);
1007 Request
.Type
= CSRSS_READ_INPUT
;
1008 Request
.Data
.ReadInputRequest
.ConsoleHandle
= hConsoleInput
;
1009 Status
= CsrClientCallServer(&Request
, &Reply
, sizeof(CSRSS_API_REQUEST
),
1010 sizeof(CSRSS_API_REPLY
));
1011 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
1013 SetLastErrorByStatus(Status
);
1019 *lpBuffer
= Reply
.Data
.ReadInputReply
.Input
;
1023 while ((NumEventsRead
< nLength
) && (Reply
.Data
.ReadInputReply
.MoreEvents
))
1025 Status
= CsrClientCallServer(&Request
, &Reply
, sizeof(CSRSS_API_REQUEST
),
1026 sizeof(CSRSS_API_REPLY
));
1027 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
1029 SetLastErrorByStatus(Status
);
1033 if (Status
== STATUS_PENDING
)
1038 *lpBuffer
= Reply
.Data
.ReadInputReply
.Input
;
1043 *lpNumberOfEventsRead
= NumEventsRead
;
1049 /*--------------------------------------------------------------
1056 HANDLE hConsoleInput
,
1057 PINPUT_RECORD lpBuffer
,
1059 LPDWORD lpNumberOfEventsRead
1067 /*--------------------------------------------------------------
1068 * WriteConsoleInputA
1074 HANDLE hConsoleInput
,
1075 CONST INPUT_RECORD
*lpBuffer
,
1077 LPDWORD lpNumberOfEventsWritten
1085 /*--------------------------------------------------------------
1086 * WriteConsoleInputW
1092 HANDLE hConsoleInput
,
1093 CONST INPUT_RECORD
*lpBuffer
,
1095 LPDWORD lpNumberOfEventsWritten
1103 /*--------------------------------------------------------------
1104 * ReadConsoleOutputA
1110 HANDLE hConsoleOutput
,
1111 PCHAR_INFO lpBuffer
,
1113 COORD dwBufferCoord
,
1114 PSMALL_RECT lpReadRegion
1122 /*--------------------------------------------------------------
1123 * ReadConsoleOutputW
1129 HANDLE hConsoleOutput
,
1130 PCHAR_INFO lpBuffer
,
1132 COORD dwBufferCoord
,
1133 PSMALL_RECT lpReadRegion
1140 /*--------------------------------------------------------------
1141 * WriteConsoleOutputA
1143 WINBASEAPI BOOL WINAPI
1144 WriteConsoleOutputA(HANDLE hConsoleOutput
,
1145 CONST CHAR_INFO
*lpBuffer
,
1147 COORD dwBufferCoord
,
1148 PSMALL_RECT lpWriteRegion
)
1150 PCSRSS_API_REQUEST Request
;
1151 CSRSS_API_REPLY Reply
;
1157 Size
= dwBufferSize
.Y
* dwBufferSize
.X
* sizeof(CHAR_INFO
);
1159 if ((sizeof(CSRSS_API_REQUEST
) + Size
) >
1160 (sizeof(LPC_MESSAGE
) + MAX_MESSAGE_DATA
))
1162 COORD FragDim
, FragCoord
;
1163 SMALL_RECT FragRegion
;
1165 CONST CHAR_INFO
* lpFragBuffer
;
1167 SizeX
= min(dwBufferSize
.X
- dwBufferCoord
.X
,
1168 lpWriteRegion
->Right
- lpWriteRegion
->Left
);
1169 SizeY
= min(dwBufferSize
.Y
- dwBufferCoord
.Y
,
1170 lpWriteRegion
->Bottom
- lpWriteRegion
->Top
);
1172 for (i
= dwBufferCoord
.Y
; i
< (dwBufferCoord
.Y
+ SizeY
); i
++)
1174 for (j
= dwBufferCoord
.X
; j
< (dwBufferCoord
.X
+ SizeX
); j
++)
1180 FragRegion
.Left
= lpWriteRegion
->Left
+ j
;
1181 FragRegion
.Right
= lpWriteRegion
->Left
+ j
+ 1;
1182 FragRegion
.Top
= lpWriteRegion
->Top
+ i
;
1183 FragRegion
.Bottom
= lpWriteRegion
->Bottom
+ i
+ 1;
1185 lpFragBuffer
= lpBuffer
+ (i
* dwBufferSize
.X
) + j
;
1186 Result
= WriteConsoleOutputA(hConsoleOutput
,
1200 Request
= RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY
,
1201 sizeof(CSRSS_API_REQUEST
) + Size
);
1202 if (Request
== NULL
)
1204 SetLastError(ERROR_OUTOFMEMORY
);
1207 Request
->Type
= CSRSS_WRITE_CONSOLE_OUTPUT
;
1208 Request
->Data
.WriteConsoleOutputRequest
.ConsoleHandle
= hConsoleOutput
;
1209 Request
->Data
.WriteConsoleOutputRequest
.BufferSize
= dwBufferSize
;
1210 Request
->Data
.WriteConsoleOutputRequest
.BufferCoord
= dwBufferCoord
;
1211 Request
->Data
.WriteConsoleOutputRequest
.WriteRegion
= *lpWriteRegion
;
1212 RtlCopyMemory(&Request
->Data
.WriteConsoleOutputRequest
.CharInfo
, lpBuffer
,
1215 Status
= CsrClientCallServer(Request
, &Reply
,
1216 sizeof(CSRSS_API_REQUEST
) + Size
,
1217 sizeof(CSRSS_API_REPLY
));
1218 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Reply
.Status
))
1220 RtlFreeHeap(GetProcessHeap(), 0, Request
);
1221 SetLastErrorByStatus(Status
);
1225 *lpWriteRegion
= Reply
.Data
.WriteConsoleOutputReply
.WriteRegion
;
1226 RtlFreeHeap(GetProcessHeap(), 0, Request
);
1231 /*--------------------------------------------------------------
1232 * WriteConsoleOutputW
1237 WriteConsoleOutputW(
1238 HANDLE hConsoleOutput
,
1239 CONST CHAR_INFO
*lpBuffer
,
1241 COORD dwBufferCoord
,
1242 PSMALL_RECT lpWriteRegion
1250 /*--------------------------------------------------------------
1251 * ReadConsoleOutputCharacterA
1256 ReadConsoleOutputCharacterA(
1257 HANDLE hConsoleOutput
,
1261 LPDWORD lpNumberOfCharsRead
1264 SetLastError( ERROR_CALL_NOT_IMPLEMENTED
);
1269 /*--------------------------------------------------------------
1270 * ReadConsoleOutputCharacterW
1275 ReadConsoleOutputCharacterW(
1276 HANDLE hConsoleOutput
,
1280 LPDWORD lpNumberOfCharsRead
1288 /*--------------------------------------------------------------
1289 * ReadConsoleOutputAttribute
1294 ReadConsoleOutputAttribute(
1295 HANDLE hConsoleOutput
,
1299 LPDWORD lpNumberOfAttrsRead
1302 SetLastError( ERROR_CALL_NOT_IMPLEMENTED
);
1307 /*--------------------------------------------------------------
1308 * WriteConsoleOutputCharacterA
1313 WriteConsoleOutputCharacterA(
1314 HANDLE hConsoleOutput
,
1318 LPDWORD lpNumberOfCharsWritten
1321 PCSRSS_API_REQUEST Request
;
1322 CSRSS_API_REPLY Reply
;
1326 Request
= RtlAllocateHeap(GetProcessHeap(),
1328 sizeof(CSRSS_API_REQUEST
) + CSRSS_MAX_WRITE_CONSOLE_OUTPUT_CHAR
);
1331 SetLastError( ERROR_OUTOFMEMORY
);
1334 Request
->Type
= CSRSS_WRITE_CONSOLE_OUTPUT_CHAR
;
1335 Request
->Data
.WriteConsoleOutputCharRequest
.ConsoleHandle
= hConsoleOutput
;
1336 Request
->Data
.WriteConsoleOutputCharRequest
.Coord
= dwWriteCoord
;
1337 if( lpNumberOfCharsWritten
)
1338 *lpNumberOfCharsWritten
= nLength
;
1341 Size
= nLength
> CSRSS_MAX_WRITE_CONSOLE_OUTPUT_CHAR
? CSRSS_MAX_WRITE_CONSOLE_OUTPUT_CHAR
: nLength
;
1342 Request
->Data
.WriteConsoleOutputCharRequest
.Length
= Size
;
1343 memcpy( &Request
->Data
.WriteConsoleOutputCharRequest
.String
[0],
1346 Status
= CsrClientCallServer( Request
, &Reply
, sizeof( CSRSS_API_REQUEST
) + Size
, sizeof( CSRSS_API_REPLY
) );
1347 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
1349 RtlFreeHeap( GetProcessHeap(), 0, Request
);
1350 SetLastErrorByStatus ( Status
);
1354 lpCharacter
+= Size
;
1355 Request
->Data
.WriteConsoleOutputCharRequest
.Coord
= Reply
.Data
.WriteConsoleOutputCharReply
.EndCoord
;
1361 /*--------------------------------------------------------------
1362 * WriteConsoleOutputCharacterW
1367 WriteConsoleOutputCharacterW(
1368 HANDLE hConsoleOutput
,
1369 LPCWSTR lpCharacter
,
1372 LPDWORD lpNumberOfCharsWritten
1381 /*--------------------------------------------------------------
1382 * WriteConsoleOutputAttribute
1387 WriteConsoleOutputAttribute(
1388 HANDLE hConsoleOutput
,
1389 CONST WORD
*lpAttribute
,
1392 LPDWORD lpNumberOfAttrsWritten
1395 PCSRSS_API_REQUEST Request
;
1396 CSRSS_API_REPLY Reply
;
1401 Request
= RtlAllocateHeap(GetProcessHeap(),
1403 sizeof(CSRSS_API_REQUEST
) + CSRSS_MAX_WRITE_CONSOLE_OUTPUT_ATTRIB
);
1406 SetLastError( ERROR_OUTOFMEMORY
);
1409 Request
->Type
= CSRSS_WRITE_CONSOLE_OUTPUT_ATTRIB
;
1410 Request
->Data
.WriteConsoleOutputAttribRequest
.ConsoleHandle
= hConsoleOutput
;
1411 Request
->Data
.WriteConsoleOutputAttribRequest
.Coord
= dwWriteCoord
;
1412 if( lpNumberOfAttrsWritten
)
1413 *lpNumberOfAttrsWritten
= nLength
;
1416 Size
= nLength
> CSRSS_MAX_WRITE_CONSOLE_OUTPUT_ATTRIB
? CSRSS_MAX_WRITE_CONSOLE_OUTPUT_ATTRIB
: nLength
;
1417 Request
->Data
.WriteConsoleOutputAttribRequest
.Length
= Size
;
1418 for( c
= 0; c
< ( Size
* 2 ); c
++ )
1419 Request
->Data
.WriteConsoleOutputAttribRequest
.String
[c
] = (char)lpAttribute
[c
];
1420 Status
= CsrClientCallServer( Request
, &Reply
, sizeof( CSRSS_API_REQUEST
) + (Size
* 2), sizeof( CSRSS_API_REPLY
) );
1421 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
1423 RtlFreeHeap( GetProcessHeap(), 0, Request
);
1424 SetLastErrorByStatus ( Status
);
1428 lpAttribute
+= Size
;
1429 Request
->Data
.WriteConsoleOutputAttribRequest
.Coord
= Reply
.Data
.WriteConsoleOutputAttribReply
.EndCoord
;
1435 /*--------------------------------------------------------------
1436 * FillConsoleOutputAttribute
1441 FillConsoleOutputAttribute(
1442 HANDLE hConsoleOutput
,
1446 LPDWORD lpNumberOfAttrsWritten
1449 CSRSS_API_REQUEST Request
;
1450 CSRSS_API_REPLY Reply
;
1453 Request
.Type
= CSRSS_FILL_OUTPUT_ATTRIB
;
1454 Request
.Data
.FillOutputAttribRequest
.ConsoleHandle
= hConsoleOutput
;
1455 Request
.Data
.FillOutputAttribRequest
.Attribute
= wAttribute
;
1456 Request
.Data
.FillOutputAttribRequest
.Coord
= dwWriteCoord
;
1457 Request
.Data
.FillOutputAttribRequest
.Length
= nLength
;
1458 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
1459 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
1461 SetLastErrorByStatus ( Status
);
1464 if( lpNumberOfAttrsWritten
)
1465 *lpNumberOfAttrsWritten
= nLength
;
1470 /*--------------------------------------------------------------
1477 HANDLE hConsoleHandle
,
1481 CSRSS_API_REQUEST Request
;
1482 CSRSS_API_REPLY Reply
;
1485 Request
.Type
= CSRSS_GET_MODE
;
1486 Request
.Data
.GetConsoleModeRequest
.ConsoleHandle
= hConsoleHandle
;
1487 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
1488 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
1490 SetLastErrorByStatus ( Status
);
1493 *lpMode
= Reply
.Data
.GetConsoleModeReply
.ConsoleMode
;
1498 /*--------------------------------------------------------------
1499 * GetNumberOfConsoleInputEvents
1504 GetNumberOfConsoleInputEvents(
1505 HANDLE hConsoleInput
,
1506 LPDWORD lpNumberOfEvents
1514 /*--------------------------------------------------------------
1515 * GetLargestConsoleWindowSize
1520 GetLargestConsoleWindowSize(
1521 HANDLE hConsoleOutput
1525 COORD Coord
= {80,25};
1533 /*--------------------------------------------------------------
1534 * GetConsoleCursorInfo
1539 GetConsoleCursorInfo(
1540 HANDLE hConsoleOutput
,
1541 PCONSOLE_CURSOR_INFO lpConsoleCursorInfo
1544 CSRSS_API_REQUEST Request
;
1545 CSRSS_API_REPLY Reply
;
1548 Request
.Type
= CSRSS_GET_CURSOR_INFO
;
1549 Request
.Data
.GetCursorInfoRequest
.ConsoleHandle
= hConsoleOutput
;
1550 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
1552 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
1554 SetLastErrorByStatus ( Status
);
1557 *lpConsoleCursorInfo
= Reply
.Data
.GetCursorInfoReply
.Info
;
1562 /*--------------------------------------------------------------
1563 * GetNumberOfConsoleMouseButtons
1568 GetNumberOfConsoleMouseButtons(
1569 LPDWORD lpNumberOfMouseButtons
1577 /*--------------------------------------------------------------
1584 HANDLE hConsoleHandle
,
1588 CSRSS_API_REQUEST Request
;
1589 CSRSS_API_REPLY Reply
;
1592 Request
.Type
= CSRSS_SET_MODE
;
1593 Request
.Data
.SetConsoleModeRequest
.ConsoleHandle
= hConsoleHandle
;
1594 Request
.Data
.SetConsoleModeRequest
.Mode
= dwMode
;
1595 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
1596 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
1598 SetLastErrorByStatus ( Status
);
1605 /*--------------------------------------------------------------
1606 * SetConsoleActiveScreenBuffer
1611 SetConsoleActiveScreenBuffer(
1612 HANDLE hConsoleOutput
1615 CSRSS_API_REQUEST Request
;
1616 CSRSS_API_REPLY Reply
;
1619 Request
.Type
= CSRSS_SET_SCREEN_BUFFER
;
1620 Request
.Data
.SetActiveScreenBufferRequest
.OutputHandle
= hConsoleOutput
;
1621 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
1622 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
1624 SetLastErrorByStatus ( Status
);
1631 /*--------------------------------------------------------------
1632 * FlushConsoleInputBuffer
1637 FlushConsoleInputBuffer(
1638 HANDLE hConsoleInput
1641 CSRSS_API_REQUEST Request
;
1642 CSRSS_API_REPLY Reply
;
1645 Request
.Type
= CSRSS_FLUSH_INPUT_BUFFER
;
1646 Request
.Data
.FlushInputBufferRequest
.ConsoleInput
= hConsoleInput
;
1647 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
1648 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
1650 SetLastErrorByStatus ( Status
);
1657 /*--------------------------------------------------------------
1658 * SetConsoleScreenBufferSize
1663 SetConsoleScreenBufferSize(
1664 HANDLE hConsoleOutput
,
1672 /*--------------------------------------------------------------
1673 * SetConsoleCursorInfo
1678 SetConsoleCursorInfo(
1679 HANDLE hConsoleOutput
,
1680 CONST CONSOLE_CURSOR_INFO
*lpConsoleCursorInfo
1683 CSRSS_API_REQUEST Request
;
1684 CSRSS_API_REPLY Reply
;
1687 Request
.Type
= CSRSS_SET_CURSOR_INFO
;
1688 Request
.Data
.SetCursorInfoRequest
.ConsoleHandle
= hConsoleOutput
;
1689 Request
.Data
.SetCursorInfoRequest
.Info
= *lpConsoleCursorInfo
;
1690 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
1692 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
1694 SetLastErrorByStatus ( Status
);
1701 /*--------------------------------------------------------------
1702 * ScrollConsoleScreenBufferA
1707 ScrollConsoleScreenBufferA(
1708 HANDLE hConsoleOutput
,
1709 CONST SMALL_RECT
*lpScrollRectangle
,
1710 CONST SMALL_RECT
*lpClipRectangle
,
1711 COORD dwDestinationOrigin
,
1712 CONST CHAR_INFO
*lpFill
1715 CSRSS_API_REQUEST Request
;
1716 CSRSS_API_REPLY Reply
;
1719 Request
.Type
= CSRSS_SCROLL_CONSOLE_SCREEN_BUFFER
;
1720 Request
.Data
.ScrollConsoleScreenBufferRequest
.ConsoleHandle
= hConsoleOutput
;
1721 Request
.Data
.ScrollConsoleScreenBufferRequest
.ScrollRectangle
= *lpScrollRectangle
;
1723 if (lpClipRectangle
!= NULL
)
1725 Request
.Data
.ScrollConsoleScreenBufferRequest
.UseClipRectangle
= TRUE
;
1726 Request
.Data
.ScrollConsoleScreenBufferRequest
.ClipRectangle
= *lpClipRectangle
;
1730 Request
.Data
.ScrollConsoleScreenBufferRequest
.UseClipRectangle
= FALSE
;
1733 Request
.Data
.ScrollConsoleScreenBufferRequest
.DestinationOrigin
= dwDestinationOrigin
;
1734 Request
.Data
.ScrollConsoleScreenBufferRequest
.Fill
= *lpFill
;
1735 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
1737 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
1739 SetLastErrorByStatus ( Status
);
1746 /*--------------------------------------------------------------
1747 * ScrollConsoleScreenBufferW
1752 ScrollConsoleScreenBufferW(
1753 HANDLE hConsoleOutput
,
1754 CONST SMALL_RECT
*lpScrollRectangle
,
1755 CONST SMALL_RECT
*lpClipRectangle
,
1756 COORD dwDestinationOrigin
,
1757 CONST CHAR_INFO
*lpFill
1765 /*--------------------------------------------------------------
1766 * SetConsoleWindowInfo
1771 SetConsoleWindowInfo(
1772 HANDLE hConsoleOutput
,
1774 CONST SMALL_RECT
*lpConsoleWindow
1782 /*--------------------------------------------------------------
1783 * SetConsoleTextAttribute
1788 SetConsoleTextAttribute(
1789 HANDLE hConsoleOutput
,
1793 CSRSS_API_REQUEST Request
;
1794 CSRSS_API_REPLY Reply
;
1797 Request
.Type
= CSRSS_SET_ATTRIB
;
1798 Request
.Data
.SetAttribRequest
.ConsoleHandle
= hConsoleOutput
;
1799 Request
.Data
.SetAttribRequest
.Attrib
= wAttributes
;
1800 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
1801 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
1803 SetLastErrorByStatus ( Status
);
1810 AddConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine
)
1812 if (HandlerRoutine
== NULL
)
1814 IgnoreCtrlEvents
= TRUE
;
1821 RtlReAllocateHeap(RtlGetProcessHeap(),
1823 (PVOID
)CtrlHandlers
,
1824 NrCtrlHandlers
* sizeof(PHANDLER_ROUTINE
));
1825 if (CtrlHandlers
== NULL
)
1827 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1830 CtrlHandlers
[NrCtrlHandlers
- 1] = HandlerRoutine
;
1836 RemoveConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine
)
1840 if (HandlerRoutine
== NULL
)
1842 IgnoreCtrlEvents
= FALSE
;
1847 for (i
= 0; i
< NrCtrlHandlers
; i
++)
1849 if (CtrlHandlers
[i
] == HandlerRoutine
)
1851 CtrlHandlers
[i
] = CtrlHandlers
[NrCtrlHandlers
- 1];
1854 RtlReAllocateHeap(RtlGetProcessHeap(),
1856 (PVOID
)CtrlHandlers
,
1857 NrCtrlHandlers
* sizeof(PHANDLER_ROUTINE
));
1865 WINBASEAPI BOOL WINAPI
1866 SetConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine
,
1871 RtlEnterCriticalSection(&DllLock
);
1874 Ret
= AddConsoleCtrlHandler(HandlerRoutine
);
1878 Ret
= RemoveConsoleCtrlHandler(HandlerRoutine
);
1880 RtlLeaveCriticalSection(&DllLock
);
1885 /*--------------------------------------------------------------
1886 * GenerateConsoleCtrlEvent
1888 WINBASEAPI BOOL WINAPI
1889 GenerateConsoleCtrlEvent(
1891 DWORD dwProcessGroupId
1899 /*--------------------------------------------------------------
1902 #define MAX_CONSOLE_TITLE_LENGTH 80
1908 LPWSTR lpConsoleTitle
,
1913 CSRSS_API_REQUEST quest
;
1914 CSRSS_API_REPLY ply
;
1919 Re
.quest
.Type
= CSRSS_GET_TITLE
;
1920 Re
.quest
.Data
.GetTitleRequest
.ConsoleHandle
=
1921 GetStdHandle (STD_INPUT_HANDLE
);
1924 Status
= CsrClientCallServer (
1927 (sizeof (CSRSS_GET_TITLE_REQUEST
) +
1928 sizeof (LPC_MESSAGE_HEADER
) +
1930 sizeof (CSRSS_API_REPLY
)
1932 if ( !NT_SUCCESS(Status
)
1933 || !NT_SUCCESS (Status
= Re
.ply
.Status
)
1936 SetLastErrorByStatus (Status
);
1940 /* Convert size in characters to size in bytes */
1941 nSize
= sizeof (WCHAR
) * nSize
;
1943 /* Unmarshall data */
1944 if (nSize
< Re
.ply
.Data
.GetTitleReply
.Length
)
1946 DbgPrint ("%s: ret=%d\n", __FUNCTION__
, Re
.ply
.Data
.GetTitleReply
.Length
);
1947 nSize
/= sizeof (WCHAR
);
1952 Re
.ply
.Data
.GetTitleReply
.Title
,
1956 lpConsoleTitle
[nSize
--] = L
'\0';
1961 nSize
= Re
.ply
.Data
.GetTitleReply
.Length
/ sizeof (WCHAR
);
1962 wcscpy (lpConsoleTitle
, Re
.ply
.Data
.GetTitleReply
.Title
);
1969 /*--------------------------------------------------------------
1978 LPSTR lpConsoleTitle
,
1982 wchar_t WideTitle
[MAX_CONSOLE_TITLE_LENGTH
];
1983 DWORD nWideTitle
= sizeof WideTitle
;
1986 if (!lpConsoleTitle
|| !nSize
) return 0;
1987 nWideTitle
= GetConsoleTitleW( (LPWSTR
) WideTitle
, nWideTitle
);
1988 if (!nWideTitle
) return 0;
1990 if ( (nWritten
= WideCharToMultiByte(
1991 CP_ACP
, // ANSI code page
1992 0, // performance and mapping flags
1993 (LPWSTR
) WideTitle
, // address of wide-character string
1994 nWideTitle
, // number of characters in string
1995 lpConsoleTitle
, // address of buffer for new string
1996 nSize
, // size of buffer
2001 lpConsoleTitle
[nWritten
] = '\0';
2009 /*--------------------------------------------------------------
2016 LPCWSTR lpConsoleTitle
2019 PCSRSS_API_REQUEST Request
;
2020 CSRSS_API_REPLY Reply
;
2024 Request
= RtlAllocateHeap(GetProcessHeap(),
2026 sizeof(CSRSS_API_REQUEST
) + CSRSS_MAX_SET_TITLE_REQUEST
);
2027 if (Request
== NULL
)
2032 Request
->Type
= CSRSS_SET_TITLE
;
2033 Request
->Data
.SetTitleRequest
.Console
= GetStdHandle( STD_INPUT_HANDLE
);
2035 for( c
= 0; lpConsoleTitle
[c
] && c
< CSRSS_MAX_TITLE_LENGTH
; c
++ )
2036 Request
->Data
.SetTitleRequest
.Title
[c
] = lpConsoleTitle
[c
];
2038 Request
->Data
.SetTitleRequest
.Title
[c
] = 0;
2039 Request
->Data
.SetTitleRequest
.Length
= c
;
2040 Status
= CsrClientCallServer(Request
,
2042 sizeof(CSRSS_SET_TITLE_REQUEST
) +
2044 sizeof( LPC_MESSAGE_HEADER
) +
2046 sizeof(CSRSS_API_REPLY
));
2048 if (!NT_SUCCESS(Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
2050 RtlFreeHeap( GetProcessHeap(), 0, Request
);
2051 SetLastErrorByStatus (Status
);
2054 RtlFreeHeap( GetProcessHeap(), 0, Request
);
2059 /*--------------------------------------------------------------
2068 LPCSTR lpConsoleTitle
2071 PCSRSS_API_REQUEST Request
;
2072 CSRSS_API_REPLY Reply
;
2076 Request
= RtlAllocateHeap(GetProcessHeap(),
2078 sizeof(CSRSS_API_REQUEST
) + CSRSS_MAX_SET_TITLE_REQUEST
);
2079 if (Request
== NULL
)
2084 Request
->Type
= CSRSS_SET_TITLE
;
2085 Request
->Data
.SetTitleRequest
.Console
= GetStdHandle( STD_INPUT_HANDLE
);
2087 for( c
= 0; lpConsoleTitle
[c
] && c
< CSRSS_MAX_TITLE_LENGTH
; c
++ )
2088 Request
->Data
.SetTitleRequest
.Title
[c
] = lpConsoleTitle
[c
];
2090 Request
->Data
.SetTitleRequest
.Title
[c
] = 0;
2091 Request
->Data
.SetTitleRequest
.Length
= c
;
2092 Status
= CsrClientCallServer(Request
,
2094 sizeof(CSRSS_SET_TITLE_REQUEST
) +
2096 sizeof( LPC_MESSAGE_HEADER
) +
2098 sizeof(CSRSS_API_REPLY
));
2100 if (!NT_SUCCESS(Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
2102 RtlFreeHeap( GetProcessHeap(), 0, Request
);
2103 SetLastErrorByStatus (Status
);
2106 RtlFreeHeap( GetProcessHeap(), 0, Request
);
2111 /*--------------------------------------------------------------
2118 HANDLE hConsoleInput
,
2120 DWORD nNumberOfCharsToRead
,
2121 LPDWORD lpNumberOfCharsRead
,
2130 /*--------------------------------------------------------------
2137 HANDLE hConsoleOutput
,
2138 CONST VOID
*lpBuffer
,
2139 DWORD nNumberOfCharsToWrite
,
2140 LPDWORD lpNumberOfCharsWritten
,
2145 PCSRSS_API_REQUEST Request
;
2146 CSRSS_API_REPLY Reply
;
2149 Request
= RtlAllocateHeap(GetProcessHeap(),
2151 sizeof(CSRSS_API_REQUEST
) + nNumberOfCharsToWrite
* sizeof(WCHAR
));
2152 if (Request
== NULL
)
2157 Request
->Type
= CSRSS_WRITE_CONSOLE
;
2158 Request
->Data
.WriteConsoleRequest
.ConsoleHandle
= hConsoleOutput
;
2159 Request
->Data
.WriteConsoleRequest
.NrCharactersToWrite
=
2160 nNumberOfCharsToWrite
;
2161 // DbgPrint("nNumberOfCharsToWrite %d\n", nNumberOfCharsToWrite);
2162 // DbgPrint("Buffer %s\n", Request->Data.WriteConsoleRequest.Buffer);
2163 memcpy(Request
->Data
.WriteConsoleRequest
.Buffer
,
2165 nNumberOfCharsToWrite
* sizeof(WCHAR
));
2167 Status
= CsrClientCallServer(Request
,
2169 sizeof(CSRSS_API_REQUEST
) +
2170 nNumberOfCharsToWrite
,
2171 sizeof(CSRSS_API_REPLY
));
2173 RtlFreeHeap(GetProcessHeap(),
2177 if (!NT_SUCCESS(Status
))
2182 if (lpNumberOfCharsWritten
!= NULL
)
2184 *lpNumberOfCharsWritten
=
2185 Reply
.Data
.WriteConsoleReply
.NrCharactersWritten
;
2194 /*--------------------------------------------------------------
2195 * CreateConsoleScreenBuffer
2200 CreateConsoleScreenBuffer(
2201 DWORD dwDesiredAccess
,
2203 CONST SECURITY_ATTRIBUTES
*lpSecurityAttributes
,
2205 LPVOID lpScreenBufferData
2208 // FIXME: don't ignore access, share mode, and security
2209 CSRSS_API_REQUEST Request
;
2210 CSRSS_API_REPLY Reply
;
2213 Request
.Type
= CSRSS_CREATE_SCREEN_BUFFER
;
2214 Status
= CsrClientCallServer( &Request
, &Reply
, sizeof( CSRSS_API_REQUEST
), sizeof( CSRSS_API_REPLY
) );
2215 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Reply
.Status
) )
2217 SetLastErrorByStatus ( Status
);
2220 return Reply
.Data
.CreateScreenBufferReply
.OutputHandle
;
2224 /*--------------------------------------------------------------
2230 GetConsoleCP( VOID
)
2233 return CP_OEMCP
; /* FIXME */
2237 /*--------------------------------------------------------------
2252 /*--------------------------------------------------------------
2253 * GetConsoleOutputCP
2258 GetConsoleOutputCP( VOID
)
2261 return 0; /* FIXME */
2265 /*--------------------------------------------------------------
2266 * SetConsoleOutputCP