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 ******************************************************************/
22 extern BOOL WINAPI
DefaultConsoleCtrlHandler(DWORD Event
);
23 extern __declspec(noreturn
) VOID CALLBACK
ConsoleControlDispatcher(DWORD CodeAndFlag
);
24 extern RTL_CRITICAL_SECTION ConsoleLock
;
25 extern BOOL ConsoleInitialized
;
26 extern BOOL WINAPI
IsDebuggerPresent(VOID
);
28 /* GLOBALS *******************************************************************/
30 static PHANDLER_ROUTINE
* CtrlHandlers
= NULL
;
31 static ULONG NrCtrlHandlers
= 0;
32 static WCHAR InputExeName
[MAX_PATH
+ 1] = L
"";
34 /* Default Console Control Handler *******************************************/
36 BOOL WINAPI
DefaultConsoleCtrlHandler(DWORD Event
)
41 DPRINT("Ctrl-C Event\n");
44 case CTRL_BREAK_EVENT
:
45 DPRINT("Ctrl-Break Event\n");
48 case CTRL_SHUTDOWN_EVENT
:
49 DPRINT("Ctrl Shutdown Event\n");
52 case CTRL_CLOSE_EVENT
:
53 DPRINT("Ctrl Close Event\n");
56 case CTRL_LOGOFF_EVENT
:
57 DPRINT("Ctrl Logoff Event\n");
65 __declspec(noreturn
) VOID CALLBACK
ConsoleControlDispatcher(DWORD CodeAndFlag
)
68 DWORD nCode
= CodeAndFlag
& MAXLONG
;
71 SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST
);
76 case CTRL_BREAK_EVENT
:
78 if(IsDebuggerPresent())
80 EXCEPTION_RECORD erException
;
81 erException
.ExceptionCode
=
82 (nCode
== CTRL_C_EVENT
? DBG_CONTROL_C
: DBG_CONTROL_BREAK
);
83 erException
.ExceptionFlags
= 0;
84 erException
.ExceptionRecord
= NULL
;
85 erException
.ExceptionAddress
= &DefaultConsoleCtrlHandler
;
86 erException
.NumberParameters
= 0;
87 RtlRaiseException(&erException
);
90 if (!ConsoleInitialized
) ExitThread(0);
91 RtlEnterCriticalSection(&ConsoleLock
);
93 if(!(nCode
== CTRL_C_EVENT
&&
94 NtCurrentPeb()->ProcessParameters
->ConsoleFlags
& 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 if (!ConsoleInitialized
) ExitThread(0);
111 RtlEnterCriticalSection(&ConsoleLock
);
113 if(!(nCode
== CTRL_C_EVENT
&&
114 NtCurrentPeb()->ProcessParameters
->ConsoleFlags
& 1))
119 if (i
== 1 && (CodeAndFlag
& MINLONG
) &&
120 (nCode
== CTRL_LOGOFF_EVENT
|| nCode
== CTRL_SHUTDOWN_EVENT
))
123 if(CtrlHandlers
[i
- 1](nCode
))
127 case CTRL_CLOSE_EVENT
:
128 case CTRL_LOGOFF_EVENT
:
129 case CTRL_SHUTDOWN_EVENT
:
130 nExitCode
= CodeAndFlag
;
137 RtlLeaveCriticalSection(&ConsoleLock
);
138 ExitThread(nExitCode
);
142 /* FUNCTIONS *****************************************************************/
148 AddConsoleAliasA (LPCSTR lpSource
,
152 LPWSTR lpSourceW
= NULL
;
153 LPWSTR lpTargetW
= NULL
;
154 LPWSTR lpExeNameW
= NULL
;
158 BasepAnsiStringToHeapUnicodeString(lpSource
, (LPWSTR
*) &lpSourceW
);
160 BasepAnsiStringToHeapUnicodeString(lpTarget
, (LPWSTR
*) &lpTargetW
);
162 BasepAnsiStringToHeapUnicodeString(lpExeName
, (LPWSTR
*) &lpExeNameW
);
164 bRetVal
= AddConsoleAliasW(lpSourceW
, lpTargetW
, lpExeNameW
);
168 RtlFreeHeap(GetProcessHeap(), 0, (LPWSTR
*) lpSourceW
);
170 RtlFreeHeap(GetProcessHeap(), 0, (LPWSTR
*) lpTargetW
);
172 RtlFreeHeap(GetProcessHeap(), 0, (LPWSTR
*) lpExeNameW
);
182 AddConsoleAliasW (LPCWSTR lpSource
,
186 PCSR_API_MESSAGE Request
;
190 ULONG TargetLength
= 0;
196 DPRINT("AddConsoleAliasW enterd with lpSource %S lpTarget %S lpExeName %S\n", lpSource
, lpTarget
, lpExeName
);
198 ExeLength
= wcslen(lpExeName
) + 1;
199 SourceLength
= wcslen(lpSource
)+ 1;
201 TargetLength
= wcslen(lpTarget
) + 1;
203 Size
= (ExeLength
+ SourceLength
+ TargetLength
) * sizeof(WCHAR
);
204 RequestLength
= sizeof(CSR_API_MESSAGE
) + Size
;
206 Request
= RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY
, RequestLength
);
207 Ptr
= (WCHAR
*)(((ULONG_PTR
)Request
) + sizeof(CSR_API_MESSAGE
));
209 wcscpy(Ptr
, lpSource
);
210 Request
->Data
.AddConsoleAlias
.SourceLength
= SourceLength
;
211 Ptr
= (WCHAR
*)(((ULONG_PTR
)Request
) + sizeof(CSR_API_MESSAGE
) + SourceLength
* sizeof(WCHAR
));
213 wcscpy(Ptr
, lpExeName
);
214 Request
->Data
.AddConsoleAlias
.ExeLength
= ExeLength
;
215 Ptr
= (WCHAR
*)(((ULONG_PTR
)Request
) + sizeof(CSR_API_MESSAGE
) + (ExeLength
+ SourceLength
)* sizeof(WCHAR
));
217 if (lpTarget
) /* target can be optional */
218 wcscpy(Ptr
, lpTarget
);
220 Request
->Data
.AddConsoleAlias
.TargetLength
= TargetLength
;
222 CsrRequest
= MAKE_CSR_API(ADD_CONSOLE_ALIAS
, CSR_CONSOLE
);
223 Status
= CsrClientCallServer(Request
,
228 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
->Status
))
230 SetLastErrorByStatus(Status
);
231 RtlFreeHeap(GetProcessHeap(), 0, Request
);
234 RtlFreeHeap(GetProcessHeap(), 0, Request
);
243 ConsoleMenuControl (HANDLE hConsole
,
250 DPRINT1("ConsoleMenuControl(0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", hConsole
, Unknown1
, Unknown2
);
251 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
260 DuplicateConsoleHandle (HANDLE hConsole
,
261 DWORD dwDesiredAccess
,
265 CSR_API_MESSAGE Request
;
269 if (dwOptions
& ~(DUPLICATE_CLOSE_SOURCE
| DUPLICATE_SAME_ACCESS
)
270 || (!(dwOptions
& DUPLICATE_SAME_ACCESS
)
271 && dwDesiredAccess
& ~(GENERIC_READ
| GENERIC_WRITE
)))
273 SetLastError (ERROR_INVALID_PARAMETER
);
274 return INVALID_HANDLE_VALUE
;
277 CsrRequest
= MAKE_CSR_API(DUPLICATE_HANDLE
, CSR_NATIVE
);
278 Request
.Data
.DuplicateHandleRequest
.Handle
= hConsole
;
279 Request
.Data
.DuplicateHandleRequest
.Access
= dwDesiredAccess
;
280 Request
.Data
.DuplicateHandleRequest
.Inheritable
= bInheritHandle
;
281 Request
.Data
.DuplicateHandleRequest
.Options
= dwOptions
;
282 Status
= CsrClientCallServer(&Request
,
285 sizeof(CSR_API_MESSAGE
));
286 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
=Request
.Status
))
288 SetLastErrorByStatus(Status
);
289 return INVALID_HANDLE_VALUE
;
291 return Request
.Data
.DuplicateHandleRequest
.Handle
;
299 ExpungeConsoleCommandHistoryW (DWORD Unknown0
)
304 DPRINT1("ExpungeConsoleCommandHistoryW(0x%x) UNIMPLEMENTED!\n", Unknown0
);
305 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
314 ExpungeConsoleCommandHistoryA (DWORD Unknown0
)
320 DPRINT1("ExpungeConsoleCommandHistoryW(0x%x) UNIMPLEMENTED!\n", Unknown0
);
321 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
330 GetConsoleAliasW (LPWSTR lpSource
,
331 LPWSTR lpTargetBuffer
,
332 DWORD TargetBufferLength
,
335 PCSR_API_MESSAGE Request
;
336 PCSR_CAPTURE_BUFFER CaptureBuffer
;
345 DPRINT("GetConsoleAliasW entered lpSource %S lpExeName %S\n", lpSource
, lpExeName
);
347 CsrRequest
= MAKE_CSR_API(GET_CONSOLE_ALIAS
, CSR_CONSOLE
);
349 ExeLength
= wcslen(lpExeName
) + 1;
350 SourceLength
= wcslen(lpSource
) + 1;
352 Size
= (ExeLength
+ SourceLength
) * sizeof(WCHAR
);
354 RequestLength
= Size
+ sizeof(CSR_API_MESSAGE
);
355 Request
= RtlAllocateHeap(GetProcessHeap(), 0, RequestLength
);
357 CaptureBuffer
= CsrAllocateCaptureBuffer(1, TargetBufferLength
);
360 RtlFreeHeap(GetProcessHeap(), 0, Request
);
364 Request
->Data
.GetConsoleAlias
.TargetBuffer
= NULL
;
365 CsrCaptureMessageBuffer(CaptureBuffer
,
368 (PVOID
*)&Request
->Data
.GetConsoleAlias
.TargetBuffer
);
369 Request
->Data
.GetConsoleAlias
.TargetBufferLength
= TargetBufferLength
;
371 Ptr
= (LPWSTR
)((ULONG_PTR
)Request
+ sizeof(CSR_API_MESSAGE
));
372 wcscpy(Ptr
, lpSource
);
374 wcscpy(Ptr
, lpExeName
);
376 Request
->Data
.GetConsoleAlias
.ExeLength
= ExeLength
;
377 Request
->Data
.GetConsoleAlias
.SourceLength
= SourceLength
;
379 Status
= CsrClientCallServer(Request
,
382 sizeof(CSR_API_MESSAGE
) + Size
);
384 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
->Status
))
386 RtlFreeHeap(GetProcessHeap(), 0, Request
);
387 CsrFreeCaptureBuffer(CaptureBuffer
);
388 SetLastErrorByStatus(Status
);
392 wcscpy(lpTargetBuffer
, Request
->Data
.GetConsoleAlias
.TargetBuffer
);
393 RtlFreeHeap(GetProcessHeap(), 0, Request
);
394 CsrFreeCaptureBuffer(CaptureBuffer
);
396 return Request
->Data
.GetConsoleAlias
.BytesWritten
;
404 GetConsoleAliasA (LPSTR lpSource
,
405 LPSTR lpTargetBuffer
,
406 DWORD TargetBufferLength
,
411 LPWSTR lpwTargetBuffer
;
416 DPRINT("GetConsoleAliasA entered\n");
418 dwSourceSize
= (strlen(lpSource
)+1) * sizeof(WCHAR
);
419 lpwSource
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, dwSourceSize
);
420 MultiByteToWideChar(CP_ACP
, 0, lpSource
, -1, lpwSource
, dwSourceSize
);
422 dwExeNameSize
= (strlen(lpExeName
)+1) * sizeof(WCHAR
);
423 lpwExeName
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, dwExeNameSize
);
424 MultiByteToWideChar(CP_ACP
, 0, lpExeName
, -1, lpwExeName
, dwExeNameSize
);
426 lpwTargetBuffer
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, TargetBufferLength
* sizeof(WCHAR
));
428 dwResult
= GetConsoleAliasW(lpwSource
, lpwTargetBuffer
, TargetBufferLength
* sizeof(WCHAR
), lpwExeName
);
430 HeapFree(GetProcessHeap(), 0, lpwSource
);
431 HeapFree(GetProcessHeap(), 0, lpwExeName
);
434 dwResult
= WideCharToMultiByte(CP_ACP
, 0, lpwTargetBuffer
, dwResult
/ sizeof(WCHAR
), lpTargetBuffer
, TargetBufferLength
, NULL
, NULL
);
436 HeapFree(GetProcessHeap(), 0, lpwTargetBuffer
);
446 GetConsoleAliasExesW (LPWSTR lpExeNameBuffer
,
447 DWORD ExeNameBufferLength
)
449 CSR_API_MESSAGE Request
;
450 PCSR_CAPTURE_BUFFER CaptureBuffer
;
454 DPRINT("GetConsoleAliasExesW entered\n");
456 CaptureBuffer
= CsrAllocateCaptureBuffer(1, ExeNameBufferLength
);
459 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
463 CsrRequest
= MAKE_CSR_API(GET_CONSOLE_ALIASES_EXES
, CSR_CONSOLE
);
464 CsrAllocateMessagePointer(CaptureBuffer
,
466 (PVOID
*)&Request
.Data
.GetConsoleAliasesExes
.ExeNames
);
467 Request
.Data
.GetConsoleAliasesExes
.Length
= ExeNameBufferLength
;
469 Status
= CsrClientCallServer(& Request
,
472 sizeof(CSR_API_MESSAGE
));
474 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
476 SetLastErrorByStatus(Status
);
477 CsrFreeCaptureBuffer(CaptureBuffer
);
481 memcpy(lpExeNameBuffer
,
482 Request
.Data
.GetConsoleAliasesExes
.ExeNames
,
483 Request
.Data
.GetConsoleAliasesExes
.BytesWritten
);
484 CsrFreeCaptureBuffer(CaptureBuffer
);
485 return Request
.Data
.GetConsoleAliasesExes
.BytesWritten
;
493 GetConsoleAliasExesA (LPSTR lpExeNameBuffer
,
494 DWORD ExeNameBufferLength
)
496 LPWSTR lpwExeNameBuffer
;
499 DPRINT("GetConsoleAliasExesA entered\n");
501 lpwExeNameBuffer
= HeapAlloc(GetProcessHeap(), 0, ExeNameBufferLength
* sizeof(WCHAR
));
503 dwResult
= GetConsoleAliasExesW(lpwExeNameBuffer
, ExeNameBufferLength
* sizeof(WCHAR
));
506 dwResult
= WideCharToMultiByte(CP_ACP
, 0, lpwExeNameBuffer
, dwResult
/ sizeof(WCHAR
), lpExeNameBuffer
, ExeNameBufferLength
, NULL
, NULL
);
508 HeapFree(GetProcessHeap(), 0, lpwExeNameBuffer
);
516 GetConsoleAliasExesLengthW (VOID
)
518 CSR_API_MESSAGE Request
;
522 DPRINT("GetConsoleAliasExesLengthW entered\n");
524 CsrRequest
= MAKE_CSR_API(GET_CONSOLE_ALIASES_EXES_LENGTH
, CSR_CONSOLE
);
525 Request
.Data
.GetConsoleAliasesExesLength
.Length
= 0;
528 Status
= CsrClientCallServer(& Request
,
531 sizeof(CSR_API_MESSAGE
));
533 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
535 SetLastErrorByStatus(Status
);
539 return Request
.Data
.GetConsoleAliasesExesLength
.Length
;
546 GetConsoleAliasExesLengthA (VOID
)
550 DPRINT("GetConsoleAliasExesLengthA entered\n");
552 dwLength
= GetConsoleAliasExesLengthW();
555 dwLength
/= sizeof(WCHAR
);
565 GetConsoleAliasesW (LPWSTR AliasBuffer
,
566 DWORD AliasBufferLength
,
569 CSR_API_MESSAGE Request
;
574 DPRINT("GetConsoleAliasesW entered\n");
576 dwLength
= GetConsoleAliasesLengthW(ExeName
);
577 if (!dwLength
|| dwLength
> AliasBufferLength
)
580 CsrRequest
= MAKE_CSR_API(GET_ALL_CONSOLE_ALIASES
, CSR_CONSOLE
);
581 Request
.Data
.GetAllConsoleAlias
.AliasBuffer
= AliasBuffer
;
582 Request
.Data
.GetAllConsoleAlias
.AliasBufferLength
= AliasBufferLength
;
583 Request
.Data
.GetAllConsoleAlias
.lpExeName
= ExeName
;
585 Status
= CsrClientCallServer(& Request
,
588 sizeof(CSR_API_MESSAGE
));
590 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
592 SetLastErrorByStatus(Status
);
596 return Request
.Data
.GetAllConsoleAlias
.BytesWritten
/ sizeof(WCHAR
);
604 GetConsoleAliasesA (LPSTR AliasBuffer
,
605 DWORD AliasBufferLength
,
609 LPWSTR lpwExeName
= NULL
;
610 LPWSTR lpwAliasBuffer
;
612 DPRINT("GetConsoleAliasesA entered\n");
615 BasepAnsiStringToHeapUnicodeString(ExeName
, (LPWSTR
*) &lpwExeName
);
617 lpwAliasBuffer
= HeapAlloc(GetProcessHeap(), 0, AliasBufferLength
* sizeof(WCHAR
));
619 dwRetVal
= GetConsoleAliasesW(lpwAliasBuffer
, AliasBufferLength
, lpwExeName
);
622 RtlFreeHeap(GetProcessHeap(), 0, (LPWSTR
*) lpwExeName
);
625 dwRetVal
= WideCharToMultiByte(CP_ACP
, 0, lpwAliasBuffer
, dwRetVal
, AliasBuffer
, AliasBufferLength
, NULL
, NULL
);
627 HeapFree(GetProcessHeap(), 0, lpwAliasBuffer
);
636 GetConsoleAliasesLengthW (LPWSTR lpExeName
)
638 CSR_API_MESSAGE Request
;
642 DPRINT("GetConsoleAliasesLengthW entered\n");
644 CsrRequest
= MAKE_CSR_API(GET_ALL_CONSOLE_ALIASES_LENGTH
, CSR_CONSOLE
);
645 Request
.Data
.GetAllConsoleAliasesLength
.lpExeName
= lpExeName
;
646 Request
.Data
.GetAllConsoleAliasesLength
.Length
= 0;
648 Status
= CsrClientCallServer(&Request
,
651 sizeof(CSR_API_MESSAGE
));
653 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
655 SetLastErrorByStatus(Status
);
659 return Request
.Data
.GetAllConsoleAliasesLength
.Length
;
667 GetConsoleAliasesLengthA (LPSTR lpExeName
)
670 LPWSTR lpExeNameW
= NULL
;
673 BasepAnsiStringToHeapUnicodeString(lpExeName
, (LPWSTR
*) &lpExeNameW
);
675 dwRetVal
= GetConsoleAliasesLengthW(lpExeNameW
);
677 dwRetVal
/= sizeof(WCHAR
);
681 RtlFreeHeap(GetProcessHeap(), 0, (LPWSTR
*) lpExeNameW
);
691 GetConsoleCommandHistoryW (DWORD Unknown0
,
698 DPRINT1("GetConsoleCommandHistoryW(0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
, Unknown2
);
699 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
708 GetConsoleCommandHistoryA (DWORD Unknown0
,
715 DPRINT1("GetConsoleCommandHistoryA(0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
, Unknown2
);
716 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
725 GetConsoleCommandHistoryLengthW (DWORD Unknown0
)
730 DPRINT1("GetConsoleCommandHistoryLengthW(0x%x) UNIMPLEMENTED!\n", Unknown0
);
731 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
740 GetConsoleCommandHistoryLengthA (DWORD Unknown0
)
745 DPRINT1("GetConsoleCommandHistoryLengthA(0x%x) UNIMPLEMENTED!\n", Unknown0
);
746 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
754 GetConsoleDisplayMode (LPDWORD lpdwMode
)
756 * FUNCTION: Get the console display mode
758 * lpdwMode - Address of variable that receives the current value
760 * STATUS: Undocumented
763 DPRINT1("GetConsoleDisplayMode(0x%x) UNIMPLEMENTED!\n", lpdwMode
);
764 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
773 GetConsoleFontInfo (DWORD Unknown0
,
781 DPRINT1("GetConsoleFontInfo(0x%x, 0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
, Unknown2
, Unknown3
);
782 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
791 GetConsoleFontSize(HANDLE hConsoleOutput
,
794 COORD Empty
= {0, 0};
795 DPRINT1("GetConsoleFontSize(0x%x, 0x%x) UNIMPLEMENTED!\n", hConsoleOutput
, nFont
);
796 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
805 GetConsoleHardwareState (HANDLE hConsole
,
812 CSR_API_MESSAGE Request
; ULONG CsrRequest
;
816 CsrRequest
= MAKE_CSR_API(SETGET_CONSOLE_HW_STATE
, CSR_CONSOLE
);
817 Request
.Data
.ConsoleHardwareStateRequest
.ConsoleHandle
= hConsole
;
818 Request
.Data
.ConsoleHardwareStateRequest
.SetGet
= CONSOLE_HARDWARE_STATE_GET
;
820 Status
= CsrClientCallServer(& Request
,
823 sizeof(CSR_API_MESSAGE
));
824 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
826 SetLastErrorByStatus(Status
);
829 *State
= Request
.Data
.ConsoleHardwareStateRequest
.State
;
838 GetConsoleInputWaitHandle (VOID
)
843 CSR_API_MESSAGE Request
; ULONG CsrRequest
;
847 CsrRequest
= MAKE_CSR_API(GET_INPUT_WAIT_HANDLE
, CSR_CONSOLE
);
848 Status
= CsrClientCallServer(&Request
, NULL
, CsrRequest
,
849 sizeof(CSR_API_MESSAGE
));
850 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
852 SetLastErrorByStatus(Status
);
855 return Request
.Data
.GetConsoleInputWaitHandle
.InputWaitHandle
;
863 GetCurrentConsoleFont(HANDLE hConsoleOutput
,
865 PCONSOLE_FONT_INFO lpConsoleCurrentFont
)
867 DPRINT1("GetCurrentConsoleFont(0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", hConsoleOutput
, bMaximumWindow
, lpConsoleCurrentFont
);
868 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
877 GetNumberOfConsoleFonts (VOID
)
882 DPRINT1("GetNumberOfConsoleFonts() UNIMPLEMENTED!\n");
883 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
884 return 1; /* FIXME: call csrss.exe */
892 InvalidateConsoleDIBits (DWORD Unknown0
,
898 DPRINT1("InvalidateConsoleDIBits(0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
);
899 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
908 OpenConsoleW (LPCWSTR wsName
,
909 DWORD dwDesiredAccess
,
916 CSR_API_MESSAGE Request
; ULONG CsrRequest
;
918 NTSTATUS Status
= STATUS_SUCCESS
;
920 if(0 == _wcsicmp(wsName
, L
"CONIN$"))
922 CsrRequest
= MAKE_CSR_API(GET_INPUT_HANDLE
, CSR_NATIVE
);
924 else if (0 == _wcsicmp(wsName
, L
"CONOUT$"))
926 CsrRequest
= MAKE_CSR_API(GET_OUTPUT_HANDLE
, CSR_NATIVE
);
930 SetLastError(ERROR_INVALID_PARAMETER
);
931 return(INVALID_HANDLE_VALUE
);
933 if (dwDesiredAccess
& ~(GENERIC_READ
|GENERIC_WRITE
))
935 SetLastError(ERROR_INVALID_PARAMETER
);
936 return(INVALID_HANDLE_VALUE
);
938 if (dwShareMode
& ~(FILE_SHARE_READ
|FILE_SHARE_WRITE
))
940 SetLastError(ERROR_INVALID_PARAMETER
);
941 return(INVALID_HANDLE_VALUE
);
943 /* Structures for GET_INPUT_HANDLE and GET_OUTPUT_HANDLE requests are identical */
944 Request
.Data
.GetInputHandleRequest
.Access
= dwDesiredAccess
;
945 Request
.Data
.GetInputHandleRequest
.Inheritable
= bInheritHandle
;
946 Status
= CsrClientCallServer(& Request
,
949 sizeof(CSR_API_MESSAGE
));
950 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
952 SetLastErrorByStatus(Status
);
953 return INVALID_HANDLE_VALUE
;
955 return Request
.Data
.GetInputHandleRequest
.InputHandle
;
963 SetConsoleCommandHistoryMode (DWORD dwMode
)
968 DPRINT1("SetConsoleCommandHistoryMode(0x%x) UNIMPLEMENTED!\n", dwMode
);
969 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
978 SetConsoleCursor (DWORD Unknown0
,
984 DPRINT1("SetConsoleCursor(0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
);
985 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
994 SetConsoleDisplayMode (HANDLE hOut
,
998 * FUNCTION: Set the console display mode.
1000 * hOut - Standard output handle.
1001 * dwNewMode - New mode.
1002 * lpdwOldMode - Address of a variable that receives the old mode.
1005 DPRINT1("SetConsoleDisplayMode(0x%x, 0x%x, 0x%p) UNIMPLEMENTED!\n", hOut
, dwNewMode
, lpdwOldMode
);
1006 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1015 SetConsoleFont (DWORD Unknown0
,
1021 DPRINT1("SetConsoleFont(0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
);
1022 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1031 SetConsoleHardwareState (HANDLE hConsole
,
1038 CSR_API_MESSAGE Request
; ULONG CsrRequest
;
1042 CsrRequest
= MAKE_CSR_API(SETGET_CONSOLE_HW_STATE
, CSR_CONSOLE
);
1043 Request
.Data
.ConsoleHardwareStateRequest
.ConsoleHandle
= hConsole
;
1044 Request
.Data
.ConsoleHardwareStateRequest
.SetGet
= CONSOLE_HARDWARE_STATE_SET
;
1045 Request
.Data
.ConsoleHardwareStateRequest
.State
= State
;
1047 Status
= CsrClientCallServer(& Request
,
1050 sizeof(CSR_API_MESSAGE
));
1051 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
1053 SetLastErrorByStatus(Status
);
1064 SetConsoleKeyShortcuts (DWORD Unknown0
,
1072 DPRINT1("SetConsoleKeyShortcuts(0x%x, 0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
, Unknown2
, Unknown3
);
1073 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1082 SetConsoleMaximumWindowSize (DWORD Unknown0
,
1088 DPRINT1("SetConsoleMaximumWindowSize(0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
);
1089 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1098 SetConsoleMenuClose (DWORD Unknown0
)
1103 DPRINT1("SetConsoleMenuClose(0x%x) UNIMPLEMENTED!\n", Unknown0
);
1104 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1113 SetConsoleNumberOfCommandsA (DWORD Unknown0
,
1119 DPRINT1("SetConsoleNumberOfCommandsA(0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
);
1120 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1129 SetConsoleNumberOfCommandsW (DWORD Unknown0
,
1135 DPRINT1("SetConsoleNumberOfCommandsW(0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
);
1136 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1145 SetConsolePalette (DWORD Unknown0
,
1152 DPRINT1("SetConsolePalette(0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
, Unknown2
);
1153 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1162 SetLastConsoleEventActive (VOID
)
1167 DPRINT1("SetLastConsoleEventActive() UNIMPLEMENTED!\n");
1168 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1177 ShowConsoleCursor (DWORD Unknown0
,
1183 DPRINT1("ShowConsoleCursor(0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
);
1184 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1190 * FUNCTION: Checks whether the given handle is a valid console handle.
1192 * Handle - Handle to be checked
1194 * TRUE: Handle is a valid console handle
1195 * FALSE: Handle is not a valid console handle.
1196 * STATUS: Officially undocumented
1201 VerifyConsoleIoHandle(HANDLE Handle
)
1203 CSR_API_MESSAGE Request
; ULONG CsrRequest
;
1207 CsrRequest
= MAKE_CSR_API(VERIFY_HANDLE
, CSR_NATIVE
);
1208 Request
.Data
.VerifyHandleRequest
.Handle
= Handle
;
1209 Status
= CsrClientCallServer(&Request
,
1212 sizeof(CSR_API_MESSAGE
));
1213 if (!NT_SUCCESS(Status
))
1215 SetLastErrorByStatus(Status
);
1219 return (BOOL
)NT_SUCCESS(Request
.Status
);
1227 WriteConsoleInputVDMA (DWORD Unknown0
,
1232 DPRINT1("WriteConsoleInputVDMA(0x%x, 0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
, Unknown2
, Unknown3
);
1233 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1242 WriteConsoleInputVDMW (DWORD Unknown0
,
1247 DPRINT1("WriteConsoleInputVDMW(0x%x, 0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
, Unknown2
, Unknown3
);
1248 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1257 CloseConsoleHandle(HANDLE Handle
)
1262 CSR_API_MESSAGE Request
; ULONG CsrRequest
;
1266 CsrRequest
= MAKE_CSR_API(CLOSE_HANDLE
, CSR_NATIVE
);
1267 Request
.Data
.CloseHandleRequest
.Handle
= Handle
;
1268 Status
= CsrClientCallServer(&Request
,
1271 sizeof(CSR_API_MESSAGE
));
1272 if (!NT_SUCCESS(Status
))
1274 SetLastErrorByStatus(Status
);
1285 GetStdHandle(DWORD nStdHandle
)
1287 * FUNCTION: Get a handle for the standard input, standard output
1288 * and a standard error device.
1290 * nStdHandle - Specifies the device for which to return the handle.
1291 * RETURNS: If the function succeeds, the return value is the handle
1292 * of the specified device. Otherwise the value is INVALID_HANDLE_VALUE.
1295 PRTL_USER_PROCESS_PARAMETERS Ppb
;
1297 Ppb
= NtCurrentPeb()->ProcessParameters
;
1300 case STD_INPUT_HANDLE
:
1301 return Ppb
->StandardInput
;
1303 case STD_OUTPUT_HANDLE
:
1304 return Ppb
->StandardOutput
;
1306 case STD_ERROR_HANDLE
:
1307 return Ppb
->StandardError
;
1310 SetLastError (ERROR_INVALID_PARAMETER
);
1311 return INVALID_HANDLE_VALUE
;
1319 SetStdHandle(DWORD nStdHandle
,
1322 * FUNCTION: Set the handle for the standard input, standard output or
1323 * the standard error device.
1325 * nStdHandle - Specifies the handle to be set.
1326 * hHandle - The handle to set.
1327 * RETURNS: TRUE if the function succeeds, FALSE otherwise.
1330 PRTL_USER_PROCESS_PARAMETERS Ppb
;
1332 /* no need to check if hHandle == INVALID_HANDLE_VALUE */
1334 Ppb
= NtCurrentPeb()->ProcessParameters
;
1338 case STD_INPUT_HANDLE
:
1339 Ppb
->StandardInput
= hHandle
;
1342 case STD_OUTPUT_HANDLE
:
1343 Ppb
->StandardOutput
= hHandle
;
1346 case STD_ERROR_HANDLE
:
1347 Ppb
->StandardError
= hHandle
;
1351 /* windows for whatever reason sets the last error to ERROR_INVALID_HANDLE here */
1352 SetLastError (ERROR_INVALID_HANDLE
);
1358 IntWriteConsole(HANDLE hConsoleOutput
,
1360 DWORD nNumberOfCharsToWrite
,
1361 LPDWORD lpNumberOfCharsWritten
,
1365 PCSR_API_MESSAGE Request
;
1369 ULONG SizeBytes
, CharSize
;
1372 CharSize
= (bUnicode
? sizeof(WCHAR
) : sizeof(CHAR
));
1373 Request
= RtlAllocateHeap(RtlGetProcessHeap(), 0,
1374 max(sizeof(CSR_API_MESSAGE
),
1375 CSR_API_MESSAGE_HEADER_SIZE(CSRSS_WRITE_CONSOLE
)
1376 + min(nNumberOfCharsToWrite
, CSRSS_MAX_WRITE_CONSOLE
/ CharSize
) * CharSize
));
1377 if (Request
== NULL
)
1379 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1383 CsrRequest
= MAKE_CSR_API(WRITE_CONSOLE
, CSR_CONSOLE
);
1385 while(nNumberOfCharsToWrite
> 0)
1387 Request
->Data
.WriteConsoleRequest
.ConsoleHandle
= hConsoleOutput
;
1388 Request
->Data
.WriteConsoleRequest
.Unicode
= bUnicode
;
1390 nChars
= (USHORT
)min(nNumberOfCharsToWrite
, CSRSS_MAX_WRITE_CONSOLE
/ CharSize
);
1391 Request
->Data
.WriteConsoleRequest
.NrCharactersToWrite
= nChars
;
1393 SizeBytes
= nChars
* CharSize
;
1395 memcpy(Request
->Data
.WriteConsoleRequest
.Buffer
, lpBuffer
, SizeBytes
);
1397 Status
= CsrClientCallServer(Request
,
1400 max(sizeof(CSR_API_MESSAGE
), CSR_API_MESSAGE_HEADER_SIZE(CSRSS_WRITE_CONSOLE
) + SizeBytes
));
1402 if(!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
->Status
))
1404 RtlFreeHeap(RtlGetProcessHeap(), 0, Request
);
1405 SetLastErrorByStatus(Status
);
1409 nNumberOfCharsToWrite
-= nChars
;
1410 lpBuffer
= (PVOID
)((ULONG_PTR
)lpBuffer
+ (ULONG_PTR
)SizeBytes
);
1411 Written
+= Request
->Data
.WriteConsoleRequest
.NrCharactersWritten
;
1414 if(lpNumberOfCharsWritten
!= NULL
)
1416 *lpNumberOfCharsWritten
= Written
;
1418 RtlFreeHeap(RtlGetProcessHeap(), 0, Request
);
1424 /*--------------------------------------------------------------
1430 WriteConsoleA(HANDLE hConsoleOutput
,
1431 CONST VOID
*lpBuffer
,
1432 DWORD nNumberOfCharsToWrite
,
1433 LPDWORD lpNumberOfCharsWritten
,
1436 return IntWriteConsole(hConsoleOutput
,
1438 nNumberOfCharsToWrite
,
1439 lpNumberOfCharsWritten
,
1445 /*--------------------------------------------------------------
1452 HANDLE hConsoleOutput
,
1453 CONST VOID
*lpBuffer
,
1454 DWORD nNumberOfCharsToWrite
,
1455 LPDWORD lpNumberOfCharsWritten
,
1459 return IntWriteConsole(hConsoleOutput
,
1461 nNumberOfCharsToWrite
,
1462 lpNumberOfCharsWritten
,
1469 IntReadConsole(HANDLE hConsoleInput
,
1471 DWORD nNumberOfCharsToRead
,
1472 LPDWORD lpNumberOfCharsRead
,
1473 PCONSOLE_READCONSOLE_CONTROL lpReserved
,
1476 PCSR_API_MESSAGE Request
;
1479 ULONG CharSize
, CharsRead
= 0;
1481 CharSize
= (bUnicode
? sizeof(WCHAR
) : sizeof(CHAR
));
1482 Request
= RtlAllocateHeap(RtlGetProcessHeap(), 0,
1483 max(sizeof(CSR_API_MESSAGE
),
1484 CSR_API_MESSAGE_HEADER_SIZE(CSRSS_READ_CONSOLE
)
1485 + min(nNumberOfCharsToRead
, CSRSS_MAX_READ_CONSOLE
/ CharSize
) * CharSize
));
1486 if (Request
== NULL
)
1488 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1492 Request
->Status
= STATUS_SUCCESS
;
1493 CsrRequest
= MAKE_CSR_API(READ_CONSOLE
, CSR_CONSOLE
);
1497 if(Request
->Status
== STATUS_PENDING
)
1499 Status
= NtWaitForSingleObject(Request
->Data
.ReadConsoleRequest
.EventHandle
, FALSE
, 0);
1500 if(!NT_SUCCESS(Status
))
1502 DPRINT1("Wait for console input failed!\n");
1507 Request
->Data
.ReadConsoleRequest
.ConsoleHandle
= hConsoleInput
;
1508 Request
->Data
.ReadConsoleRequest
.Unicode
= bUnicode
;
1509 Request
->Data
.ReadConsoleRequest
.NrCharactersToRead
= (WORD
)min(nNumberOfCharsToRead
, CSRSS_MAX_READ_CONSOLE
/ CharSize
);
1510 Request
->Data
.ReadConsoleRequest
.nCharsCanBeDeleted
= (WORD
)CharsRead
;
1511 Status
= CsrClientCallServer(Request
,
1514 max(sizeof(CSR_API_MESSAGE
),
1515 CSR_API_MESSAGE_HEADER_SIZE(CSRSS_READ_CONSOLE
)
1516 + Request
->Data
.ReadConsoleRequest
.NrCharactersToRead
* CharSize
));
1518 if(!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
->Status
))
1520 DPRINT1("CSR returned error in ReadConsole\n");
1521 RtlFreeHeap(RtlGetProcessHeap(), 0, Request
);
1522 SetLastErrorByStatus(Status
);
1526 nNumberOfCharsToRead
-= Request
->Data
.ReadConsoleRequest
.NrCharactersRead
;
1527 memcpy((PVOID
)((ULONG_PTR
)lpBuffer
+ (ULONG_PTR
)(CharsRead
* CharSize
)),
1528 Request
->Data
.ReadConsoleRequest
.Buffer
,
1529 Request
->Data
.ReadConsoleRequest
.NrCharactersRead
* CharSize
);
1530 CharsRead
+= Request
->Data
.ReadConsoleRequest
.NrCharactersRead
;
1532 if(Request
->Status
== STATUS_NOTIFY_CLEANUP
)
1537 nNumberOfCharsToRead
++;
1539 Request
->Status
= STATUS_PENDING
;
1541 } while(Request
->Status
== STATUS_PENDING
&& nNumberOfCharsToRead
> 0);
1543 if(lpNumberOfCharsRead
!= NULL
)
1545 *lpNumberOfCharsRead
= CharsRead
;
1548 RtlFreeHeap(RtlGetProcessHeap(), 0, Request
);
1554 /*--------------------------------------------------------------
1560 ReadConsoleA(HANDLE hConsoleInput
,
1562 DWORD nNumberOfCharsToRead
,
1563 LPDWORD lpNumberOfCharsRead
,
1564 PCONSOLE_READCONSOLE_CONTROL pInputControl
)
1566 return IntReadConsole(hConsoleInput
,
1568 nNumberOfCharsToRead
,
1569 lpNumberOfCharsRead
,
1575 /*--------------------------------------------------------------
1581 ReadConsoleW(HANDLE hConsoleInput
,
1583 DWORD nNumberOfCharsToRead
,
1584 LPDWORD lpNumberOfCharsRead
,
1585 PCONSOLE_READCONSOLE_CONTROL pInputControl
)
1587 return IntReadConsole(hConsoleInput
,
1589 nNumberOfCharsToRead
,
1590 lpNumberOfCharsRead
,
1596 /*--------------------------------------------------------------
1601 BOOL WINAPI
AllocConsole(VOID
)
1603 CSR_API_MESSAGE Request
; ULONG CsrRequest
;
1608 if(NtCurrentPeb()->ProcessParameters
->ConsoleHandle
)
1610 DPRINT("AllocConsole: Allocate duplicate console to the same Process\n");
1611 SetLastErrorByStatus (STATUS_OBJECT_NAME_EXISTS
);
1615 Request
.Data
.AllocConsoleRequest
.CtrlDispatcher
= ConsoleControlDispatcher
;
1616 Request
.Data
.AllocConsoleRequest
.ConsoleNeeded
= TRUE
;
1618 CsrRequest
= MAKE_CSR_API(ALLOC_CONSOLE
, CSR_CONSOLE
);
1619 Status
= CsrClientCallServer( &Request
, NULL
, CsrRequest
, sizeof( CSR_API_MESSAGE
) );
1620 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Request
.Status
) )
1622 SetLastErrorByStatus ( Status
);
1625 NtCurrentPeb()->ProcessParameters
->ConsoleHandle
= Request
.Data
.AllocConsoleRequest
.Console
;
1626 SetStdHandle( STD_INPUT_HANDLE
, Request
.Data
.AllocConsoleRequest
.InputHandle
);
1627 SetStdHandle( STD_OUTPUT_HANDLE
, Request
.Data
.AllocConsoleRequest
.OutputHandle
);
1628 hStdError
= DuplicateConsoleHandle(Request
.Data
.AllocConsoleRequest
.OutputHandle
,
1631 DUPLICATE_SAME_ACCESS
);
1632 SetStdHandle( STD_ERROR_HANDLE
, hStdError
);
1637 /*--------------------------------------------------------------
1642 BOOL WINAPI
FreeConsole(VOID
)
1644 // AG: I'm not sure if this is correct (what happens to std handles?)
1645 // but I just tried to reverse what AllocConsole() does...
1647 CSR_API_MESSAGE Request
; ULONG CsrRequest
;
1651 CsrRequest
= MAKE_CSR_API(FREE_CONSOLE
, CSR_CONSOLE
);
1652 Status
= CsrClientCallServer( &Request
, NULL
, CsrRequest
, sizeof( CSR_API_MESSAGE
) );
1653 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Request
.Status
) )
1655 SetLastErrorByStatus ( Status
);
1659 NtCurrentPeb()->ProcessParameters
->ConsoleHandle
= NULL
;
1664 /*--------------------------------------------------------------
1665 * GetConsoleScreenBufferInfo
1671 GetConsoleScreenBufferInfo(
1672 HANDLE hConsoleOutput
,
1673 PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo
1676 CSR_API_MESSAGE Request
; ULONG CsrRequest
;
1680 CsrRequest
= MAKE_CSR_API(SCREEN_BUFFER_INFO
, CSR_CONSOLE
);
1681 Request
.Data
.ScreenBufferInfoRequest
.ConsoleHandle
= hConsoleOutput
;
1682 Status
= CsrClientCallServer( &Request
, NULL
, CsrRequest
, sizeof( CSR_API_MESSAGE
) );
1683 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Request
.Status
) )
1685 SetLastErrorByStatus ( Status
);
1688 *lpConsoleScreenBufferInfo
= Request
.Data
.ScreenBufferInfoRequest
.Info
;
1693 /*--------------------------------------------------------------
1694 * SetConsoleCursorPosition
1700 SetConsoleCursorPosition(
1701 HANDLE hConsoleOutput
,
1702 COORD dwCursorPosition
1705 CSR_API_MESSAGE Request
; ULONG CsrRequest
;
1709 CsrRequest
= MAKE_CSR_API(SET_CURSOR
, CSR_CONSOLE
);
1710 Request
.Data
.SetCursorRequest
.ConsoleHandle
= hConsoleOutput
;
1711 Request
.Data
.SetCursorRequest
.Position
= dwCursorPosition
;
1712 Status
= CsrClientCallServer( &Request
, NULL
, CsrRequest
, sizeof( CSR_API_MESSAGE
) );
1713 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Request
.Status
) )
1715 SetLastErrorByStatus ( Status
);
1723 IntFillConsoleOutputCharacter(HANDLE hConsoleOutput
,
1727 LPDWORD lpNumberOfCharsWritten
,
1730 CSR_API_MESSAGE Request
; ULONG CsrRequest
;
1734 CsrRequest
= MAKE_CSR_API(FILL_OUTPUT
, CSR_CONSOLE
);
1735 Request
.Data
.FillOutputRequest
.ConsoleHandle
= hConsoleOutput
;
1736 Request
.Data
.FillOutputRequest
.Unicode
= bUnicode
;
1738 Request
.Data
.FillOutputRequest
.Char
.UnicodeChar
= *((WCHAR
*)cCharacter
);
1740 Request
.Data
.FillOutputRequest
.Char
.AsciiChar
= *((CHAR
*)cCharacter
);
1741 Request
.Data
.FillOutputRequest
.Position
= dwWriteCoord
;
1742 Request
.Data
.FillOutputRequest
.Length
= (WORD
)nLength
;
1743 Status
= CsrClientCallServer(&Request
, NULL
,
1745 sizeof(CSR_API_MESSAGE
));
1747 if(!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
1749 SetLastErrorByStatus(Status
);
1753 if(lpNumberOfCharsWritten
!= NULL
)
1755 *lpNumberOfCharsWritten
= Request
.Data
.FillOutputRequest
.NrCharactersWritten
;
1761 /*--------------------------------------------------------------
1762 * FillConsoleOutputCharacterA
1767 FillConsoleOutputCharacterA(
1768 HANDLE hConsoleOutput
,
1772 LPDWORD lpNumberOfCharsWritten
1775 return IntFillConsoleOutputCharacter(hConsoleOutput
,
1779 lpNumberOfCharsWritten
,
1784 /*--------------------------------------------------------------
1785 * FillConsoleOutputCharacterW
1791 FillConsoleOutputCharacterW(
1792 HANDLE hConsoleOutput
,
1796 LPDWORD lpNumberOfCharsWritten
1799 return IntFillConsoleOutputCharacter(hConsoleOutput
,
1803 lpNumberOfCharsWritten
,
1809 IntPeekConsoleInput(HANDLE hConsoleInput
,
1810 PINPUT_RECORD lpBuffer
,
1812 LPDWORD lpNumberOfEventsRead
,
1815 CSR_API_MESSAGE Request
; ULONG CsrRequest
;
1816 PCSR_CAPTURE_BUFFER CaptureBuffer
;
1820 if(lpBuffer
== NULL
)
1822 SetLastError(ERROR_INVALID_PARAMETER
);
1826 Size
= nLength
* sizeof(INPUT_RECORD
);
1828 /* Allocate a Capture Buffer */
1829 DPRINT("IntPeekConsoleInput: %lx %p\n", Size
, lpNumberOfEventsRead
);
1830 CaptureBuffer
= CsrAllocateCaptureBuffer(1, Size
);
1832 /* Allocate space in the Buffer */
1833 CsrCaptureMessageBuffer(CaptureBuffer
,
1836 (PVOID
*)&Request
.Data
.PeekConsoleInputRequest
.InputRecord
);
1838 /* Set up the data to send to the Console Server */
1839 CsrRequest
= MAKE_CSR_API(PEEK_CONSOLE_INPUT
, CSR_CONSOLE
);
1840 Request
.Data
.PeekConsoleInputRequest
.ConsoleHandle
= hConsoleInput
;
1841 Request
.Data
.PeekConsoleInputRequest
.Unicode
= bUnicode
;
1842 Request
.Data
.PeekConsoleInputRequest
.Length
= nLength
;
1844 /* Call the server */
1845 Status
= CsrClientCallServer(&Request
,
1848 sizeof(CSR_API_MESSAGE
));
1849 DPRINT("Server returned: %x\n", Request
.Status
);
1851 /* Check for success*/
1852 if (NT_SUCCESS(Request
.Status
))
1854 /* Return the number of events read */
1855 DPRINT("Events read: %lx\n", Request
.Data
.PeekConsoleInputRequest
.Length
);
1856 *lpNumberOfEventsRead
= Request
.Data
.PeekConsoleInputRequest
.Length
;
1858 /* Copy into the buffer */
1859 DPRINT("Copying to buffer\n");
1860 RtlCopyMemory(lpBuffer
,
1861 Request
.Data
.PeekConsoleInputRequest
.InputRecord
,
1862 sizeof(INPUT_RECORD
) * *lpNumberOfEventsRead
);
1867 *lpNumberOfEventsRead
= 0;
1868 SetLastErrorByStatus(Request
.Status
);
1871 /* Release the capture buffer */
1872 CsrFreeCaptureBuffer(CaptureBuffer
);
1874 /* Return TRUE or FALSE */
1875 return NT_SUCCESS(Request
.Status
);
1878 /*--------------------------------------------------------------
1886 HANDLE hConsoleInput
,
1887 PINPUT_RECORD lpBuffer
,
1889 LPDWORD lpNumberOfEventsRead
1892 return IntPeekConsoleInput(hConsoleInput
, lpBuffer
, nLength
,
1893 lpNumberOfEventsRead
, FALSE
);
1897 /*--------------------------------------------------------------
1905 HANDLE hConsoleInput
,
1906 PINPUT_RECORD lpBuffer
,
1908 LPDWORD lpNumberOfEventsRead
1911 return IntPeekConsoleInput(hConsoleInput
, lpBuffer
, nLength
,
1912 lpNumberOfEventsRead
, TRUE
);
1917 IntReadConsoleInput(HANDLE hConsoleInput
,
1918 PINPUT_RECORD lpBuffer
,
1920 LPDWORD lpNumberOfEventsRead
,
1923 CSR_API_MESSAGE Request
; ULONG CsrRequest
;
1928 CsrRequest
= MAKE_CSR_API(READ_INPUT
, CSR_CONSOLE
);
1932 Request
.Data
.ReadInputRequest
.ConsoleHandle
= hConsoleInput
;
1933 Request
.Data
.ReadInputRequest
.Unicode
= bUnicode
;
1934 Status
= CsrClientCallServer(&Request
, NULL
,
1936 sizeof(CSR_API_MESSAGE
));
1937 if(!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
1941 /* we couldn't read a single record, fail */
1942 SetLastErrorByStatus(Status
);
1947 /* FIXME - fail gracefully in case we already read at least one record? */
1951 else if(Status
== STATUS_PENDING
)
1955 Status
= NtWaitForSingleObject(Request
.Data
.ReadInputRequest
.Event
, FALSE
, 0);
1956 if(!NT_SUCCESS(Status
))
1958 SetLastErrorByStatus(Status
);
1964 /* nothing more to read (waiting for more input??), let's just bail */
1970 lpBuffer
[Read
++] = Request
.Data
.ReadInputRequest
.Input
;
1973 if(!Request
.Data
.ReadInputRequest
.MoreEvents
)
1975 /* nothing more to read, bail */
1981 if(lpNumberOfEventsRead
!= NULL
)
1983 *lpNumberOfEventsRead
= Read
;
1990 /*--------------------------------------------------------------
1996 ReadConsoleInputA(HANDLE hConsoleInput
,
1997 PINPUT_RECORD lpBuffer
,
1999 LPDWORD lpNumberOfEventsRead
)
2001 return IntReadConsoleInput(hConsoleInput
, lpBuffer
, nLength
,
2002 lpNumberOfEventsRead
, FALSE
);
2006 /*--------------------------------------------------------------
2014 HANDLE hConsoleInput
,
2015 PINPUT_RECORD lpBuffer
,
2017 LPDWORD lpNumberOfEventsRead
2020 return IntReadConsoleInput(hConsoleInput
, lpBuffer
, nLength
,
2021 lpNumberOfEventsRead
, TRUE
);
2026 IntWriteConsoleInput(HANDLE hConsoleInput
,
2027 PINPUT_RECORD lpBuffer
,
2029 LPDWORD lpNumberOfEventsWritten
,
2032 CSR_API_MESSAGE Request
; ULONG CsrRequest
;
2033 PCSR_CAPTURE_BUFFER CaptureBuffer
;
2037 if(lpBuffer
== NULL
)
2039 SetLastError(ERROR_INVALID_PARAMETER
);
2043 Size
= nLength
* sizeof(INPUT_RECORD
);
2045 /* Allocate a Capture Buffer */
2046 DPRINT("IntWriteConsoleInput: %lx %p\n", Size
, lpNumberOfEventsWritten
);
2047 CaptureBuffer
= CsrAllocateCaptureBuffer(1, Size
);
2049 /* Allocate space in the Buffer */
2050 CsrCaptureMessageBuffer(CaptureBuffer
,
2053 (PVOID
*)&Request
.Data
.WriteConsoleInputRequest
.InputRecord
);
2055 /* Set up the data to send to the Console Server */
2056 CsrRequest
= MAKE_CSR_API(WRITE_CONSOLE_INPUT
, CSR_CONSOLE
);
2057 Request
.Data
.WriteConsoleInputRequest
.ConsoleHandle
= hConsoleInput
;
2058 Request
.Data
.WriteConsoleInputRequest
.Unicode
= bUnicode
;
2059 Request
.Data
.WriteConsoleInputRequest
.Length
= nLength
;
2061 /* Call the server */
2062 Status
= CsrClientCallServer(&Request
,
2065 sizeof(CSR_API_MESSAGE
));
2066 DPRINT("Server returned: %x\n", Request
.Status
);
2068 /* Check for success*/
2069 if (NT_SUCCESS(Request
.Status
))
2071 /* Return the number of events read */
2072 DPRINT("Events read: %lx\n", Request
.Data
.WriteConsoleInputRequest
.Length
);
2073 *lpNumberOfEventsWritten
= Request
.Data
.WriteConsoleInputRequest
.Length
;
2078 *lpNumberOfEventsWritten
= 0;
2079 SetLastErrorByStatus(Request
.Status
);
2082 /* Release the capture buffer */
2083 CsrFreeCaptureBuffer(CaptureBuffer
);
2085 /* Return TRUE or FALSE */
2086 return NT_SUCCESS(Request
.Status
);
2090 /*--------------------------------------------------------------
2091 * WriteConsoleInputA
2098 HANDLE hConsoleInput
,
2099 CONST INPUT_RECORD
*lpBuffer
,
2101 LPDWORD lpNumberOfEventsWritten
2104 return IntWriteConsoleInput(hConsoleInput
,
2105 (PINPUT_RECORD
)lpBuffer
,
2107 lpNumberOfEventsWritten
,
2112 /*--------------------------------------------------------------
2113 * WriteConsoleInputW
2120 HANDLE hConsoleInput
,
2121 CONST INPUT_RECORD
*lpBuffer
,
2123 LPDWORD lpNumberOfEventsWritten
2126 return IntWriteConsoleInput(hConsoleInput
,
2127 (PINPUT_RECORD
)lpBuffer
,
2129 lpNumberOfEventsWritten
,
2135 IntReadConsoleOutput(HANDLE hConsoleOutput
,
2136 PCHAR_INFO lpBuffer
,
2138 COORD dwBufferCoord
,
2139 PSMALL_RECT lpReadRegion
,
2142 CSR_API_MESSAGE Request
; ULONG CsrRequest
;
2143 PCSR_CAPTURE_BUFFER CaptureBuffer
;
2145 DWORD Size
, SizeX
, SizeY
;
2147 if(lpBuffer
== NULL
)
2149 SetLastError(ERROR_INVALID_PARAMETER
);
2153 Size
= dwBufferSize
.X
* dwBufferSize
.Y
* sizeof(CHAR_INFO
);
2155 /* Allocate a Capture Buffer */
2156 DPRINT("IntReadConsoleOutput: %lx %p\n", Size
, lpReadRegion
);
2157 CaptureBuffer
= CsrAllocateCaptureBuffer(1, Size
);
2159 /* Allocate space in the Buffer */
2160 CsrCaptureMessageBuffer(CaptureBuffer
,
2163 (PVOID
*)&Request
.Data
.ReadConsoleOutputRequest
.CharInfo
);
2165 /* Set up the data to send to the Console Server */
2166 CsrRequest
= MAKE_CSR_API(READ_CONSOLE_OUTPUT
, CSR_CONSOLE
);
2167 Request
.Data
.ReadConsoleOutputRequest
.ConsoleHandle
= hConsoleOutput
;
2168 Request
.Data
.ReadConsoleOutputRequest
.Unicode
= bUnicode
;
2169 Request
.Data
.ReadConsoleOutputRequest
.BufferSize
= dwBufferSize
;
2170 Request
.Data
.ReadConsoleOutputRequest
.BufferCoord
= dwBufferCoord
;
2171 Request
.Data
.ReadConsoleOutputRequest
.ReadRegion
= *lpReadRegion
;
2173 /* Call the server */
2174 Status
= CsrClientCallServer(&Request
,
2177 sizeof(CSR_API_MESSAGE
));
2178 DPRINT("Server returned: %x\n", Request
.Status
);
2180 /* Check for success*/
2181 if (NT_SUCCESS(Request
.Status
))
2183 /* Copy into the buffer */
2184 DPRINT("Copying to buffer\n");
2185 SizeX
= Request
.Data
.ReadConsoleOutputRequest
.ReadRegion
.Right
-
2186 Request
.Data
.ReadConsoleOutputRequest
.ReadRegion
.Left
+ 1;
2187 SizeY
= Request
.Data
.ReadConsoleOutputRequest
.ReadRegion
.Bottom
-
2188 Request
.Data
.ReadConsoleOutputRequest
.ReadRegion
.Top
+ 1;
2189 RtlCopyMemory(lpBuffer
,
2190 Request
.Data
.ReadConsoleOutputRequest
.CharInfo
,
2191 sizeof(CHAR_INFO
) * SizeX
* SizeY
);
2196 SetLastErrorByStatus(Request
.Status
);
2199 /* Return the read region */
2200 DPRINT("read region: %lx\n", Request
.Data
.ReadConsoleOutputRequest
.ReadRegion
);
2201 *lpReadRegion
= Request
.Data
.ReadConsoleOutputRequest
.ReadRegion
;
2203 /* Release the capture buffer */
2204 CsrFreeCaptureBuffer(CaptureBuffer
);
2206 /* Return TRUE or FALSE */
2207 return NT_SUCCESS(Request
.Status
);
2210 /*--------------------------------------------------------------
2211 * ReadConsoleOutputA
2218 HANDLE hConsoleOutput
,
2219 PCHAR_INFO lpBuffer
,
2221 COORD dwBufferCoord
,
2222 PSMALL_RECT lpReadRegion
2225 return IntReadConsoleOutput(hConsoleOutput
, lpBuffer
, dwBufferSize
,
2226 dwBufferCoord
, lpReadRegion
, FALSE
);
2230 /*--------------------------------------------------------------
2231 * ReadConsoleOutputW
2238 HANDLE hConsoleOutput
,
2239 PCHAR_INFO lpBuffer
,
2241 COORD dwBufferCoord
,
2242 PSMALL_RECT lpReadRegion
2245 return IntReadConsoleOutput(hConsoleOutput
, lpBuffer
, dwBufferSize
,
2246 dwBufferCoord
, lpReadRegion
, TRUE
);
2251 IntWriteConsoleOutput(HANDLE hConsoleOutput
,
2252 CONST CHAR_INFO
*lpBuffer
,
2254 COORD dwBufferCoord
,
2255 PSMALL_RECT lpWriteRegion
,
2258 CSR_API_MESSAGE Request
; ULONG CsrRequest
;
2259 PCSR_CAPTURE_BUFFER CaptureBuffer
;
2263 Size
= dwBufferSize
.Y
* dwBufferSize
.X
* sizeof(CHAR_INFO
);
2265 /* Allocate a Capture Buffer */
2266 DPRINT("IntWriteConsoleOutput: %lx %p\n", Size
, lpWriteRegion
);
2267 CaptureBuffer
= CsrAllocateCaptureBuffer(1, Size
);
2269 /* Allocate space in the Buffer */
2270 CsrCaptureMessageBuffer(CaptureBuffer
,
2273 (PVOID
*)&Request
.Data
.WriteConsoleOutputRequest
.CharInfo
);
2275 /* Copy from the buffer */
2276 RtlCopyMemory(Request
.Data
.WriteConsoleOutputRequest
.CharInfo
, lpBuffer
, Size
);
2278 /* Set up the data to send to the Console Server */
2279 CsrRequest
= MAKE_CSR_API(WRITE_CONSOLE_OUTPUT
, CSR_CONSOLE
);
2280 Request
.Data
.WriteConsoleOutputRequest
.ConsoleHandle
= hConsoleOutput
;
2281 Request
.Data
.WriteConsoleOutputRequest
.Unicode
= bUnicode
;
2282 Request
.Data
.WriteConsoleOutputRequest
.BufferSize
= dwBufferSize
;
2283 Request
.Data
.WriteConsoleOutputRequest
.BufferCoord
= dwBufferCoord
;
2284 Request
.Data
.WriteConsoleOutputRequest
.WriteRegion
= *lpWriteRegion
;
2286 /* Call the server */
2287 Status
= CsrClientCallServer(&Request
,
2290 sizeof(CSR_API_MESSAGE
));
2291 DPRINT("Server returned: %x\n", Request
.Status
);
2293 /* Check for success*/
2294 if (!NT_SUCCESS(Request
.Status
))
2297 SetLastErrorByStatus(Request
.Status
);
2300 /* Return the read region */
2301 DPRINT("read region: %lx\n", Request
.Data
.WriteConsoleOutputRequest
.WriteRegion
);
2302 *lpWriteRegion
= Request
.Data
.WriteConsoleOutputRequest
.WriteRegion
;
2304 /* Release the capture buffer */
2305 CsrFreeCaptureBuffer(CaptureBuffer
);
2307 /* Return TRUE or FALSE */
2308 return NT_SUCCESS(Request
.Status
);
2311 /*--------------------------------------------------------------
2312 * WriteConsoleOutputA
2317 WriteConsoleOutputA(HANDLE hConsoleOutput
,
2318 CONST CHAR_INFO
*lpBuffer
,
2320 COORD dwBufferCoord
,
2321 PSMALL_RECT lpWriteRegion
)
2323 return IntWriteConsoleOutput(hConsoleOutput
, lpBuffer
, dwBufferSize
,
2324 dwBufferCoord
, lpWriteRegion
, FALSE
);
2328 /*--------------------------------------------------------------
2329 * WriteConsoleOutputW
2335 WriteConsoleOutputW(
2336 HANDLE hConsoleOutput
,
2337 CONST CHAR_INFO
*lpBuffer
,
2339 COORD dwBufferCoord
,
2340 PSMALL_RECT lpWriteRegion
2343 return IntWriteConsoleOutput(hConsoleOutput
, lpBuffer
, dwBufferSize
,
2344 dwBufferCoord
, lpWriteRegion
, TRUE
);
2349 IntReadConsoleOutputCharacter(HANDLE hConsoleOutput
,
2353 LPDWORD lpNumberOfCharsRead
,
2356 PCSR_API_MESSAGE Request
; ULONG CsrRequest
;
2358 ULONG nChars
, SizeBytes
, CharSize
;
2359 DWORD CharsRead
= 0;
2361 CharSize
= (bUnicode
? sizeof(WCHAR
) : sizeof(CHAR
));
2363 nChars
= min(nLength
, CSRSS_MAX_READ_CONSOLE_OUTPUT_CHAR
) / CharSize
;
2364 SizeBytes
= nChars
* CharSize
;
2366 Request
= RtlAllocateHeap(RtlGetProcessHeap(), 0,
2367 max(sizeof(CSR_API_MESSAGE
),
2368 CSR_API_MESSAGE_HEADER_SIZE(CSRSS_READ_CONSOLE_OUTPUT_CHAR
)
2369 + min (nChars
, CSRSS_MAX_READ_CONSOLE_OUTPUT_CHAR
/ CharSize
) * CharSize
));
2370 if (Request
== NULL
)
2372 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2376 CsrRequest
= MAKE_CSR_API(READ_CONSOLE_OUTPUT_CHAR
, CSR_CONSOLE
);
2377 Request
->Data
.ReadConsoleOutputCharRequest
.ReadCoord
= dwReadCoord
;
2383 Request
->Data
.ReadConsoleOutputCharRequest
.ConsoleHandle
= hConsoleOutput
;
2384 Request
->Data
.ReadConsoleOutputCharRequest
.Unicode
= bUnicode
;
2385 Request
->Data
.ReadConsoleOutputCharRequest
.NumCharsToRead
= min(nLength
, nChars
);
2386 SizeBytes
= Request
->Data
.ReadConsoleOutputCharRequest
.NumCharsToRead
* CharSize
;
2388 Status
= CsrClientCallServer(Request
,
2391 max (sizeof(CSR_API_MESSAGE
),
2392 CSR_API_MESSAGE_HEADER_SIZE(CSRSS_READ_CONSOLE_OUTPUT_CHAR
) + SizeBytes
));
2393 if(!NT_SUCCESS(Status
) || !NT_SUCCESS(Request
->Status
))
2395 RtlFreeHeap(RtlGetProcessHeap(), 0, Request
);
2396 SetLastErrorByStatus(Status
);
2400 BytesRead
= Request
->Data
.ReadConsoleOutputCharRequest
.CharsRead
* CharSize
;
2401 memcpy(lpCharacter
, Request
->Data
.ReadConsoleOutputCharRequest
.String
, BytesRead
);
2402 lpCharacter
= (PVOID
)((ULONG_PTR
)lpCharacter
+ (ULONG_PTR
)BytesRead
);
2403 CharsRead
+= Request
->Data
.ReadConsoleOutputCharRequest
.CharsRead
;
2404 nLength
-= Request
->Data
.ReadConsoleOutputCharRequest
.CharsRead
;
2406 Request
->Data
.ReadConsoleOutputCharRequest
.ReadCoord
= Request
->Data
.ReadConsoleOutputCharRequest
.EndCoord
;
2409 if(lpNumberOfCharsRead
!= NULL
)
2411 *lpNumberOfCharsRead
= CharsRead
;
2414 RtlFreeHeap(RtlGetProcessHeap(), 0, Request
);
2420 /*--------------------------------------------------------------
2421 * ReadConsoleOutputCharacterA
2427 ReadConsoleOutputCharacterA(
2428 HANDLE hConsoleOutput
,
2432 LPDWORD lpNumberOfCharsRead
2435 return IntReadConsoleOutputCharacter(hConsoleOutput
,
2439 lpNumberOfCharsRead
,
2444 /*--------------------------------------------------------------
2445 * ReadConsoleOutputCharacterW
2451 ReadConsoleOutputCharacterW(
2452 HANDLE hConsoleOutput
,
2456 LPDWORD lpNumberOfCharsRead
2459 return IntReadConsoleOutputCharacter(hConsoleOutput
,
2463 lpNumberOfCharsRead
,
2468 /*--------------------------------------------------------------
2469 * ReadConsoleOutputAttribute
2475 ReadConsoleOutputAttribute(
2476 HANDLE hConsoleOutput
,
2480 LPDWORD lpNumberOfAttrsRead
2483 PCSR_API_MESSAGE Request
; ULONG CsrRequest
;
2487 if (lpNumberOfAttrsRead
!= NULL
)
2488 *lpNumberOfAttrsRead
= nLength
;
2490 Request
= RtlAllocateHeap(RtlGetProcessHeap(), 0,
2491 max(sizeof(CSR_API_MESSAGE
),
2492 CSR_API_MESSAGE_HEADER_SIZE(CSRSS_READ_CONSOLE_OUTPUT_ATTRIB
)
2493 + min (nLength
, CSRSS_MAX_READ_CONSOLE_OUTPUT_ATTRIB
/ sizeof(WORD
)) * sizeof(WORD
)));
2494 if (Request
== NULL
)
2496 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2500 CsrRequest
= MAKE_CSR_API(READ_CONSOLE_OUTPUT_ATTRIB
, CSR_CONSOLE
);
2502 while (nLength
!= 0)
2504 Request
->Data
.ReadConsoleOutputAttribRequest
.ConsoleHandle
= hConsoleOutput
;
2505 Request
->Data
.ReadConsoleOutputAttribRequest
.ReadCoord
= dwReadCoord
;
2507 if (nLength
> CSRSS_MAX_READ_CONSOLE_OUTPUT_ATTRIB
/ sizeof(WORD
))
2508 Size
= CSRSS_MAX_READ_CONSOLE_OUTPUT_ATTRIB
/ sizeof(WCHAR
);
2512 Request
->Data
.ReadConsoleOutputAttribRequest
.NumAttrsToRead
= Size
;
2514 Status
= CsrClientCallServer(Request
,
2517 max (sizeof(CSR_API_MESSAGE
),
2518 CSR_API_MESSAGE_HEADER_SIZE(CSRSS_READ_CONSOLE_OUTPUT_ATTRIB
) + Size
* sizeof(WORD
)));
2519 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Request
->Status
))
2521 RtlFreeHeap(RtlGetProcessHeap(), 0, Request
);
2522 SetLastErrorByStatus(Status
);
2526 memcpy(lpAttribute
, Request
->Data
.ReadConsoleOutputAttribRequest
.Attribute
, Size
* sizeof(WORD
));
2527 lpAttribute
+= Size
;
2529 Request
->Data
.ReadConsoleOutputAttribRequest
.ReadCoord
= Request
->Data
.ReadConsoleOutputAttribRequest
.EndCoord
;
2532 RtlFreeHeap(RtlGetProcessHeap(), 0, Request
);
2539 IntWriteConsoleOutputCharacter(HANDLE hConsoleOutput
,
2543 LPDWORD lpNumberOfCharsWritten
,
2546 PCSR_API_MESSAGE Request
; ULONG CsrRequest
;
2548 ULONG SizeBytes
, CharSize
, nChars
;
2551 CharSize
= (bUnicode
? sizeof(WCHAR
) : sizeof(CHAR
));
2553 nChars
= min(nLength
, CSRSS_MAX_WRITE_CONSOLE_OUTPUT_CHAR
/ CharSize
);
2554 SizeBytes
= nChars
* CharSize
;
2556 Request
= RtlAllocateHeap(RtlGetProcessHeap(), 0,
2557 max (sizeof(CSR_API_MESSAGE
),
2558 CSR_API_MESSAGE_HEADER_SIZE(CSRSS_WRITE_CONSOLE_OUTPUT_CHAR
)
2559 + min (nChars
, CSRSS_MAX_WRITE_CONSOLE_OUTPUT_CHAR
/ CharSize
) * CharSize
));
2560 if (Request
== NULL
)
2562 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2566 CsrRequest
= MAKE_CSR_API(WRITE_CONSOLE_OUTPUT_CHAR
, CSR_CONSOLE
);
2567 Request
->Data
.WriteConsoleOutputCharRequest
.Coord
= dwWriteCoord
;
2573 Request
->Data
.WriteConsoleOutputCharRequest
.ConsoleHandle
= hConsoleOutput
;
2574 Request
->Data
.WriteConsoleOutputCharRequest
.Unicode
= bUnicode
;
2575 Request
->Data
.WriteConsoleOutputCharRequest
.Length
= (WORD
)min(nLength
, nChars
);
2576 BytesWrite
= Request
->Data
.WriteConsoleOutputCharRequest
.Length
* CharSize
;
2578 memcpy(Request
->Data
.WriteConsoleOutputCharRequest
.String
, lpCharacter
, BytesWrite
);
2580 Status
= CsrClientCallServer(Request
,
2583 max (sizeof(CSR_API_MESSAGE
),
2584 CSR_API_MESSAGE_HEADER_SIZE(CSRSS_WRITE_CONSOLE_OUTPUT_CHAR
) + BytesWrite
));
2586 if(!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
->Status
))
2588 RtlFreeHeap(RtlGetProcessHeap(), 0, Request
);
2589 SetLastErrorByStatus(Status
);
2593 nLength
-= Request
->Data
.WriteConsoleOutputCharRequest
.NrCharactersWritten
;
2594 lpCharacter
= (PVOID
)((ULONG_PTR
)lpCharacter
+ (ULONG_PTR
)(Request
->Data
.WriteConsoleOutputCharRequest
.NrCharactersWritten
* CharSize
));
2595 Written
+= Request
->Data
.WriteConsoleOutputCharRequest
.NrCharactersWritten
;
2597 Request
->Data
.WriteConsoleOutputCharRequest
.Coord
= Request
->Data
.WriteConsoleOutputCharRequest
.EndCoord
;
2600 if(lpNumberOfCharsWritten
!= NULL
)
2602 *lpNumberOfCharsWritten
= Written
;
2605 RtlFreeHeap(RtlGetProcessHeap(), 0, Request
);
2611 /*--------------------------------------------------------------
2612 * WriteConsoleOutputCharacterA
2617 WriteConsoleOutputCharacterA(HANDLE hConsoleOutput
,
2621 LPDWORD lpNumberOfCharsWritten
)
2623 return IntWriteConsoleOutputCharacter(hConsoleOutput
,
2627 lpNumberOfCharsWritten
,
2632 /*--------------------------------------------------------------
2633 * WriteConsoleOutputCharacterW
2638 WriteConsoleOutputCharacterW(HANDLE hConsoleOutput
,
2639 LPCWSTR lpCharacter
,
2642 LPDWORD lpNumberOfCharsWritten
)
2644 return IntWriteConsoleOutputCharacter(hConsoleOutput
,
2648 lpNumberOfCharsWritten
,
2653 /*--------------------------------------------------------------
2654 * WriteConsoleOutputAttribute
2660 WriteConsoleOutputAttribute(
2661 HANDLE hConsoleOutput
,
2662 CONST WORD
*lpAttribute
,
2665 LPDWORD lpNumberOfAttrsWritten
2668 PCSR_API_MESSAGE Request
; ULONG CsrRequest
;
2672 Request
= RtlAllocateHeap(RtlGetProcessHeap(), 0,
2673 max (sizeof(CSR_API_MESSAGE
),
2674 CSR_API_MESSAGE_HEADER_SIZE(CSRSS_WRITE_CONSOLE_OUTPUT_ATTRIB
)
2675 + min(nLength
, CSRSS_MAX_WRITE_CONSOLE_OUTPUT_ATTRIB
/ sizeof(WORD
)) * sizeof(WORD
)));
2676 if (Request
== NULL
)
2678 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2682 CsrRequest
= MAKE_CSR_API(WRITE_CONSOLE_OUTPUT_ATTRIB
, CSR_CONSOLE
);
2683 Request
->Data
.WriteConsoleOutputAttribRequest
.Coord
= dwWriteCoord
;
2685 if( lpNumberOfAttrsWritten
)
2686 *lpNumberOfAttrsWritten
= nLength
;
2689 Size
= (WORD
)min(nLength
, CSRSS_MAX_WRITE_CONSOLE_OUTPUT_ATTRIB
/ sizeof(WORD
));
2690 Request
->Data
.WriteConsoleOutputAttribRequest
.ConsoleHandle
= hConsoleOutput
;
2691 Request
->Data
.WriteConsoleOutputAttribRequest
.Length
= Size
;
2692 memcpy(Request
->Data
.WriteConsoleOutputAttribRequest
.Attribute
, lpAttribute
, Size
* sizeof(WORD
));
2694 Status
= CsrClientCallServer( Request
,
2697 max (sizeof(CSR_API_MESSAGE
),
2698 CSR_API_MESSAGE_HEADER_SIZE(CSRSS_WRITE_CONSOLE_OUTPUT_ATTRIB
) + Size
* sizeof(WORD
)));
2700 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Request
->Status
) )
2702 RtlFreeHeap(RtlGetProcessHeap(), 0, Request
);
2703 SetLastErrorByStatus ( Status
);
2707 lpAttribute
+= Size
;
2708 Request
->Data
.WriteConsoleOutputAttribRequest
.Coord
= Request
->Data
.WriteConsoleOutputAttribRequest
.EndCoord
;
2711 RtlFreeHeap(RtlGetProcessHeap(), 0, Request
);
2717 /*--------------------------------------------------------------
2718 * FillConsoleOutputAttribute
2724 FillConsoleOutputAttribute(
2725 HANDLE hConsoleOutput
,
2729 LPDWORD lpNumberOfAttrsWritten
2732 CSR_API_MESSAGE Request
; ULONG CsrRequest
;
2736 CsrRequest
= MAKE_CSR_API(FILL_OUTPUT_ATTRIB
, CSR_CONSOLE
);
2737 Request
.Data
.FillOutputAttribRequest
.ConsoleHandle
= hConsoleOutput
;
2738 Request
.Data
.FillOutputAttribRequest
.Attribute
= (CHAR
)wAttribute
;
2739 Request
.Data
.FillOutputAttribRequest
.Coord
= dwWriteCoord
;
2740 Request
.Data
.FillOutputAttribRequest
.Length
= (WORD
)nLength
;
2741 Status
= CsrClientCallServer( &Request
, NULL
, CsrRequest
, sizeof( CSR_API_MESSAGE
) );
2742 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Request
.Status
) )
2744 SetLastErrorByStatus ( Status
);
2747 if( lpNumberOfAttrsWritten
)
2748 *lpNumberOfAttrsWritten
= nLength
;
2753 /*--------------------------------------------------------------
2761 HANDLE hConsoleHandle
,
2765 CSR_API_MESSAGE Request
; ULONG CsrRequest
;
2769 CsrRequest
= MAKE_CSR_API(GET_CONSOLE_MODE
, CSR_CONSOLE
);
2770 Request
.Data
.GetConsoleModeRequest
.ConsoleHandle
= hConsoleHandle
;
2771 Status
= CsrClientCallServer( &Request
, NULL
, CsrRequest
, sizeof( CSR_API_MESSAGE
) );
2772 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Request
.Status
) )
2774 SetLastErrorByStatus ( Status
);
2777 *lpMode
= Request
.Data
.GetConsoleModeRequest
.ConsoleMode
;
2782 /*--------------------------------------------------------------
2783 * GetNumberOfConsoleInputEvents
2789 GetNumberOfConsoleInputEvents(
2790 HANDLE hConsoleInput
,
2791 LPDWORD lpNumberOfEvents
2794 CSR_API_MESSAGE Request
; ULONG CsrRequest
;
2798 if(lpNumberOfEvents
== NULL
)
2800 SetLastError(ERROR_INVALID_PARAMETER
);
2804 CsrRequest
= MAKE_CSR_API(GET_NUM_INPUT_EVENTS
, CSR_CONSOLE
);
2805 Request
.Data
.GetNumInputEventsRequest
.ConsoleHandle
= hConsoleInput
;
2806 Status
= CsrClientCallServer(&Request
, NULL
, CsrRequest
, sizeof(CSR_API_MESSAGE
));
2807 if(!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
2809 SetLastErrorByStatus(Status
);
2813 *lpNumberOfEvents
= Request
.Data
.GetNumInputEventsRequest
.NumInputEvents
;
2819 /*--------------------------------------------------------------
2820 * GetLargestConsoleWindowSize
2826 GetLargestConsoleWindowSize(
2827 HANDLE hConsoleOutput
2830 COORD Coord
= {80,25};
2831 DPRINT1("GetLargestConsoleWindowSize(0x%x) UNIMPLEMENTED!\n", hConsoleOutput
);
2832 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2837 /*--------------------------------------------------------------
2838 * GetConsoleCursorInfo
2844 GetConsoleCursorInfo(
2845 HANDLE hConsoleOutput
,
2846 PCONSOLE_CURSOR_INFO lpConsoleCursorInfo
2849 CSR_API_MESSAGE Request
; ULONG CsrRequest
;
2853 CsrRequest
= MAKE_CSR_API(GET_CURSOR_INFO
, CSR_CONSOLE
);
2854 Request
.Data
.GetCursorInfoRequest
.ConsoleHandle
= hConsoleOutput
;
2855 Status
= CsrClientCallServer( &Request
, NULL
, CsrRequest
, sizeof( CSR_API_MESSAGE
) );
2857 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Request
.Status
) )
2859 SetLastErrorByStatus ( Status
);
2862 *lpConsoleCursorInfo
= Request
.Data
.GetCursorInfoRequest
.Info
;
2867 /*--------------------------------------------------------------
2868 * GetNumberOfConsoleMouseButtons
2874 GetNumberOfConsoleMouseButtons(
2875 LPDWORD lpNumberOfMouseButtons
2878 DPRINT1("GetNumberOfConsoleMouseButtons(0x%x) UNIMPLEMENTED!\n", lpNumberOfMouseButtons
);
2879 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2884 /*--------------------------------------------------------------
2892 HANDLE hConsoleHandle
,
2896 CSR_API_MESSAGE Request
; ULONG CsrRequest
;
2900 CsrRequest
= MAKE_CSR_API(SET_CONSOLE_MODE
, CSR_CONSOLE
);
2901 Request
.Data
.SetConsoleModeRequest
.ConsoleHandle
= hConsoleHandle
;
2902 Request
.Data
.SetConsoleModeRequest
.Mode
= dwMode
;
2903 Status
= CsrClientCallServer( &Request
, NULL
, CsrRequest
, sizeof( CSR_API_MESSAGE
) );
2904 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Request
.Status
) )
2906 SetLastErrorByStatus ( Status
);
2913 /*--------------------------------------------------------------
2914 * SetConsoleActiveScreenBuffer
2920 SetConsoleActiveScreenBuffer(
2921 HANDLE hConsoleOutput
2924 CSR_API_MESSAGE Request
; ULONG CsrRequest
;
2928 CsrRequest
= MAKE_CSR_API(SET_SCREEN_BUFFER
, CSR_CONSOLE
);
2929 Request
.Data
.SetScreenBufferRequest
.OutputHandle
= hConsoleOutput
;
2930 Status
= CsrClientCallServer( &Request
, NULL
, CsrRequest
, sizeof( CSR_API_MESSAGE
) );
2931 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Request
.Status
) )
2933 SetLastErrorByStatus ( Status
);
2940 /*--------------------------------------------------------------
2941 * FlushConsoleInputBuffer
2947 FlushConsoleInputBuffer(
2948 HANDLE hConsoleInput
2951 CSR_API_MESSAGE Request
; ULONG CsrRequest
;
2955 CsrRequest
= MAKE_CSR_API(FLUSH_INPUT_BUFFER
, CSR_CONSOLE
);
2956 Request
.Data
.FlushInputBufferRequest
.ConsoleInput
= hConsoleInput
;
2957 Status
= CsrClientCallServer( &Request
, NULL
, CsrRequest
, sizeof( CSR_API_MESSAGE
) );
2958 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Request
.Status
) )
2960 SetLastErrorByStatus ( Status
);
2967 /*--------------------------------------------------------------
2968 * SetConsoleScreenBufferSize
2974 SetConsoleScreenBufferSize(
2975 HANDLE hConsoleOutput
,
2979 DPRINT1("SetConsoleScreenBufferSize(0x%x, 0x%x) UNIMPLEMENTED!\n", hConsoleOutput
, dwSize
);
2980 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2984 /*--------------------------------------------------------------
2985 * SetConsoleCursorInfo
2991 SetConsoleCursorInfo(
2992 HANDLE hConsoleOutput
,
2993 CONST CONSOLE_CURSOR_INFO
*lpConsoleCursorInfo
2996 CSR_API_MESSAGE Request
; ULONG CsrRequest
;
3000 CsrRequest
= MAKE_CSR_API(SET_CURSOR_INFO
, CSR_CONSOLE
);
3001 Request
.Data
.SetCursorInfoRequest
.ConsoleHandle
= hConsoleOutput
;
3002 Request
.Data
.SetCursorInfoRequest
.Info
= *lpConsoleCursorInfo
;
3003 Status
= CsrClientCallServer( &Request
, NULL
, CsrRequest
, sizeof( CSR_API_MESSAGE
) );
3005 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Request
.Status
) )
3007 SetLastErrorByStatus ( Status
);
3015 IntScrollConsoleScreenBuffer(HANDLE hConsoleOutput
,
3016 const SMALL_RECT
*lpScrollRectangle
,
3017 const SMALL_RECT
*lpClipRectangle
,
3018 COORD dwDestinationOrigin
,
3019 const CHAR_INFO
*lpFill
,
3022 CSR_API_MESSAGE Request
; ULONG CsrRequest
;
3026 CsrRequest
= MAKE_CSR_API(SCROLL_CONSOLE_SCREEN_BUFFER
, CSR_CONSOLE
);
3027 Request
.Data
.ScrollConsoleScreenBufferRequest
.ConsoleHandle
= hConsoleOutput
;
3028 Request
.Data
.ScrollConsoleScreenBufferRequest
.Unicode
= bUnicode
;
3029 Request
.Data
.ScrollConsoleScreenBufferRequest
.ScrollRectangle
= *lpScrollRectangle
;
3031 if(lpClipRectangle
!= NULL
)
3033 Request
.Data
.ScrollConsoleScreenBufferRequest
.UseClipRectangle
= TRUE
;
3034 Request
.Data
.ScrollConsoleScreenBufferRequest
.ClipRectangle
= *lpClipRectangle
;
3038 Request
.Data
.ScrollConsoleScreenBufferRequest
.UseClipRectangle
= FALSE
;
3041 Request
.Data
.ScrollConsoleScreenBufferRequest
.DestinationOrigin
= dwDestinationOrigin
;
3042 Request
.Data
.ScrollConsoleScreenBufferRequest
.Fill
= *lpFill
;
3043 Status
= CsrClientCallServer(&Request
, NULL
,
3045 sizeof(CSR_API_MESSAGE
));
3047 if(!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
3049 SetLastErrorByStatus(Status
);
3057 /*--------------------------------------------------------------
3058 * ScrollConsoleScreenBufferA
3064 ScrollConsoleScreenBufferA(
3065 HANDLE hConsoleOutput
,
3066 CONST SMALL_RECT
*lpScrollRectangle
,
3067 CONST SMALL_RECT
*lpClipRectangle
,
3068 COORD dwDestinationOrigin
,
3069 CONST CHAR_INFO
*lpFill
3072 return IntScrollConsoleScreenBuffer(hConsoleOutput
,
3073 (PSMALL_RECT
)lpScrollRectangle
,
3074 (PSMALL_RECT
)lpClipRectangle
,
3075 dwDestinationOrigin
,
3081 /*--------------------------------------------------------------
3082 * ScrollConsoleScreenBufferW
3088 ScrollConsoleScreenBufferW(
3089 HANDLE hConsoleOutput
,
3090 CONST SMALL_RECT
*lpScrollRectangle
,
3091 CONST SMALL_RECT
*lpClipRectangle
,
3092 COORD dwDestinationOrigin
,
3093 CONST CHAR_INFO
*lpFill
3096 return IntScrollConsoleScreenBuffer(hConsoleOutput
,
3099 dwDestinationOrigin
,
3105 /*--------------------------------------------------------------
3106 * SetConsoleWindowInfo
3112 SetConsoleWindowInfo(
3113 HANDLE hConsoleOutput
,
3115 CONST SMALL_RECT
*lpConsoleWindow
3118 DPRINT1("SetConsoleWindowInfo(0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", hConsoleOutput
, bAbsolute
, lpConsoleWindow
);
3119 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3124 /*--------------------------------------------------------------
3125 * SetConsoleTextAttribute
3131 SetConsoleTextAttribute(
3132 HANDLE hConsoleOutput
,
3136 CSR_API_MESSAGE Request
; ULONG CsrRequest
;
3140 CsrRequest
= MAKE_CSR_API(SET_ATTRIB
, CSR_CONSOLE
);
3141 Request
.Data
.SetAttribRequest
.ConsoleHandle
= hConsoleOutput
;
3142 Request
.Data
.SetAttribRequest
.Attrib
= wAttributes
;
3143 Status
= CsrClientCallServer( &Request
, NULL
, CsrRequest
, sizeof( CSR_API_MESSAGE
) );
3144 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Request
.Status
) )
3146 SetLastErrorByStatus ( Status
);
3154 AddConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine
)
3156 if (HandlerRoutine
== NULL
)
3158 NtCurrentPeb()->ProcessParameters
->ConsoleFlags
= TRUE
;
3164 if (CtrlHandlers
== NULL
)
3166 CtrlHandlers
= RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY
,
3167 NrCtrlHandlers
* sizeof(PHANDLER_ROUTINE
));
3171 CtrlHandlers
= RtlReAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY
,
3172 (PVOID
)CtrlHandlers
,
3173 NrCtrlHandlers
* sizeof(PHANDLER_ROUTINE
));
3175 if (CtrlHandlers
== NULL
)
3178 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3181 CtrlHandlers
[NrCtrlHandlers
- 1] = HandlerRoutine
;
3188 RemoveConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine
)
3192 if (HandlerRoutine
== NULL
)
3194 NtCurrentPeb()->ProcessParameters
->ConsoleFlags
= FALSE
;
3199 for (i
= 0; i
< NrCtrlHandlers
; i
++)
3201 if ( ((void*)(CtrlHandlers
[i
])) == (void*)HandlerRoutine
)
3204 memmove(CtrlHandlers
+ i
, CtrlHandlers
+ i
+ 1,
3205 (NrCtrlHandlers
- i
) * sizeof(PHANDLER_ROUTINE
));
3207 RtlReAllocateHeap(RtlGetProcessHeap(),
3209 (PVOID
)CtrlHandlers
,
3210 NrCtrlHandlers
* sizeof(PHANDLER_ROUTINE
));
3215 SetLastError(ERROR_INVALID_PARAMETER
);
3224 SetConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine
,
3229 RtlEnterCriticalSection(&DllLock
);
3232 Ret
= AddConsoleCtrlHandler(HandlerRoutine
);
3236 Ret
= RemoveConsoleCtrlHandler(HandlerRoutine
);
3238 RtlLeaveCriticalSection(&DllLock
);
3243 /*--------------------------------------------------------------
3244 * GenerateConsoleCtrlEvent
3249 GenerateConsoleCtrlEvent(
3251 DWORD dwProcessGroupId
3254 CSR_API_MESSAGE Request
;
3258 if (dwCtrlEvent
!= CTRL_C_EVENT
&& dwCtrlEvent
!= CTRL_BREAK_EVENT
)
3260 SetLastError(ERROR_INVALID_PARAMETER
);
3264 CsrRequest
= MAKE_CSR_API(GENERATE_CTRL_EVENT
, CSR_CONSOLE
);
3265 Request
.Data
.GenerateCtrlEvent
.Event
= dwCtrlEvent
;
3266 Request
.Data
.GenerateCtrlEvent
.ProcessGroup
= dwProcessGroupId
;
3267 Status
= CsrClientCallServer(&Request
,
3270 sizeof(CSR_API_MESSAGE
));
3271 if(!NT_SUCCESS(Status
) || !(NT_SUCCESS(Status
= Request
.Status
)))
3273 SetLastErrorByStatus(Status
);
3281 /*--------------------------------------------------------------
3289 LPWSTR lpConsoleTitle
,
3293 PCSR_API_MESSAGE Request
; ULONG CsrRequest
;
3296 Request
= RtlAllocateHeap(RtlGetProcessHeap(), 0,
3297 CSR_API_MESSAGE_HEADER_SIZE(CSRSS_GET_TITLE
) + CSRSS_MAX_TITLE_LENGTH
* sizeof(WCHAR
));
3298 if (Request
== NULL
)
3300 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3304 CsrRequest
= MAKE_CSR_API(GET_TITLE
, CSR_CONSOLE
);
3306 Status
= CsrClientCallServer(Request
,
3309 CSR_API_MESSAGE_HEADER_SIZE(CSRSS_GET_TITLE
) + CSRSS_MAX_TITLE_LENGTH
* sizeof(WCHAR
));
3310 if(!NT_SUCCESS(Status
) || !(NT_SUCCESS(Status
= Request
->Status
)))
3312 RtlFreeHeap(RtlGetProcessHeap(), 0, Request
);
3313 SetLastErrorByStatus(Status
);
3317 if(nSize
* sizeof(WCHAR
) <= Request
->Data
.GetTitleRequest
.Length
)
3323 nSize
= Request
->Data
.GetTitleRequest
.Length
/ sizeof (WCHAR
);
3325 memcpy(lpConsoleTitle
, Request
->Data
.GetTitleRequest
.Title
, nSize
* sizeof(WCHAR
));
3326 lpConsoleTitle
[nSize
] = L
'\0';
3328 RtlFreeHeap(RtlGetProcessHeap(), 0, Request
);
3334 /*--------------------------------------------------------------
3344 LPSTR lpConsoleTitle
,
3348 WCHAR WideTitle
[CSRSS_MAX_TITLE_LENGTH
+ 1];
3349 DWORD nWideTitle
= CSRSS_MAX_TITLE_LENGTH
+ 1;
3352 if (!lpConsoleTitle
|| !nSize
) return 0;
3353 nWideTitle
= GetConsoleTitleW( (LPWSTR
) WideTitle
, nWideTitle
);
3354 if (!nWideTitle
) return 0;
3356 if ( (nWritten
= WideCharToMultiByte(
3357 CP_ACP
, // ANSI code page
3358 0, // performance and mapping flags
3359 (LPWSTR
) WideTitle
, // address of wide-character string
3360 nWideTitle
, // number of characters in string
3361 lpConsoleTitle
, // address of buffer for new string
3362 nSize
- 1, // size of buffer
3367 lpConsoleTitle
[nWritten
] = '\0';
3375 /*--------------------------------------------------------------
3383 LPCWSTR lpConsoleTitle
3386 PCSR_API_MESSAGE Request
; ULONG CsrRequest
;
3390 Request
= RtlAllocateHeap(RtlGetProcessHeap(), 0,
3391 max (sizeof(CSR_API_MESSAGE
),
3392 CSR_API_MESSAGE_HEADER_SIZE(CSRSS_SET_TITLE
) +
3393 min (wcslen(lpConsoleTitle
), CSRSS_MAX_TITLE_LENGTH
) * sizeof(WCHAR
)));
3394 if (Request
== NULL
)
3396 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3400 CsrRequest
= MAKE_CSR_API(SET_TITLE
, CSR_CONSOLE
);
3402 for( c
= 0; lpConsoleTitle
[c
] && c
< CSRSS_MAX_TITLE_LENGTH
; c
++ )
3403 Request
->Data
.SetTitleRequest
.Title
[c
] = lpConsoleTitle
[c
];
3404 Request
->Data
.SetTitleRequest
.Length
= c
* sizeof(WCHAR
);
3405 Status
= CsrClientCallServer(Request
,
3408 max (sizeof(CSR_API_MESSAGE
), CSR_API_MESSAGE_HEADER_SIZE(CSRSS_SET_TITLE
) + c
* sizeof(WCHAR
)));
3409 if (!NT_SUCCESS(Status
) || !NT_SUCCESS( Status
= Request
->Status
) )
3411 RtlFreeHeap(RtlGetProcessHeap(), 0, Request
);
3412 SetLastErrorByStatus (Status
);
3416 RtlFreeHeap(RtlGetProcessHeap(), 0, Request
);
3422 /*--------------------------------------------------------------
3432 LPCSTR lpConsoleTitle
3435 PCSR_API_MESSAGE Request
; ULONG CsrRequest
;
3439 Request
= RtlAllocateHeap(RtlGetProcessHeap(), 0,
3440 max (sizeof(CSR_API_MESSAGE
),
3441 CSR_API_MESSAGE_HEADER_SIZE(CSRSS_SET_TITLE
) +
3442 min (strlen(lpConsoleTitle
), CSRSS_MAX_TITLE_LENGTH
) * sizeof(WCHAR
)));
3443 if (Request
== NULL
)
3445 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3449 CsrRequest
= MAKE_CSR_API(SET_TITLE
, CSR_CONSOLE
);
3451 for( c
= 0; lpConsoleTitle
[c
] && c
< CSRSS_MAX_TITLE_LENGTH
; c
++ )
3452 Request
->Data
.SetTitleRequest
.Title
[c
] = lpConsoleTitle
[c
];
3453 Request
->Data
.SetTitleRequest
.Length
= c
* sizeof(WCHAR
);
3454 Status
= CsrClientCallServer(Request
,
3457 max (sizeof(CSR_API_MESSAGE
), CSR_API_MESSAGE_HEADER_SIZE(CSRSS_SET_TITLE
) + c
* sizeof(WCHAR
)));
3458 if (!NT_SUCCESS(Status
) || !NT_SUCCESS( Status
= Request
->Status
) )
3460 RtlFreeHeap(RtlGetProcessHeap(), 0, Request
);
3461 SetLastErrorByStatus (Status
);
3465 RtlFreeHeap(RtlGetProcessHeap(), 0, Request
);
3471 /*--------------------------------------------------------------
3472 * CreateConsoleScreenBuffer
3478 CreateConsoleScreenBuffer(
3479 DWORD dwDesiredAccess
,
3481 CONST SECURITY_ATTRIBUTES
*lpSecurityAttributes
,
3483 LPVOID lpScreenBufferData
3486 CSR_API_MESSAGE Request
; ULONG CsrRequest
;
3490 if (dwDesiredAccess
& ~(GENERIC_READ
| GENERIC_WRITE
)
3491 || dwShareMode
& ~(FILE_SHARE_READ
| FILE_SHARE_WRITE
)
3492 || dwFlags
!= CONSOLE_TEXTMODE_BUFFER
)
3494 SetLastError(ERROR_INVALID_PARAMETER
);
3495 return INVALID_HANDLE_VALUE
;
3498 Request
.Data
.CreateScreenBufferRequest
.Access
= dwDesiredAccess
;
3499 Request
.Data
.CreateScreenBufferRequest
.ShareMode
= dwShareMode
;
3500 Request
.Data
.CreateScreenBufferRequest
.Inheritable
=
3501 lpSecurityAttributes
? lpSecurityAttributes
->bInheritHandle
: FALSE
;
3503 CsrRequest
= MAKE_CSR_API(CREATE_SCREEN_BUFFER
, CSR_CONSOLE
);
3504 Status
= CsrClientCallServer( &Request
, NULL
, CsrRequest
, sizeof( CSR_API_MESSAGE
) );
3505 if( !NT_SUCCESS( Status
) || !NT_SUCCESS( Status
= Request
.Status
) )
3507 SetLastErrorByStatus ( Status
);
3508 return INVALID_HANDLE_VALUE
;
3510 return Request
.Data
.CreateScreenBufferRequest
.OutputHandle
;
3514 /*--------------------------------------------------------------
3521 GetConsoleCP( VOID
)
3523 CSR_API_MESSAGE Request
; ULONG CsrRequest
;
3527 CsrRequest
= MAKE_CSR_API(GET_CONSOLE_CP
, CSR_CONSOLE
);
3528 Status
= CsrClientCallServer(&Request
, NULL
, CsrRequest
,
3529 sizeof(CSR_API_MESSAGE
));
3530 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
3532 SetLastErrorByStatus (Status
);
3535 return Request
.Data
.GetConsoleCodePage
.CodePage
;
3539 /*--------------------------------------------------------------
3550 CSR_API_MESSAGE Request
; ULONG CsrRequest
;
3554 CsrRequest
= MAKE_CSR_API(SET_CONSOLE_CP
, CSR_CONSOLE
);
3555 Request
.Data
.SetConsoleCodePage
.CodePage
= wCodePageID
;
3556 Status
= CsrClientCallServer(&Request
, NULL
, CsrRequest
,
3557 sizeof(CSR_API_MESSAGE
));
3558 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
3560 SetLastErrorByStatus (Status
);
3562 return NT_SUCCESS(Status
);
3566 /*--------------------------------------------------------------
3567 * GetConsoleOutputCP
3573 GetConsoleOutputCP( VOID
)
3575 CSR_API_MESSAGE Request
; ULONG CsrRequest
;
3579 CsrRequest
= MAKE_CSR_API(GET_CONSOLE_OUTPUT_CP
, CSR_CONSOLE
);
3580 Status
= CsrClientCallServer(&Request
, NULL
, CsrRequest
,
3581 sizeof(CSR_API_MESSAGE
));
3582 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
3584 SetLastErrorByStatus (Status
);
3587 return Request
.Data
.GetConsoleOutputCodePage
.CodePage
;
3591 /*--------------------------------------------------------------
3592 * SetConsoleOutputCP
3602 CSR_API_MESSAGE Request
; ULONG CsrRequest
;
3606 CsrRequest
= MAKE_CSR_API(SET_CONSOLE_OUTPUT_CP
, CSR_CONSOLE
);
3607 Request
.Data
.SetConsoleOutputCodePage
.CodePage
= wCodePageID
;
3608 Status
= CsrClientCallServer(&Request
, NULL
, CsrRequest
,
3609 sizeof(CSR_API_MESSAGE
));
3610 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
3612 SetLastErrorByStatus (Status
);
3614 return NT_SUCCESS(Status
);
3618 /*--------------------------------------------------------------
3619 * GetConsoleProcessList
3624 GetConsoleProcessList(LPDWORD lpdwProcessList
,
3625 DWORD dwProcessCount
)
3627 PCSR_API_MESSAGE Request
; ULONG CsrRequest
;
3631 if(lpdwProcessList
== NULL
|| dwProcessCount
== 0)
3633 SetLastError(ERROR_INVALID_PARAMETER
);
3637 Request
= RtlAllocateHeap(RtlGetProcessHeap(), 0,
3638 max (sizeof(CSR_API_MESSAGE
),
3639 CSR_API_MESSAGE_HEADER_SIZE(CSRSS_GET_PROCESS_LIST
)
3640 + min (dwProcessCount
, CSRSS_MAX_GET_PROCESS_LIST
/ sizeof(DWORD
)) * sizeof(DWORD
)));
3641 if (Request
== NULL
)
3643 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3647 CsrRequest
= MAKE_CSR_API(GET_PROCESS_LIST
, CSR_CONSOLE
);
3648 Request
->Data
.GetProcessListRequest
.nMaxIds
= min (dwProcessCount
, CSRSS_MAX_GET_PROCESS_LIST
/ sizeof(DWORD
));
3650 Status
= CsrClientCallServer(Request
,
3653 max (sizeof(CSR_API_MESSAGE
),
3654 CSR_API_MESSAGE_HEADER_SIZE(CSRSS_GET_PROCESS_LIST
)
3655 + Request
->Data
.GetProcessListRequest
.nMaxIds
* sizeof(DWORD
)));
3656 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
->Status
))
3658 RtlFreeHeap(RtlGetProcessHeap(), 0, Request
);
3659 SetLastErrorByStatus (Status
);
3664 nProcesses
= Request
->Data
.GetProcessListRequest
.nProcessIdsCopied
;
3665 if(dwProcessCount
>= nProcesses
)
3667 memcpy(lpdwProcessList
, Request
->Data
.GetProcessListRequest
.ProcessId
, nProcesses
* sizeof(DWORD
));
3671 RtlFreeHeap(RtlGetProcessHeap(), 0, Request
);
3678 /*--------------------------------------------------------------
3679 * GetConsoleSelectionInfo
3684 GetConsoleSelectionInfo(PCONSOLE_SELECTION_INFO lpConsoleSelectionInfo
)
3686 DPRINT1("GetConsoleSelectionInfo(0x%x) UNIMPLEMENTED!\n", lpConsoleSelectionInfo
);
3687 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3693 /*--------------------------------------------------------------
3699 AttachConsole(DWORD dwProcessId
)
3701 DPRINT1("AttachConsole(0x%x) UNIMPLEMENTED!\n", dwProcessId
);
3702 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3706 /*--------------------------------------------------------------
3712 GetConsoleWindow (VOID
)
3714 CSR_API_MESSAGE Request
; ULONG CsrRequest
;
3718 CsrRequest
= MAKE_CSR_API(GET_CONSOLE_WINDOW
, CSR_CONSOLE
);
3719 Status
= CsrClientCallServer( &Request
, NULL
, CsrRequest
, sizeof( CSR_API_MESSAGE
) );
3720 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
3722 SetLastErrorByStatus (Status
);
3725 return Request
.Data
.GetConsoleWindowRequest
.WindowHandle
;
3729 /*--------------------------------------------------------------
3734 BOOL WINAPI
SetConsoleIcon(HICON hicon
)
3736 CSR_API_MESSAGE Request
; ULONG CsrRequest
;
3740 CsrRequest
= MAKE_CSR_API(SET_CONSOLE_ICON
, CSR_CONSOLE
);
3741 Request
.Data
.SetConsoleIconRequest
.WindowIcon
= hicon
;
3742 Status
= CsrClientCallServer( &Request
, NULL
, CsrRequest
, sizeof( CSR_API_MESSAGE
) );
3743 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
3745 SetLastErrorByStatus (Status
);
3748 return NT_SUCCESS(Status
);
3752 /*--------------------------------------------------------------
3753 * SetConsoleInputExeNameW
3758 SetConsoleInputExeNameW(LPCWSTR lpInputExeName
)
3761 int lenName
= lstrlenW(lpInputExeName
);
3764 lenName
> (int)(sizeof(InputExeName
) / sizeof(InputExeName
[0])) - 1)
3766 /* Fail if string is empty or too long */
3767 SetLastError(ERROR_INVALID_PARAMETER
);
3771 RtlEnterCriticalSection(&ConsoleLock
);
3772 /* wrap copying into SEH as we may copy from invalid buffer and in case of an
3773 exception the console lock would've never been released, which would cause
3774 further calls (if the exception was handled by the caller) to recursively
3775 acquire the lock... */
3778 RtlCopyMemory(InputExeName
, lpInputExeName
, lenName
* sizeof(WCHAR
));
3779 InputExeName
[lenName
] = L
'\0';
3782 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3785 SetLastErrorByStatus(_SEH2_GetExceptionCode());
3788 RtlLeaveCriticalSection(&ConsoleLock
);
3794 /*--------------------------------------------------------------
3795 * SetConsoleInputExeNameA
3800 SetConsoleInputExeNameA(LPCSTR lpInputExeName
)
3802 ANSI_STRING InputExeNameA
;
3803 UNICODE_STRING InputExeNameU
;
3807 RtlInitAnsiString(&InputExeNameA
, lpInputExeName
);
3809 if(InputExeNameA
.Length
< sizeof(InputExeNameA
.Buffer
[0]) ||
3810 InputExeNameA
.Length
>= (sizeof(InputExeName
) / sizeof(InputExeName
[0])) - 1)
3812 /* Fail if string is empty or too long */
3813 SetLastError(ERROR_INVALID_PARAMETER
);
3817 Status
= RtlAnsiStringToUnicodeString(&InputExeNameU
, &InputExeNameA
, TRUE
);
3818 if(NT_SUCCESS(Status
))
3820 Ret
= SetConsoleInputExeNameW(InputExeNameU
.Buffer
);
3821 RtlFreeUnicodeString(&InputExeNameU
);
3825 SetLastErrorByStatus(Status
);
3833 /*--------------------------------------------------------------
3834 * GetConsoleInputExeNameW
3839 GetConsoleInputExeNameW(DWORD nBufferLength
, LPWSTR lpBuffer
)
3843 RtlEnterCriticalSection(&ConsoleLock
);
3845 lenName
= lstrlenW(InputExeName
);
3846 if(lenName
>= (int)nBufferLength
)
3848 /* buffer is not large enough, return the required size */
3849 RtlLeaveCriticalSection(&ConsoleLock
);
3850 SetLastError(ERROR_BUFFER_OVERFLOW
);
3854 /* wrap copying into SEH as we may copy to invalid buffer and in case of an
3855 exception the console lock would've never been released, which would cause
3856 further calls (if the exception was handled by the caller) to recursively
3857 acquire the lock... */
3860 RtlCopyMemory(lpBuffer
, InputExeName
, (lenName
+ 1) * sizeof(WCHAR
));
3862 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3865 SetLastErrorByStatus(_SEH2_GetExceptionCode());
3869 RtlLeaveCriticalSection(&ConsoleLock
);
3875 /*--------------------------------------------------------------
3876 * GetConsoleInputExeNameA
3881 GetConsoleInputExeNameA(DWORD nBufferLength
, LPSTR lpBuffer
)
3886 if(nBufferLength
> 0)
3888 Buffer
= RtlAllocateHeap(RtlGetProcessHeap(), 0, nBufferLength
* sizeof(WCHAR
));
3891 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3900 Ret
= GetConsoleInputExeNameW(nBufferLength
, Buffer
);
3901 if(nBufferLength
> 0)
3905 UNICODE_STRING BufferU
;
3906 ANSI_STRING BufferA
;
3908 RtlInitUnicodeString(&BufferU
, Buffer
);
3911 BufferA
.MaximumLength
= (USHORT
)nBufferLength
;
3912 BufferA
.Buffer
= lpBuffer
;
3914 RtlUnicodeStringToAnsiString(&BufferA
, &BufferU
, FALSE
);
3917 RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer
);
3924 /*--------------------------------------------------------------
3925 * GetConsoleHistoryInfo
3930 GetConsoleHistoryInfo(PCONSOLE_HISTORY_INFO lpConsoleHistoryInfo
)
3932 DPRINT1("GetConsoleHistoryInfo(0x%p) UNIMPLEMENTED!\n", lpConsoleHistoryInfo
);
3933 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3938 /*--------------------------------------------------------------
3939 * SetConsoleHistoryInfo
3944 SetConsoleHistoryInfo(IN PCONSOLE_HISTORY_INFO lpConsoleHistoryInfo
)
3946 DPRINT1("SetConsoleHistoryInfo(0x%p) UNIMPLEMENTED!\n", lpConsoleHistoryInfo
);
3947 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3952 /*--------------------------------------------------------------
3953 * GetConsoleOriginalTitleW
3958 GetConsoleOriginalTitleW(OUT LPWSTR lpConsoleTitle
,
3961 DPRINT1("GetConsoleOriginalTitleW(0x%p, 0x%x) UNIMPLEMENTED!\n", lpConsoleTitle
, nSize
);
3962 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3967 /*--------------------------------------------------------------
3968 * GetConsoleOriginalTitleA
3973 GetConsoleOriginalTitleA(OUT LPSTR lpConsoleTitle
,
3976 DPRINT1("GetConsoleOriginalTitleA(0x%p, 0x%x) UNIMPLEMENTED!\n", lpConsoleTitle
, nSize
);
3977 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3982 /*--------------------------------------------------------------
3983 * GetConsoleScreenBufferInfoEx
3988 GetConsoleScreenBufferInfoEx(IN HANDLE hConsoleOutput
,
3989 OUT PCONSOLE_SCREEN_BUFFER_INFOEX lpConsoleScreenBufferInfoEx
)
3991 DPRINT1("GetConsoleScreenBufferInfoEx(0x%p, 0x%p) UNIMPLEMENTED!\n", hConsoleOutput
, lpConsoleScreenBufferInfoEx
);
3992 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3997 /*--------------------------------------------------------------
3998 * SetConsoleScreenBufferInfoEx
4003 SetConsoleScreenBufferInfoEx(IN HANDLE hConsoleOutput
,
4004 IN PCONSOLE_SCREEN_BUFFER_INFOEX lpConsoleScreenBufferInfoEx
)
4006 DPRINT1("SetConsoleScreenBufferInfoEx(0x%p, 0x%p) UNIMPLEMENTED!\n", hConsoleOutput
, lpConsoleScreenBufferInfoEx
);
4007 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
4012 /*--------------------------------------------------------------
4013 * GetCurrentConsoleFontEx
4018 GetCurrentConsoleFontEx(IN HANDLE hConsoleOutput
,
4019 IN BOOL bMaximumWindow
,
4020 OUT PCONSOLE_FONT_INFOEX lpConsoleCurrentFontEx
)
4022 DPRINT1("GetCurrentConsoleFontEx(0x%p, 0x%x, 0x%p) UNIMPLEMENTED!\n", hConsoleOutput
, bMaximumWindow
, lpConsoleCurrentFontEx
);
4023 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);