3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: dll/win32/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 RTL_CRITICAL_SECTION ConsoleLock
;
23 extern BOOL ConsoleInitialized
;
24 extern BOOL WINAPI
IsDebuggerPresent(VOID
);
26 /* GLOBALS *******************************************************************/
28 PHANDLER_ROUTINE InitialHandler
[1];
29 PHANDLER_ROUTINE
* CtrlHandlers
;
31 ULONG NrAllocatedHandlers
;
33 #define INPUTEXENAME_BUFLEN 256
34 static WCHAR InputExeName
[INPUTEXENAME_BUFLEN
] = L
"";
36 /* Default Console Control Handler *******************************************/
40 DefaultConsoleCtrlHandler(DWORD Event
)
42 DPRINT("Default handler called: %lx\n", Event
);
46 DPRINT("Ctrl-C Event\n");
49 case CTRL_BREAK_EVENT
:
50 DPRINT("Ctrl-Break Event\n");
53 case CTRL_SHUTDOWN_EVENT
:
54 DPRINT("Ctrl Shutdown Event\n");
57 case CTRL_CLOSE_EVENT
:
58 DPRINT("Ctrl Close Event\n");
61 case CTRL_LOGOFF_EVENT
:
62 DPRINT("Ctrl Logoff Event\n");
66 ExitProcess(CONTROL_C_EXIT
);
73 ConsoleControlDispatcher(DWORD CodeAndFlag
)
76 DWORD nCode
= CodeAndFlag
& MAXLONG
;
78 EXCEPTION_RECORD erException
;
80 DPRINT("Console Dispatcher Active: %lx %lx\n", CodeAndFlag
, nCode
);
81 SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST
);
86 case CTRL_BREAK_EVENT
:
88 if (IsDebuggerPresent())
90 erException
.ExceptionCode
= (nCode
== CTRL_C_EVENT
?
91 DBG_CONTROL_C
: DBG_CONTROL_BREAK
);
92 erException
.ExceptionFlags
= 0;
93 erException
.ExceptionRecord
= NULL
;
94 erException
.ExceptionAddress
= DefaultConsoleCtrlHandler
;
95 erException
.NumberParameters
= 0;
99 RtlRaiseException(&erException
);
101 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
103 RtlEnterCriticalSection(&ConsoleLock
);
105 if ((nCode
!= CTRL_C_EVENT
) ||
106 (NtCurrentPeb()->ProcessParameters
->ConsoleFlags
!= 1))
108 for (i
= NrCtrlHandlers
; i
> 0; i
--)
110 if (CtrlHandlers
[i
- 1](nCode
)) break;
114 RtlLeaveCriticalSection(&ConsoleLock
);
124 case CTRL_CLOSE_EVENT
:
125 case CTRL_LOGOFF_EVENT
:
126 case CTRL_SHUTDOWN_EVENT
:
136 ExitProcess(CONTROL_C_EXIT
);
145 ASSERT(ConsoleInitialized
);
147 RtlEnterCriticalSection(&ConsoleLock
);
149 if ((nCode
!= CTRL_C_EVENT
) || (NtCurrentPeb()->ProcessParameters
->ConsoleFlags
!= 1))
151 for (i
= NrCtrlHandlers
; i
> 0; i
--)
154 (CodeAndFlag
& MINLONG
) &&
155 ((nCode
== CTRL_LOGOFF_EVENT
) || (nCode
== CTRL_SHUTDOWN_EVENT
)))
157 DPRINT("Skipping system/service apps\n");
161 if (CtrlHandlers
[i
- 1](nCode
))
165 case CTRL_CLOSE_EVENT
:
166 case CTRL_LOGOFF_EVENT
:
167 case CTRL_SHUTDOWN_EVENT
:
169 nExitCode
= CodeAndFlag
;
177 RtlLeaveCriticalSection(&ConsoleLock
);
178 ExitThread(nExitCode
);
182 /* FUNCTIONS *****************************************************************/
189 AddConsoleAliasA(LPCSTR lpSource
,
193 LPWSTR lpSourceW
= NULL
;
194 LPWSTR lpTargetW
= NULL
;
195 LPWSTR lpExeNameW
= NULL
;
199 BasepAnsiStringToHeapUnicodeString(lpSource
, (LPWSTR
*) &lpSourceW
);
201 BasepAnsiStringToHeapUnicodeString(lpTarget
, (LPWSTR
*) &lpTargetW
);
203 BasepAnsiStringToHeapUnicodeString(lpExeName
, (LPWSTR
*) &lpExeNameW
);
205 bRetVal
= AddConsoleAliasW(lpSourceW
, lpTargetW
, lpExeNameW
);
209 RtlFreeHeap(GetProcessHeap(), 0, (LPWSTR
*) lpSourceW
);
211 RtlFreeHeap(GetProcessHeap(), 0, (LPWSTR
*) lpTargetW
);
213 RtlFreeHeap(GetProcessHeap(), 0, (LPWSTR
*) lpExeNameW
);
224 AddConsoleAliasW(LPCWSTR lpSource
,
228 PCSR_API_MESSAGE Request
;
232 ULONG TargetLength
= 0;
238 DPRINT("AddConsoleAliasW enterd with lpSource %S lpTarget %S lpExeName %S\n", lpSource
, lpTarget
, lpExeName
);
240 ExeLength
= wcslen(lpExeName
) + 1;
241 SourceLength
= wcslen(lpSource
)+ 1;
243 TargetLength
= wcslen(lpTarget
) + 1;
245 Size
= (ExeLength
+ SourceLength
+ TargetLength
) * sizeof(WCHAR
);
246 RequestLength
= sizeof(CSR_API_MESSAGE
) + Size
;
248 Request
= RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY
, RequestLength
);
249 Ptr
= (WCHAR
*)(((ULONG_PTR
)Request
) + sizeof(CSR_API_MESSAGE
));
251 wcscpy(Ptr
, lpSource
);
252 Request
->Data
.AddConsoleAlias
.SourceLength
= SourceLength
;
253 Ptr
= (WCHAR
*)(((ULONG_PTR
)Request
) + sizeof(CSR_API_MESSAGE
) + SourceLength
* sizeof(WCHAR
));
255 wcscpy(Ptr
, lpExeName
);
256 Request
->Data
.AddConsoleAlias
.ExeLength
= ExeLength
;
257 Ptr
= (WCHAR
*)(((ULONG_PTR
)Request
) + sizeof(CSR_API_MESSAGE
) + (ExeLength
+ SourceLength
)* sizeof(WCHAR
));
259 if (lpTarget
) /* target can be optional */
260 wcscpy(Ptr
, lpTarget
);
262 Request
->Data
.AddConsoleAlias
.TargetLength
= TargetLength
;
264 CsrRequest
= MAKE_CSR_API(ADD_CONSOLE_ALIAS
, CSR_CONSOLE
);
265 Status
= CsrClientCallServer(Request
,
270 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
->Status
))
272 SetLastErrorByStatus(Status
);
273 RtlFreeHeap(GetProcessHeap(), 0, Request
);
277 RtlFreeHeap(GetProcessHeap(), 0, Request
);
283 * @unimplemented (Undocumented)
287 ConsoleMenuControl(HANDLE hConsole
,
291 DPRINT1("ConsoleMenuControl(0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", hConsole
, Unknown1
, Unknown2
);
292 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
302 DuplicateConsoleHandle(HANDLE hConsole
,
303 DWORD dwDesiredAccess
,
307 CSR_API_MESSAGE Request
;
311 if (dwOptions
& ~(DUPLICATE_CLOSE_SOURCE
| DUPLICATE_SAME_ACCESS
)
312 || (!(dwOptions
& DUPLICATE_SAME_ACCESS
)
313 && dwDesiredAccess
& ~(GENERIC_READ
| GENERIC_WRITE
)))
315 SetLastError (ERROR_INVALID_PARAMETER
);
316 return INVALID_HANDLE_VALUE
;
319 CsrRequest
= MAKE_CSR_API(DUPLICATE_HANDLE
, CSR_NATIVE
);
320 Request
.Data
.DuplicateHandleRequest
.Handle
= hConsole
;
321 Request
.Data
.DuplicateHandleRequest
.Access
= dwDesiredAccess
;
322 Request
.Data
.DuplicateHandleRequest
.Inheritable
= bInheritHandle
;
323 Request
.Data
.DuplicateHandleRequest
.Options
= dwOptions
;
325 Status
= CsrClientCallServer(&Request
,
328 sizeof(CSR_API_MESSAGE
));
329 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
=Request
.Status
))
331 SetLastErrorByStatus(Status
);
332 return INVALID_HANDLE_VALUE
;
335 return Request
.Data
.DuplicateHandleRequest
.Handle
;
340 * @unimplemented (Undocumented)
344 ExpungeConsoleCommandHistoryW(DWORD Unknown0
)
346 DPRINT1("ExpungeConsoleCommandHistoryW(0x%x) UNIMPLEMENTED!\n", Unknown0
);
347 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
353 * @unimplemented (Undocumented)
357 ExpungeConsoleCommandHistoryA (DWORD Unknown0
)
359 DPRINT1("ExpungeConsoleCommandHistoryW(0x%x) UNIMPLEMENTED!\n", Unknown0
);
360 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
370 GetConsoleAliasW(LPWSTR lpSource
,
371 LPWSTR lpTargetBuffer
,
372 DWORD TargetBufferLength
,
375 PCSR_API_MESSAGE Request
;
376 PCSR_CAPTURE_BUFFER CaptureBuffer
;
385 DPRINT("GetConsoleAliasW entered lpSource %S lpExeName %S\n", lpSource
, lpExeName
);
387 if (lpTargetBuffer
== NULL
)
389 SetLastError(ERROR_INVALID_PARAMETER
);
393 CsrRequest
= MAKE_CSR_API(GET_CONSOLE_ALIAS
, CSR_CONSOLE
);
395 ExeLength
= wcslen(lpExeName
) + 1;
396 SourceLength
= wcslen(lpSource
) + 1;
398 Size
= (ExeLength
+ SourceLength
) * sizeof(WCHAR
);
400 RequestLength
= Size
+ sizeof(CSR_API_MESSAGE
);
401 Request
= RtlAllocateHeap(GetProcessHeap(), 0, RequestLength
);
404 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
408 CaptureBuffer
= CsrAllocateCaptureBuffer(1, TargetBufferLength
);
411 RtlFreeHeap(GetProcessHeap(), 0, Request
);
412 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
416 Request
->Data
.GetConsoleAlias
.TargetBuffer
= NULL
;
418 CsrCaptureMessageBuffer(CaptureBuffer
,
421 (PVOID
*)&Request
->Data
.GetConsoleAlias
.TargetBuffer
);
423 Request
->Data
.GetConsoleAlias
.TargetBufferLength
= TargetBufferLength
;
425 Ptr
= (LPWSTR
)((ULONG_PTR
)Request
+ sizeof(CSR_API_MESSAGE
));
426 wcscpy(Ptr
, lpSource
);
428 wcscpy(Ptr
, lpExeName
);
430 Request
->Data
.GetConsoleAlias
.ExeLength
= ExeLength
;
431 Request
->Data
.GetConsoleAlias
.SourceLength
= SourceLength
;
433 Status
= CsrClientCallServer(Request
,
436 sizeof(CSR_API_MESSAGE
) + Size
);
438 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
->Status
))
440 RtlFreeHeap(GetProcessHeap(), 0, Request
);
441 CsrFreeCaptureBuffer(CaptureBuffer
);
442 SetLastErrorByStatus(Status
);
446 wcscpy(lpTargetBuffer
, Request
->Data
.GetConsoleAlias
.TargetBuffer
);
447 RtlFreeHeap(GetProcessHeap(), 0, Request
);
448 CsrFreeCaptureBuffer(CaptureBuffer
);
450 return Request
->Data
.GetConsoleAlias
.BytesWritten
;
459 GetConsoleAliasA(LPSTR lpSource
,
460 LPSTR lpTargetBuffer
,
461 DWORD TargetBufferLength
,
466 LPWSTR lpwTargetBuffer
;
471 DPRINT("GetConsoleAliasA entered\n");
473 if (lpTargetBuffer
== NULL
)
475 SetLastError(ERROR_INVALID_PARAMETER
);
479 dwSourceSize
= (strlen(lpSource
)+1) * sizeof(WCHAR
);
480 lpwSource
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, dwSourceSize
);
481 if (lpwSource
== NULL
)
483 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
486 MultiByteToWideChar(CP_ACP
, 0, lpSource
, -1, lpwSource
, dwSourceSize
);
488 dwExeNameSize
= (strlen(lpExeName
)+1) * sizeof(WCHAR
);
489 lpwExeName
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, dwExeNameSize
);
490 if (lpwExeName
== NULL
)
492 HeapFree(GetProcessHeap(), 0, lpwSource
);
493 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
496 MultiByteToWideChar(CP_ACP
, 0, lpExeName
, -1, lpwExeName
, dwExeNameSize
);
498 lpwTargetBuffer
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, TargetBufferLength
* sizeof(WCHAR
));
499 if (lpwTargetBuffer
== NULL
)
501 HeapFree(GetProcessHeap(), 0, lpwSource
);
502 HeapFree(GetProcessHeap(), 0, lpwExeName
);
503 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
507 dwResult
= GetConsoleAliasW(lpwSource
, lpwTargetBuffer
, TargetBufferLength
* sizeof(WCHAR
), lpwExeName
);
509 HeapFree(GetProcessHeap(), 0, lpwSource
);
510 HeapFree(GetProcessHeap(), 0, lpwExeName
);
513 dwResult
= WideCharToMultiByte(CP_ACP
, 0, lpwTargetBuffer
, dwResult
/ sizeof(WCHAR
), lpTargetBuffer
, TargetBufferLength
, NULL
, NULL
);
515 HeapFree(GetProcessHeap(), 0, lpwTargetBuffer
);
526 GetConsoleAliasExesW(LPWSTR lpExeNameBuffer
,
527 DWORD ExeNameBufferLength
)
529 CSR_API_MESSAGE Request
;
530 PCSR_CAPTURE_BUFFER CaptureBuffer
;
534 DPRINT("GetConsoleAliasExesW entered\n");
536 CaptureBuffer
= CsrAllocateCaptureBuffer(1, ExeNameBufferLength
);
539 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
543 CsrRequest
= MAKE_CSR_API(GET_CONSOLE_ALIASES_EXES
, CSR_CONSOLE
);
544 CsrAllocateMessagePointer(CaptureBuffer
,
546 (PVOID
*)&Request
.Data
.GetConsoleAliasesExes
.ExeNames
);
547 Request
.Data
.GetConsoleAliasesExes
.Length
= ExeNameBufferLength
;
549 Status
= CsrClientCallServer(&Request
,
552 sizeof(CSR_API_MESSAGE
));
554 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
556 SetLastErrorByStatus(Status
);
557 CsrFreeCaptureBuffer(CaptureBuffer
);
561 memcpy(lpExeNameBuffer
,
562 Request
.Data
.GetConsoleAliasesExes
.ExeNames
,
563 Request
.Data
.GetConsoleAliasesExes
.BytesWritten
);
565 CsrFreeCaptureBuffer(CaptureBuffer
);
566 return Request
.Data
.GetConsoleAliasesExes
.BytesWritten
;
575 GetConsoleAliasExesA(LPSTR lpExeNameBuffer
,
576 DWORD ExeNameBufferLength
)
578 LPWSTR lpwExeNameBuffer
;
581 DPRINT("GetConsoleAliasExesA entered\n");
583 lpwExeNameBuffer
= HeapAlloc(GetProcessHeap(), 0, ExeNameBufferLength
* sizeof(WCHAR
));
585 dwResult
= GetConsoleAliasExesW(lpwExeNameBuffer
, ExeNameBufferLength
* sizeof(WCHAR
));
588 dwResult
= WideCharToMultiByte(CP_ACP
, 0, lpwExeNameBuffer
, dwResult
/ sizeof(WCHAR
), lpExeNameBuffer
, ExeNameBufferLength
, NULL
, NULL
);
590 HeapFree(GetProcessHeap(), 0, lpwExeNameBuffer
);
599 GetConsoleAliasExesLengthW(VOID
)
601 CSR_API_MESSAGE Request
;
605 DPRINT("GetConsoleAliasExesLengthW entered\n");
607 CsrRequest
= MAKE_CSR_API(GET_CONSOLE_ALIASES_EXES_LENGTH
, CSR_CONSOLE
);
608 Request
.Data
.GetConsoleAliasesExesLength
.Length
= 0;
611 Status
= CsrClientCallServer(&Request
,
614 sizeof(CSR_API_MESSAGE
));
616 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
618 SetLastErrorByStatus(Status
);
622 return Request
.Data
.GetConsoleAliasesExesLength
.Length
;
630 GetConsoleAliasExesLengthA(VOID
)
634 DPRINT("GetConsoleAliasExesLengthA entered\n");
636 dwLength
= GetConsoleAliasExesLengthW();
639 dwLength
/= sizeof(WCHAR
);
650 GetConsoleAliasesW(LPWSTR AliasBuffer
,
651 DWORD AliasBufferLength
,
654 CSR_API_MESSAGE Request
;
659 DPRINT("GetConsoleAliasesW entered\n");
661 dwLength
= GetConsoleAliasesLengthW(ExeName
);
662 if (!dwLength
|| dwLength
> AliasBufferLength
)
665 CsrRequest
= MAKE_CSR_API(GET_ALL_CONSOLE_ALIASES
, CSR_CONSOLE
);
666 Request
.Data
.GetAllConsoleAlias
.AliasBuffer
= AliasBuffer
;
667 Request
.Data
.GetAllConsoleAlias
.AliasBufferLength
= AliasBufferLength
;
668 Request
.Data
.GetAllConsoleAlias
.lpExeName
= ExeName
;
670 Status
= CsrClientCallServer(&Request
,
673 sizeof(CSR_API_MESSAGE
));
675 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
677 SetLastErrorByStatus(Status
);
681 return Request
.Data
.GetAllConsoleAlias
.BytesWritten
/ sizeof(WCHAR
);
690 GetConsoleAliasesA(LPSTR AliasBuffer
,
691 DWORD AliasBufferLength
,
695 LPWSTR lpwExeName
= NULL
;
696 LPWSTR lpwAliasBuffer
;
698 DPRINT("GetConsoleAliasesA entered\n");
701 BasepAnsiStringToHeapUnicodeString(ExeName
, (LPWSTR
*) &lpwExeName
);
703 lpwAliasBuffer
= HeapAlloc(GetProcessHeap(), 0, AliasBufferLength
* sizeof(WCHAR
));
705 dwRetVal
= GetConsoleAliasesW(lpwAliasBuffer
, AliasBufferLength
, lpwExeName
);
708 RtlFreeHeap(GetProcessHeap(), 0, (LPWSTR
*) lpwExeName
);
711 dwRetVal
= WideCharToMultiByte(CP_ACP
, 0, lpwAliasBuffer
, dwRetVal
, AliasBuffer
, AliasBufferLength
, NULL
, NULL
);
713 HeapFree(GetProcessHeap(), 0, lpwAliasBuffer
);
723 GetConsoleAliasesLengthW(LPWSTR lpExeName
)
725 CSR_API_MESSAGE Request
;
729 DPRINT("GetConsoleAliasesLengthW entered\n");
731 CsrRequest
= MAKE_CSR_API(GET_ALL_CONSOLE_ALIASES_LENGTH
, CSR_CONSOLE
);
732 Request
.Data
.GetAllConsoleAliasesLength
.lpExeName
= lpExeName
;
733 Request
.Data
.GetAllConsoleAliasesLength
.Length
= 0;
735 Status
= CsrClientCallServer(&Request
,
738 sizeof(CSR_API_MESSAGE
));
740 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
742 SetLastErrorByStatus(Status
);
746 return Request
.Data
.GetAllConsoleAliasesLength
.Length
;
755 GetConsoleAliasesLengthA(LPSTR lpExeName
)
758 LPWSTR lpExeNameW
= NULL
;
761 BasepAnsiStringToHeapUnicodeString(lpExeName
, (LPWSTR
*) &lpExeNameW
);
763 dwRetVal
= GetConsoleAliasesLengthW(lpExeNameW
);
765 dwRetVal
/= sizeof(WCHAR
);
769 RtlFreeHeap(GetProcessHeap(), 0, (LPWSTR
*) lpExeNameW
);
776 * @unimplemented (Undocumented)
780 GetConsoleCommandHistoryW(DWORD Unknown0
,
784 DPRINT1("GetConsoleCommandHistoryW(0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
, Unknown2
);
785 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
791 * @unimplemented (Undocumented)
795 GetConsoleCommandHistoryA(DWORD Unknown0
,
799 DPRINT1("GetConsoleCommandHistoryA(0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
, Unknown2
);
800 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
806 * @unimplemented (Undocumented)
810 GetConsoleCommandHistoryLengthW(DWORD Unknown0
)
812 DPRINT1("GetConsoleCommandHistoryLengthW(0x%x) UNIMPLEMENTED!\n", Unknown0
);
813 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
819 * @unimplemented (Undocumented)
823 GetConsoleCommandHistoryLengthA(DWORD Unknown0
)
825 DPRINT1("GetConsoleCommandHistoryLengthA(0x%x) UNIMPLEMENTED!\n", Unknown0
);
826 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
835 GetConsoleDisplayMode(LPDWORD lpdwMode
)
837 * FUNCTION: Get the console display mode
839 * lpdwMode - Address of variable that receives the current value
841 * STATUS: Undocumented
844 DPRINT1("GetConsoleDisplayMode(0x%x) UNIMPLEMENTED!\n", lpdwMode
);
845 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
851 * @unimplemented (Undocumented)
855 GetConsoleFontInfo(DWORD Unknown0
,
860 DPRINT1("GetConsoleFontInfo(0x%x, 0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
, Unknown2
, Unknown3
);
861 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
871 GetConsoleFontSize(HANDLE hConsoleOutput
,
874 COORD Empty
= {0, 0};
875 DPRINT1("GetConsoleFontSize(0x%x, 0x%x) UNIMPLEMENTED!\n", hConsoleOutput
, nFont
);
876 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
882 * @implemented (Undocumented)
886 GetConsoleHardwareState(HANDLE hConsole
,
890 CSR_API_MESSAGE Request
;
894 CsrRequest
= MAKE_CSR_API(SETGET_CONSOLE_HW_STATE
, CSR_CONSOLE
);
895 Request
.Data
.ConsoleHardwareStateRequest
.ConsoleHandle
= hConsole
;
896 Request
.Data
.ConsoleHardwareStateRequest
.SetGet
= CONSOLE_HARDWARE_STATE_GET
;
898 Status
= CsrClientCallServer(&Request
,
901 sizeof(CSR_API_MESSAGE
));
902 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
904 SetLastErrorByStatus(Status
);
908 *State
= Request
.Data
.ConsoleHardwareStateRequest
.State
;
914 * @implemented (Undocumented)
918 GetConsoleInputWaitHandle(VOID
)
920 CSR_API_MESSAGE Request
;
924 CsrRequest
= MAKE_CSR_API(GET_INPUT_WAIT_HANDLE
, CSR_CONSOLE
);
926 Status
= CsrClientCallServer(&Request
,
929 sizeof(CSR_API_MESSAGE
));
930 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
932 SetLastErrorByStatus(Status
);
936 return Request
.Data
.GetConsoleInputWaitHandle
.InputWaitHandle
;
945 GetCurrentConsoleFont(HANDLE hConsoleOutput
,
947 PCONSOLE_FONT_INFO lpConsoleCurrentFont
)
949 DPRINT1("GetCurrentConsoleFont(0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", hConsoleOutput
, bMaximumWindow
, lpConsoleCurrentFont
);
950 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
956 * @unimplemented (Undocumented)
960 GetNumberOfConsoleFonts(VOID
)
962 DPRINT1("GetNumberOfConsoleFonts() UNIMPLEMENTED!\n");
963 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
964 return 1; /* FIXME: call csrss.exe */
969 * @unimplemented (Undocumented)
973 InvalidateConsoleDIBits(DWORD Unknown0
,
976 DPRINT1("InvalidateConsoleDIBits(0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
);
977 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
983 * @unimplemented (Undocumented)
987 OpenConsoleW(LPCWSTR wsName
,
988 DWORD dwDesiredAccess
,
992 CSR_API_MESSAGE Request
;
994 NTSTATUS Status
= STATUS_SUCCESS
;
996 if (wsName
&& 0 == _wcsicmp(wsName
, L
"CONIN$"))
998 CsrRequest
= MAKE_CSR_API(GET_INPUT_HANDLE
, CSR_NATIVE
);
1000 else if (wsName
&& 0 == _wcsicmp(wsName
, L
"CONOUT$"))
1002 CsrRequest
= MAKE_CSR_API(GET_OUTPUT_HANDLE
, CSR_NATIVE
);
1006 SetLastError(ERROR_INVALID_PARAMETER
);
1007 return(INVALID_HANDLE_VALUE
);
1010 if (dwDesiredAccess
& ~(GENERIC_READ
|GENERIC_WRITE
))
1012 SetLastError(ERROR_INVALID_PARAMETER
);
1013 return(INVALID_HANDLE_VALUE
);
1016 if (dwShareMode
& ~(FILE_SHARE_READ
|FILE_SHARE_WRITE
))
1018 SetLastError(ERROR_INVALID_PARAMETER
);
1019 return(INVALID_HANDLE_VALUE
);
1022 /* Structures for GET_INPUT_HANDLE and GET_OUTPUT_HANDLE requests are identical */
1023 Request
.Data
.GetInputHandleRequest
.Access
= dwDesiredAccess
;
1024 Request
.Data
.GetInputHandleRequest
.Inheritable
= bInheritHandle
;
1025 Request
.Data
.GetInputHandleRequest
.ShareMode
= dwShareMode
;
1027 Status
= CsrClientCallServer(&Request
,
1030 sizeof(CSR_API_MESSAGE
));
1031 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
1033 SetLastErrorByStatus(Status
);
1034 return INVALID_HANDLE_VALUE
;
1037 return Request
.Data
.GetInputHandleRequest
.Handle
;
1042 * @unimplemented (Undocumented)
1046 SetConsoleCommandHistoryMode(DWORD dwMode
)
1048 DPRINT1("SetConsoleCommandHistoryMode(0x%x) UNIMPLEMENTED!\n", dwMode
);
1049 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1055 * @unimplemented (Undocumented)
1059 SetConsoleCursor(DWORD Unknown0
,
1062 DPRINT1("SetConsoleCursor(0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
);
1063 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1073 SetConsoleDisplayMode(HANDLE hOut
,
1077 * FUNCTION: Set the console display mode.
1079 * hOut - Standard output handle.
1080 * dwNewMode - New mode.
1081 * lpdwOldMode - Address of a variable that receives the old mode.
1084 DPRINT1("SetConsoleDisplayMode(0x%x, 0x%x, 0x%p) UNIMPLEMENTED!\n", hOut
, dwNewMode
, lpdwOldMode
);
1085 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1091 * @unimplemented (Undocumented)
1095 SetConsoleFont(DWORD Unknown0
,
1098 DPRINT1("SetConsoleFont(0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
);
1099 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1105 * @implemented (Undocumented)
1109 SetConsoleHardwareState(HANDLE hConsole
,
1113 CSR_API_MESSAGE Request
;
1117 CsrRequest
= MAKE_CSR_API(SETGET_CONSOLE_HW_STATE
, CSR_CONSOLE
);
1118 Request
.Data
.ConsoleHardwareStateRequest
.ConsoleHandle
= hConsole
;
1119 Request
.Data
.ConsoleHardwareStateRequest
.SetGet
= CONSOLE_HARDWARE_STATE_SET
;
1120 Request
.Data
.ConsoleHardwareStateRequest
.State
= State
;
1122 Status
= CsrClientCallServer(&Request
,
1125 sizeof(CSR_API_MESSAGE
));
1126 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
1128 SetLastErrorByStatus(Status
);
1137 * @unimplemented (Undocumented)
1141 SetConsoleKeyShortcuts(DWORD Unknown0
,
1146 DPRINT1("SetConsoleKeyShortcuts(0x%x, 0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
, Unknown2
, Unknown3
);
1147 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1153 * @unimplemented (Undocumented)
1157 SetConsoleMaximumWindowSize(DWORD Unknown0
,
1160 DPRINT1("SetConsoleMaximumWindowSize(0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
);
1161 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1167 * @unimplemented (Undocumented)
1171 SetConsoleMenuClose(DWORD Unknown0
)
1173 DPRINT1("SetConsoleMenuClose(0x%x) UNIMPLEMENTED!\n", Unknown0
);
1174 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1180 * @unimplemented (Undocumented)
1184 SetConsoleNumberOfCommandsA(DWORD Unknown0
,
1187 DPRINT1("SetConsoleNumberOfCommandsA(0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
);
1188 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1194 * @unimplemented (Undocumented)
1198 SetConsoleNumberOfCommandsW(DWORD Unknown0
,
1201 DPRINT1("SetConsoleNumberOfCommandsW(0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
);
1202 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1208 * @unimplemented (Undocumented)
1212 SetConsolePalette(DWORD Unknown0
,
1216 DPRINT1("SetConsolePalette(0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
, Unknown2
);
1217 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1223 * @unimplemented (Undocumented)
1227 SetLastConsoleEventActive(VOID
)
1229 DPRINT1("SetLastConsoleEventActive() UNIMPLEMENTED!\n");
1230 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1236 * @unimplemented (Undocumented)
1240 ShowConsoleCursor(DWORD Unknown0
,
1243 DPRINT1("ShowConsoleCursor(0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
);
1244 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1250 * FUNCTION: Checks whether the given handle is a valid console handle.
1252 * Handle - Handle to be checked
1254 * TRUE: Handle is a valid console handle
1255 * FALSE: Handle is not a valid console handle.
1256 * STATUS: Officially undocumented
1262 VerifyConsoleIoHandle(HANDLE Handle
)
1264 CSR_API_MESSAGE Request
;
1268 CsrRequest
= MAKE_CSR_API(VERIFY_HANDLE
, CSR_NATIVE
);
1269 Request
.Data
.VerifyHandleRequest
.Handle
= Handle
;
1271 Status
= CsrClientCallServer(&Request
,
1274 sizeof(CSR_API_MESSAGE
));
1275 if (!NT_SUCCESS(Status
))
1277 SetLastErrorByStatus(Status
);
1281 return (BOOL
)NT_SUCCESS(Request
.Status
);
1290 WriteConsoleInputVDMA(DWORD Unknown0
,
1295 DPRINT1("WriteConsoleInputVDMA(0x%x, 0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
, Unknown2
, Unknown3
);
1296 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1306 WriteConsoleInputVDMW(DWORD Unknown0
,
1311 DPRINT1("WriteConsoleInputVDMW(0x%x, 0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
, Unknown2
, Unknown3
);
1312 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1318 * @implemented (Undocumented)
1322 CloseConsoleHandle(HANDLE Handle
)
1324 CSR_API_MESSAGE Request
;
1328 CsrRequest
= MAKE_CSR_API(CLOSE_HANDLE
, CSR_NATIVE
);
1329 Request
.Data
.CloseHandleRequest
.Handle
= Handle
;
1331 Status
= CsrClientCallServer(&Request
,
1334 sizeof(CSR_API_MESSAGE
));
1335 if (!NT_SUCCESS(Status
))
1337 SetLastErrorByStatus(Status
);
1349 GetStdHandle(DWORD nStdHandle
)
1351 * FUNCTION: Get a handle for the standard input, standard output
1352 * and a standard error device.
1354 * nStdHandle - Specifies the device for which to return the handle.
1355 * RETURNS: If the function succeeds, the return value is the handle
1356 * of the specified device. Otherwise the value is INVALID_HANDLE_VALUE.
1359 PRTL_USER_PROCESS_PARAMETERS Ppb
;
1361 Ppb
= NtCurrentPeb()->ProcessParameters
;
1364 case STD_INPUT_HANDLE
:
1365 return Ppb
->StandardInput
;
1367 case STD_OUTPUT_HANDLE
:
1368 return Ppb
->StandardOutput
;
1370 case STD_ERROR_HANDLE
:
1371 return Ppb
->StandardError
;
1374 SetLastError (ERROR_INVALID_PARAMETER
);
1375 return INVALID_HANDLE_VALUE
;
1384 SetStdHandle(DWORD nStdHandle
,
1387 * FUNCTION: Set the handle for the standard input, standard output or
1388 * the standard error device.
1390 * nStdHandle - Specifies the handle to be set.
1391 * hHandle - The handle to set.
1392 * RETURNS: TRUE if the function succeeds, FALSE otherwise.
1395 PRTL_USER_PROCESS_PARAMETERS Ppb
;
1397 /* no need to check if hHandle == INVALID_HANDLE_VALUE */
1399 Ppb
= NtCurrentPeb()->ProcessParameters
;
1403 case STD_INPUT_HANDLE
:
1404 Ppb
->StandardInput
= hHandle
;
1407 case STD_OUTPUT_HANDLE
:
1408 Ppb
->StandardOutput
= hHandle
;
1411 case STD_ERROR_HANDLE
:
1412 Ppb
->StandardError
= hHandle
;
1416 /* windows for whatever reason sets the last error to ERROR_INVALID_HANDLE here */
1417 SetLastError(ERROR_INVALID_HANDLE
);
1424 IntWriteConsole(HANDLE hConsoleOutput
,
1426 DWORD nNumberOfCharsToWrite
,
1427 LPDWORD lpNumberOfCharsWritten
,
1431 PCSR_API_MESSAGE Request
;
1435 ULONG SizeBytes
, CharSize
;
1438 CharSize
= (bUnicode
? sizeof(WCHAR
) : sizeof(CHAR
));
1439 Request
= RtlAllocateHeap(RtlGetProcessHeap(),
1441 max(sizeof(CSR_API_MESSAGE
),
1442 CSR_API_MESSAGE_HEADER_SIZE(CSRSS_WRITE_CONSOLE
) + min(nNumberOfCharsToWrite
,
1443 CSRSS_MAX_WRITE_CONSOLE
/ CharSize
) * CharSize
));
1444 if (Request
== NULL
)
1446 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1450 CsrRequest
= MAKE_CSR_API(WRITE_CONSOLE
, CSR_CONSOLE
);
1452 while (nNumberOfCharsToWrite
> 0)
1454 Request
->Data
.WriteConsoleRequest
.ConsoleHandle
= hConsoleOutput
;
1455 Request
->Data
.WriteConsoleRequest
.Unicode
= bUnicode
;
1457 nChars
= (USHORT
)min(nNumberOfCharsToWrite
, CSRSS_MAX_WRITE_CONSOLE
/ CharSize
);
1458 Request
->Data
.WriteConsoleRequest
.NrCharactersToWrite
= nChars
;
1460 SizeBytes
= nChars
* CharSize
;
1462 memcpy(Request
->Data
.WriteConsoleRequest
.Buffer
, lpBuffer
, SizeBytes
);
1464 Status
= CsrClientCallServer(Request
,
1467 max(sizeof(CSR_API_MESSAGE
),
1468 CSR_API_MESSAGE_HEADER_SIZE(CSRSS_WRITE_CONSOLE
) + SizeBytes
));
1470 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
->Status
))
1472 RtlFreeHeap(RtlGetProcessHeap(), 0, Request
);
1473 SetLastErrorByStatus(Status
);
1477 nNumberOfCharsToWrite
-= nChars
;
1478 lpBuffer
= (PVOID
)((ULONG_PTR
)lpBuffer
+ (ULONG_PTR
)SizeBytes
);
1479 Written
+= Request
->Data
.WriteConsoleRequest
.NrCharactersWritten
;
1482 if (lpNumberOfCharsWritten
!= NULL
)
1484 *lpNumberOfCharsWritten
= Written
;
1486 RtlFreeHeap(RtlGetProcessHeap(), 0, Request
);
1492 /*--------------------------------------------------------------
1499 WriteConsoleA(HANDLE hConsoleOutput
,
1500 CONST VOID
*lpBuffer
,
1501 DWORD nNumberOfCharsToWrite
,
1502 LPDWORD lpNumberOfCharsWritten
,
1505 return IntWriteConsole(hConsoleOutput
,
1507 nNumberOfCharsToWrite
,
1508 lpNumberOfCharsWritten
,
1514 /*--------------------------------------------------------------
1521 WriteConsoleW(HANDLE hConsoleOutput
,
1522 CONST VOID
*lpBuffer
,
1523 DWORD nNumberOfCharsToWrite
,
1524 LPDWORD lpNumberOfCharsWritten
,
1527 return IntWriteConsole(hConsoleOutput
,
1529 nNumberOfCharsToWrite
,
1530 lpNumberOfCharsWritten
,
1538 IntReadConsole(HANDLE hConsoleInput
,
1540 DWORD nNumberOfCharsToRead
,
1541 LPDWORD lpNumberOfCharsRead
,
1542 PCONSOLE_READCONSOLE_CONTROL lpReserved
,
1545 PCSR_API_MESSAGE Request
;
1548 ULONG CharSize
, CharsRead
= 0;
1550 CharSize
= (bUnicode
? sizeof(WCHAR
) : sizeof(CHAR
));
1551 Request
= RtlAllocateHeap(RtlGetProcessHeap(),
1553 max(sizeof(CSR_API_MESSAGE
),
1554 CSR_API_MESSAGE_HEADER_SIZE(CSRSS_READ_CONSOLE
) + min(nNumberOfCharsToRead
,
1555 CSRSS_MAX_READ_CONSOLE
/ CharSize
) * CharSize
));
1556 if (Request
== NULL
)
1558 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1562 Request
->Status
= STATUS_SUCCESS
;
1563 CsrRequest
= MAKE_CSR_API(READ_CONSOLE
, CSR_CONSOLE
);
1567 if (Request
->Status
== STATUS_PENDING
)
1569 Status
= NtWaitForSingleObject(Request
->Data
.ReadConsoleRequest
.EventHandle
,
1572 if (!NT_SUCCESS(Status
))
1574 DPRINT1("Wait for console input failed!\n");
1579 Request
->Data
.ReadConsoleRequest
.ConsoleHandle
= hConsoleInput
;
1580 Request
->Data
.ReadConsoleRequest
.Unicode
= bUnicode
;
1581 Request
->Data
.ReadConsoleRequest
.NrCharactersToRead
= (WORD
)min(nNumberOfCharsToRead
, CSRSS_MAX_READ_CONSOLE
/ CharSize
);
1582 Request
->Data
.ReadConsoleRequest
.nCharsCanBeDeleted
= (WORD
)CharsRead
;
1584 Status
= CsrClientCallServer(Request
,
1587 max(sizeof(CSR_API_MESSAGE
),
1588 CSR_API_MESSAGE_HEADER_SIZE(CSRSS_READ_CONSOLE
)
1589 + Request
->Data
.ReadConsoleRequest
.NrCharactersToRead
* CharSize
));
1591 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
->Status
))
1593 DPRINT1("CSR returned error in ReadConsole\n");
1594 RtlFreeHeap(RtlGetProcessHeap(), 0, Request
);
1595 SetLastErrorByStatus(Status
);
1599 nNumberOfCharsToRead
-= Request
->Data
.ReadConsoleRequest
.NrCharactersRead
;
1600 memcpy((PVOID
)((ULONG_PTR
)lpBuffer
+ (ULONG_PTR
)(CharsRead
* CharSize
)),
1601 Request
->Data
.ReadConsoleRequest
.Buffer
,
1602 Request
->Data
.ReadConsoleRequest
.NrCharactersRead
* CharSize
);
1603 CharsRead
+= Request
->Data
.ReadConsoleRequest
.NrCharactersRead
;
1605 if (Request
->Status
== STATUS_NOTIFY_CLEANUP
)
1610 nNumberOfCharsToRead
++;
1612 Request
->Status
= STATUS_PENDING
;
1615 while (Request
->Status
== STATUS_PENDING
&& nNumberOfCharsToRead
> 0);
1617 if (lpNumberOfCharsRead
!= NULL
)
1619 *lpNumberOfCharsRead
= CharsRead
;
1622 RtlFreeHeap(RtlGetProcessHeap(), 0, Request
);
1628 /*--------------------------------------------------------------
1635 ReadConsoleA(HANDLE hConsoleInput
,
1637 DWORD nNumberOfCharsToRead
,
1638 LPDWORD lpNumberOfCharsRead
,
1639 PCONSOLE_READCONSOLE_CONTROL pInputControl
)
1641 return IntReadConsole(hConsoleInput
,
1643 nNumberOfCharsToRead
,
1644 lpNumberOfCharsRead
,
1650 /*--------------------------------------------------------------
1657 ReadConsoleW(HANDLE hConsoleInput
,
1659 DWORD nNumberOfCharsToRead
,
1660 LPDWORD lpNumberOfCharsRead
,
1661 PCONSOLE_READCONSOLE_CONTROL pInputControl
)
1663 return IntReadConsole(hConsoleInput
,
1665 nNumberOfCharsToRead
,
1666 lpNumberOfCharsRead
,
1672 /*--------------------------------------------------------------
1681 CSR_API_MESSAGE Request
;
1686 if (NtCurrentPeb()->ProcessParameters
->ConsoleHandle
)
1688 DPRINT("AllocConsole: Allocate duplicate console to the same Process\n");
1689 SetLastErrorByStatus (STATUS_OBJECT_NAME_EXISTS
);
1693 Request
.Data
.AllocConsoleRequest
.CtrlDispatcher
= ConsoleControlDispatcher
;
1694 Request
.Data
.AllocConsoleRequest
.ConsoleNeeded
= TRUE
;
1695 Request
.Data
.AllocConsoleRequest
.Visible
= TRUE
;
1697 CsrRequest
= MAKE_CSR_API(ALLOC_CONSOLE
, CSR_CONSOLE
);
1699 Status
= CsrClientCallServer(&Request
, NULL
, CsrRequest
, sizeof(CSR_API_MESSAGE
));
1700 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
1702 SetLastErrorByStatus(Status
);
1706 NtCurrentPeb()->ProcessParameters
->ConsoleHandle
= Request
.Data
.AllocConsoleRequest
.Console
;
1708 SetStdHandle(STD_INPUT_HANDLE
, Request
.Data
.AllocConsoleRequest
.InputHandle
);
1709 SetStdHandle(STD_OUTPUT_HANDLE
, Request
.Data
.AllocConsoleRequest
.OutputHandle
);
1711 hStdError
= DuplicateConsoleHandle(Request
.Data
.AllocConsoleRequest
.OutputHandle
,
1714 DUPLICATE_SAME_ACCESS
);
1716 SetStdHandle(STD_ERROR_HANDLE
, hStdError
);
1721 /*--------------------------------------------------------------
1730 // AG: I'm not sure if this is correct (what happens to std handles?)
1731 // but I just tried to reverse what AllocConsole() does...
1733 CSR_API_MESSAGE Request
;
1737 CsrRequest
= MAKE_CSR_API(FREE_CONSOLE
, CSR_CONSOLE
);
1739 Status
= CsrClientCallServer(&Request
, NULL
, CsrRequest
, sizeof(CSR_API_MESSAGE
));
1740 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
1742 SetLastErrorByStatus(Status
);
1746 NtCurrentPeb()->ProcessParameters
->ConsoleHandle
= NULL
;
1751 /*--------------------------------------------------------------
1752 * GetConsoleScreenBufferInfo
1758 GetConsoleScreenBufferInfo(HANDLE hConsoleOutput
,
1759 PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo
)
1761 CSR_API_MESSAGE Request
;
1765 CsrRequest
= MAKE_CSR_API(SCREEN_BUFFER_INFO
, CSR_CONSOLE
);
1766 Request
.Data
.ScreenBufferInfoRequest
.ConsoleHandle
= hConsoleOutput
;
1768 Status
= CsrClientCallServer(&Request
, NULL
, CsrRequest
, sizeof(CSR_API_MESSAGE
));
1769 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
1771 SetLastErrorByStatus(Status
);
1774 *lpConsoleScreenBufferInfo
= Request
.Data
.ScreenBufferInfoRequest
.Info
;
1779 /*--------------------------------------------------------------
1780 * SetConsoleCursorPosition
1786 SetConsoleCursorPosition(HANDLE hConsoleOutput
,
1787 COORD dwCursorPosition
)
1789 CSR_API_MESSAGE Request
;
1793 CsrRequest
= MAKE_CSR_API(SET_CURSOR
, CSR_CONSOLE
);
1794 Request
.Data
.SetCursorRequest
.ConsoleHandle
= hConsoleOutput
;
1795 Request
.Data
.SetCursorRequest
.Position
= dwCursorPosition
;
1797 Status
= CsrClientCallServer(&Request
, NULL
, CsrRequest
, sizeof(CSR_API_MESSAGE
));
1798 if(!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
1800 SetLastErrorByStatus(Status
);
1810 IntFillConsoleOutputCharacter(HANDLE hConsoleOutput
,
1814 LPDWORD lpNumberOfCharsWritten
,
1817 CSR_API_MESSAGE Request
;
1821 CsrRequest
= MAKE_CSR_API(FILL_OUTPUT
, CSR_CONSOLE
);
1822 Request
.Data
.FillOutputRequest
.ConsoleHandle
= hConsoleOutput
;
1823 Request
.Data
.FillOutputRequest
.Unicode
= bUnicode
;
1826 Request
.Data
.FillOutputRequest
.Char
.UnicodeChar
= *((WCHAR
*)cCharacter
);
1828 Request
.Data
.FillOutputRequest
.Char
.AsciiChar
= *((CHAR
*)cCharacter
);
1830 Request
.Data
.FillOutputRequest
.Position
= dwWriteCoord
;
1831 Request
.Data
.FillOutputRequest
.Length
= (WORD
)nLength
;
1833 Status
= CsrClientCallServer(&Request
,
1836 sizeof(CSR_API_MESSAGE
));
1838 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
1840 SetLastErrorByStatus(Status
);
1844 if(lpNumberOfCharsWritten
!= NULL
)
1846 *lpNumberOfCharsWritten
= Request
.Data
.FillOutputRequest
.NrCharactersWritten
;
1852 /*--------------------------------------------------------------
1853 * FillConsoleOutputCharacterA
1859 FillConsoleOutputCharacterA(HANDLE hConsoleOutput
,
1863 LPDWORD lpNumberOfCharsWritten
)
1865 return IntFillConsoleOutputCharacter(hConsoleOutput
,
1869 lpNumberOfCharsWritten
,
1874 /*--------------------------------------------------------------
1875 * FillConsoleOutputCharacterW
1881 FillConsoleOutputCharacterW(HANDLE hConsoleOutput
,
1885 LPDWORD lpNumberOfCharsWritten
)
1887 return IntFillConsoleOutputCharacter(hConsoleOutput
,
1891 lpNumberOfCharsWritten
,
1898 IntPeekConsoleInput(HANDLE hConsoleInput
,
1899 PINPUT_RECORD lpBuffer
,
1901 LPDWORD lpNumberOfEventsRead
,
1904 CSR_API_MESSAGE Request
;
1906 PCSR_CAPTURE_BUFFER CaptureBuffer
;
1910 if (lpBuffer
== NULL
)
1912 SetLastError(ERROR_INVALID_PARAMETER
);
1916 Size
= nLength
* sizeof(INPUT_RECORD
);
1918 /* Allocate a Capture Buffer */
1919 DPRINT("IntPeekConsoleInput: %lx %p\n", Size
, lpNumberOfEventsRead
);
1920 CaptureBuffer
= CsrAllocateCaptureBuffer(1, Size
);
1922 /* Allocate space in the Buffer */
1923 CsrCaptureMessageBuffer(CaptureBuffer
,
1926 (PVOID
*)&Request
.Data
.PeekConsoleInputRequest
.InputRecord
);
1928 /* Set up the data to send to the Console Server */
1929 CsrRequest
= MAKE_CSR_API(PEEK_CONSOLE_INPUT
, CSR_CONSOLE
);
1930 Request
.Data
.PeekConsoleInputRequest
.ConsoleHandle
= hConsoleInput
;
1931 Request
.Data
.PeekConsoleInputRequest
.Unicode
= bUnicode
;
1932 Request
.Data
.PeekConsoleInputRequest
.Length
= nLength
;
1934 /* Call the server */
1935 Status
= CsrClientCallServer(&Request
,
1938 sizeof(CSR_API_MESSAGE
));
1939 DPRINT("Server returned: %x\n", Request
.Status
);
1941 /* Check for success*/
1942 if (NT_SUCCESS(Request
.Status
))
1944 /* Return the number of events read */
1945 DPRINT("Events read: %lx\n", Request
.Data
.PeekConsoleInputRequest
.Length
);
1946 *lpNumberOfEventsRead
= Request
.Data
.PeekConsoleInputRequest
.Length
;
1948 /* Copy into the buffer */
1949 DPRINT("Copying to buffer\n");
1950 RtlCopyMemory(lpBuffer
,
1951 Request
.Data
.PeekConsoleInputRequest
.InputRecord
,
1952 sizeof(INPUT_RECORD
) * *lpNumberOfEventsRead
);
1957 *lpNumberOfEventsRead
= 0;
1958 SetLastErrorByStatus(Request
.Status
);
1961 /* Release the capture buffer */
1962 CsrFreeCaptureBuffer(CaptureBuffer
);
1964 /* Return TRUE or FALSE */
1965 return NT_SUCCESS(Request
.Status
);
1968 /*--------------------------------------------------------------
1975 PeekConsoleInputA(HANDLE hConsoleInput
,
1976 PINPUT_RECORD lpBuffer
,
1978 LPDWORD lpNumberOfEventsRead
)
1980 return IntPeekConsoleInput(hConsoleInput
,
1983 lpNumberOfEventsRead
,
1988 /*--------------------------------------------------------------
1995 PeekConsoleInputW(HANDLE hConsoleInput
,
1996 PINPUT_RECORD lpBuffer
,
1998 LPDWORD lpNumberOfEventsRead
)
2000 return IntPeekConsoleInput(hConsoleInput
,
2002 lpNumberOfEventsRead
,
2009 IntReadConsoleInput(HANDLE hConsoleInput
,
2010 PINPUT_RECORD lpBuffer
,
2012 LPDWORD lpNumberOfEventsRead
,
2015 CSR_API_MESSAGE Request
;
2020 CsrRequest
= MAKE_CSR_API(READ_INPUT
, CSR_CONSOLE
);
2025 Request
.Data
.ReadInputRequest
.ConsoleHandle
= hConsoleInput
;
2026 Request
.Data
.ReadInputRequest
.Unicode
= bUnicode
;
2028 Status
= CsrClientCallServer(&Request
,
2031 sizeof(CSR_API_MESSAGE
));
2032 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
2036 /* we couldn't read a single record, fail */
2037 SetLastErrorByStatus(Status
);
2042 /* FIXME - fail gracefully in case we already read at least one record? */
2046 else if (Status
== STATUS_PENDING
)
2050 Status
= NtWaitForSingleObject(Request
.Data
.ReadInputRequest
.Event
, FALSE
, 0);
2051 if (!NT_SUCCESS(Status
))
2053 SetLastErrorByStatus(Status
);
2059 /* nothing more to read (waiting for more input??), let's just bail */
2065 lpBuffer
[Read
++] = Request
.Data
.ReadInputRequest
.Input
;
2068 if (!Request
.Data
.ReadInputRequest
.MoreEvents
)
2070 /* nothing more to read, bail */
2076 if (lpNumberOfEventsRead
!= NULL
)
2078 *lpNumberOfEventsRead
= Read
;
2085 /*--------------------------------------------------------------
2092 ReadConsoleInputA(HANDLE hConsoleInput
,
2093 PINPUT_RECORD lpBuffer
,
2095 LPDWORD lpNumberOfEventsRead
)
2097 return IntReadConsoleInput(hConsoleInput
,
2100 lpNumberOfEventsRead
,
2105 /*--------------------------------------------------------------
2112 ReadConsoleInputW(HANDLE hConsoleInput
,
2113 PINPUT_RECORD lpBuffer
,
2115 LPDWORD lpNumberOfEventsRead
)
2117 return IntReadConsoleInput(hConsoleInput
,
2120 lpNumberOfEventsRead
,
2127 IntWriteConsoleInput(HANDLE hConsoleInput
,
2128 PINPUT_RECORD lpBuffer
,
2130 LPDWORD lpNumberOfEventsWritten
,
2133 CSR_API_MESSAGE Request
;
2135 PCSR_CAPTURE_BUFFER CaptureBuffer
;
2139 if (lpBuffer
== NULL
)
2141 SetLastError(ERROR_INVALID_PARAMETER
);
2145 Size
= nLength
* sizeof(INPUT_RECORD
);
2147 /* Allocate a Capture Buffer */
2148 DPRINT("IntWriteConsoleInput: %lx %p\n", Size
, lpNumberOfEventsWritten
);
2149 CaptureBuffer
= CsrAllocateCaptureBuffer(1, Size
);
2151 /* Allocate space in the Buffer */
2152 CsrCaptureMessageBuffer(CaptureBuffer
,
2155 (PVOID
*)&Request
.Data
.WriteConsoleInputRequest
.InputRecord
);
2157 /* Set up the data to send to the Console Server */
2158 CsrRequest
= MAKE_CSR_API(WRITE_CONSOLE_INPUT
, CSR_CONSOLE
);
2159 Request
.Data
.WriteConsoleInputRequest
.ConsoleHandle
= hConsoleInput
;
2160 Request
.Data
.WriteConsoleInputRequest
.Unicode
= bUnicode
;
2161 Request
.Data
.WriteConsoleInputRequest
.Length
= nLength
;
2163 /* Call the server */
2164 Status
= CsrClientCallServer(&Request
,
2167 sizeof(CSR_API_MESSAGE
));
2168 DPRINT("Server returned: %x\n", Request
.Status
);
2170 /* Check for success*/
2171 if (NT_SUCCESS(Request
.Status
))
2173 /* Return the number of events read */
2174 DPRINT("Events read: %lx\n", Request
.Data
.WriteConsoleInputRequest
.Length
);
2175 *lpNumberOfEventsWritten
= Request
.Data
.WriteConsoleInputRequest
.Length
;
2180 *lpNumberOfEventsWritten
= 0;
2181 SetLastErrorByStatus(Request
.Status
);
2184 /* Release the capture buffer */
2185 CsrFreeCaptureBuffer(CaptureBuffer
);
2187 /* Return TRUE or FALSE */
2188 return NT_SUCCESS(Request
.Status
);
2192 /*--------------------------------------------------------------
2193 * WriteConsoleInputA
2199 WriteConsoleInputA(HANDLE hConsoleInput
,
2200 CONST INPUT_RECORD
*lpBuffer
,
2202 LPDWORD lpNumberOfEventsWritten
)
2204 return IntWriteConsoleInput(hConsoleInput
,
2205 (PINPUT_RECORD
)lpBuffer
,
2207 lpNumberOfEventsWritten
,
2212 /*--------------------------------------------------------------
2213 * WriteConsoleInputW
2219 WriteConsoleInputW(HANDLE hConsoleInput
,
2220 CONST INPUT_RECORD
*lpBuffer
,
2222 LPDWORD lpNumberOfEventsWritten
)
2224 return IntWriteConsoleInput(hConsoleInput
,
2225 (PINPUT_RECORD
)lpBuffer
,
2227 lpNumberOfEventsWritten
,
2234 IntReadConsoleOutput(HANDLE hConsoleOutput
,
2235 PCHAR_INFO lpBuffer
,
2237 COORD dwBufferCoord
,
2238 PSMALL_RECT lpReadRegion
,
2241 CSR_API_MESSAGE Request
;
2243 PCSR_CAPTURE_BUFFER CaptureBuffer
;
2245 DWORD Size
, SizeX
, SizeY
;
2247 if (lpBuffer
== NULL
)
2249 SetLastError(ERROR_INVALID_PARAMETER
);
2253 Size
= dwBufferSize
.X
* dwBufferSize
.Y
* sizeof(CHAR_INFO
);
2255 /* Allocate a Capture Buffer */
2256 DPRINT("IntReadConsoleOutput: %lx %p\n", Size
, lpReadRegion
);
2257 CaptureBuffer
= CsrAllocateCaptureBuffer(1, Size
);
2259 /* Allocate space in the Buffer */
2260 CsrCaptureMessageBuffer(CaptureBuffer
,
2263 (PVOID
*)&Request
.Data
.ReadConsoleOutputRequest
.CharInfo
);
2265 /* Set up the data to send to the Console Server */
2266 CsrRequest
= MAKE_CSR_API(READ_CONSOLE_OUTPUT
, CSR_CONSOLE
);
2267 Request
.Data
.ReadConsoleOutputRequest
.ConsoleHandle
= hConsoleOutput
;
2268 Request
.Data
.ReadConsoleOutputRequest
.Unicode
= bUnicode
;
2269 Request
.Data
.ReadConsoleOutputRequest
.BufferSize
= dwBufferSize
;
2270 Request
.Data
.ReadConsoleOutputRequest
.BufferCoord
= dwBufferCoord
;
2271 Request
.Data
.ReadConsoleOutputRequest
.ReadRegion
= *lpReadRegion
;
2273 /* Call the server */
2274 Status
= CsrClientCallServer(&Request
,
2277 sizeof(CSR_API_MESSAGE
));
2278 DPRINT("Server returned: %x\n", Request
.Status
);
2280 /* Check for success*/
2281 if (NT_SUCCESS(Request
.Status
))
2283 /* Copy into the buffer */
2284 DPRINT("Copying to buffer\n");
2285 SizeX
= Request
.Data
.ReadConsoleOutputRequest
.ReadRegion
.Right
-
2286 Request
.Data
.ReadConsoleOutputRequest
.ReadRegion
.Left
+ 1;
2287 SizeY
= Request
.Data
.ReadConsoleOutputRequest
.ReadRegion
.Bottom
-
2288 Request
.Data
.ReadConsoleOutputRequest
.ReadRegion
.Top
+ 1;
2289 RtlCopyMemory(lpBuffer
,
2290 Request
.Data
.ReadConsoleOutputRequest
.CharInfo
,
2291 sizeof(CHAR_INFO
) * SizeX
* SizeY
);
2296 SetLastErrorByStatus(Request
.Status
);
2299 /* Return the read region */
2300 DPRINT("read region: %lx\n", Request
.Data
.ReadConsoleOutputRequest
.ReadRegion
);
2301 *lpReadRegion
= Request
.Data
.ReadConsoleOutputRequest
.ReadRegion
;
2303 /* Release the capture buffer */
2304 CsrFreeCaptureBuffer(CaptureBuffer
);
2306 /* Return TRUE or FALSE */
2307 return NT_SUCCESS(Request
.Status
);
2310 /*--------------------------------------------------------------
2311 * ReadConsoleOutputA
2317 ReadConsoleOutputA(HANDLE hConsoleOutput
,
2318 PCHAR_INFO lpBuffer
,
2320 COORD dwBufferCoord
,
2321 PSMALL_RECT lpReadRegion
)
2323 return IntReadConsoleOutput(hConsoleOutput
,
2332 /*--------------------------------------------------------------
2333 * ReadConsoleOutputW
2339 ReadConsoleOutputW(HANDLE hConsoleOutput
,
2340 PCHAR_INFO lpBuffer
,
2342 COORD dwBufferCoord
,
2343 PSMALL_RECT lpReadRegion
)
2345 return IntReadConsoleOutput(hConsoleOutput
,
2356 IntWriteConsoleOutput(HANDLE hConsoleOutput
,
2357 CONST CHAR_INFO
*lpBuffer
,
2359 COORD dwBufferCoord
,
2360 PSMALL_RECT lpWriteRegion
,
2363 CSR_API_MESSAGE Request
;
2365 PCSR_CAPTURE_BUFFER CaptureBuffer
;
2369 Size
= dwBufferSize
.Y
* dwBufferSize
.X
* sizeof(CHAR_INFO
);
2371 /* Allocate a Capture Buffer */
2372 DPRINT("IntWriteConsoleOutput: %lx %p\n", Size
, lpWriteRegion
);
2373 CaptureBuffer
= CsrAllocateCaptureBuffer(1, Size
);
2375 /* Allocate space in the Buffer */
2376 CsrCaptureMessageBuffer(CaptureBuffer
,
2379 (PVOID
*)&Request
.Data
.WriteConsoleOutputRequest
.CharInfo
);
2381 /* Copy from the buffer */
2382 RtlCopyMemory(Request
.Data
.WriteConsoleOutputRequest
.CharInfo
, lpBuffer
, Size
);
2384 /* Set up the data to send to the Console Server */
2385 CsrRequest
= MAKE_CSR_API(WRITE_CONSOLE_OUTPUT
, CSR_CONSOLE
);
2386 Request
.Data
.WriteConsoleOutputRequest
.ConsoleHandle
= hConsoleOutput
;
2387 Request
.Data
.WriteConsoleOutputRequest
.Unicode
= bUnicode
;
2388 Request
.Data
.WriteConsoleOutputRequest
.BufferSize
= dwBufferSize
;
2389 Request
.Data
.WriteConsoleOutputRequest
.BufferCoord
= dwBufferCoord
;
2390 Request
.Data
.WriteConsoleOutputRequest
.WriteRegion
= *lpWriteRegion
;
2392 /* Call the server */
2393 Status
= CsrClientCallServer(&Request
,
2396 sizeof(CSR_API_MESSAGE
));
2397 DPRINT("Server returned: %x\n", Request
.Status
);
2399 /* Check for success*/
2400 if (!NT_SUCCESS(Request
.Status
))
2403 SetLastErrorByStatus(Request
.Status
);
2406 /* Return the read region */
2407 DPRINT("read region: %lx\n", Request
.Data
.WriteConsoleOutputRequest
.WriteRegion
);
2408 *lpWriteRegion
= Request
.Data
.WriteConsoleOutputRequest
.WriteRegion
;
2410 /* Release the capture buffer */
2411 CsrFreeCaptureBuffer(CaptureBuffer
);
2413 /* Return TRUE or FALSE */
2414 return NT_SUCCESS(Request
.Status
);
2417 /*--------------------------------------------------------------
2418 * WriteConsoleOutputA
2424 WriteConsoleOutputA(HANDLE hConsoleOutput
,
2425 CONST CHAR_INFO
*lpBuffer
,
2427 COORD dwBufferCoord
,
2428 PSMALL_RECT lpWriteRegion
)
2430 return IntWriteConsoleOutput(hConsoleOutput
,
2439 /*--------------------------------------------------------------
2440 * WriteConsoleOutputW
2446 WriteConsoleOutputW(HANDLE hConsoleOutput
,
2447 CONST CHAR_INFO
*lpBuffer
,
2449 COORD dwBufferCoord
,
2450 PSMALL_RECT lpWriteRegion
)
2452 return IntWriteConsoleOutput(hConsoleOutput
,
2463 IntReadConsoleOutputCharacter(HANDLE hConsoleOutput
,
2467 LPDWORD lpNumberOfCharsRead
,
2470 PCSR_API_MESSAGE Request
;
2473 ULONG nChars
, SizeBytes
, CharSize
;
2474 DWORD CharsRead
= 0;
2476 CharSize
= (bUnicode
? sizeof(WCHAR
) : sizeof(CHAR
));
2478 nChars
= min(nLength
, CSRSS_MAX_READ_CONSOLE_OUTPUT_CHAR
) / CharSize
;
2479 SizeBytes
= nChars
* CharSize
;
2481 Request
= RtlAllocateHeap(RtlGetProcessHeap(), 0,
2482 max(sizeof(CSR_API_MESSAGE
),
2483 CSR_API_MESSAGE_HEADER_SIZE(CSRSS_READ_CONSOLE_OUTPUT_CHAR
)
2484 + min (nChars
, CSRSS_MAX_READ_CONSOLE_OUTPUT_CHAR
/ CharSize
) * CharSize
));
2485 if (Request
== NULL
)
2487 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2491 CsrRequest
= MAKE_CSR_API(READ_CONSOLE_OUTPUT_CHAR
, CSR_CONSOLE
);
2492 Request
->Data
.ReadConsoleOutputCharRequest
.ReadCoord
= dwReadCoord
;
2498 Request
->Data
.ReadConsoleOutputCharRequest
.ConsoleHandle
= hConsoleOutput
;
2499 Request
->Data
.ReadConsoleOutputCharRequest
.Unicode
= bUnicode
;
2500 Request
->Data
.ReadConsoleOutputCharRequest
.NumCharsToRead
= min(nLength
, nChars
);
2501 SizeBytes
= Request
->Data
.ReadConsoleOutputCharRequest
.NumCharsToRead
* CharSize
;
2503 Status
= CsrClientCallServer(Request
,
2506 max(sizeof(CSR_API_MESSAGE
),
2507 CSR_API_MESSAGE_HEADER_SIZE(CSRSS_READ_CONSOLE_OUTPUT_CHAR
) + SizeBytes
));
2508 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Request
->Status
))
2510 RtlFreeHeap(RtlGetProcessHeap(), 0, Request
);
2511 SetLastErrorByStatus(Status
);
2515 BytesRead
= Request
->Data
.ReadConsoleOutputCharRequest
.CharsRead
* CharSize
;
2516 memcpy(lpCharacter
, Request
->Data
.ReadConsoleOutputCharRequest
.String
, BytesRead
);
2517 lpCharacter
= (PVOID
)((ULONG_PTR
)lpCharacter
+ (ULONG_PTR
)BytesRead
);
2518 CharsRead
+= Request
->Data
.ReadConsoleOutputCharRequest
.CharsRead
;
2519 nLength
-= Request
->Data
.ReadConsoleOutputCharRequest
.CharsRead
;
2521 Request
->Data
.ReadConsoleOutputCharRequest
.ReadCoord
= Request
->Data
.ReadConsoleOutputCharRequest
.EndCoord
;
2524 if (lpNumberOfCharsRead
!= NULL
)
2526 *lpNumberOfCharsRead
= CharsRead
;
2529 RtlFreeHeap(RtlGetProcessHeap(), 0, Request
);
2535 /*--------------------------------------------------------------
2536 * ReadConsoleOutputCharacterA
2542 ReadConsoleOutputCharacterA(HANDLE hConsoleOutput
,
2546 LPDWORD lpNumberOfCharsRead
)
2548 return IntReadConsoleOutputCharacter(hConsoleOutput
,
2552 lpNumberOfCharsRead
,
2557 /*--------------------------------------------------------------
2558 * ReadConsoleOutputCharacterW
2564 ReadConsoleOutputCharacterW(HANDLE hConsoleOutput
,
2568 LPDWORD lpNumberOfCharsRead
)
2570 return IntReadConsoleOutputCharacter(hConsoleOutput
,
2574 lpNumberOfCharsRead
,
2579 /*--------------------------------------------------------------
2580 * ReadConsoleOutputAttribute
2586 ReadConsoleOutputAttribute(HANDLE hConsoleOutput
,
2590 LPDWORD lpNumberOfAttrsRead
)
2592 PCSR_API_MESSAGE Request
;
2597 if (lpNumberOfAttrsRead
!= NULL
)
2598 *lpNumberOfAttrsRead
= nLength
;
2600 Request
= RtlAllocateHeap(RtlGetProcessHeap(),
2602 max(sizeof(CSR_API_MESSAGE
),
2603 CSR_API_MESSAGE_HEADER_SIZE(CSRSS_READ_CONSOLE_OUTPUT_ATTRIB
)
2604 + min (nLength
, CSRSS_MAX_READ_CONSOLE_OUTPUT_ATTRIB
/ sizeof(WORD
)) * sizeof(WORD
)));
2605 if (Request
== NULL
)
2607 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2611 CsrRequest
= MAKE_CSR_API(READ_CONSOLE_OUTPUT_ATTRIB
, CSR_CONSOLE
);
2613 while (nLength
!= 0)
2615 Request
->Data
.ReadConsoleOutputAttribRequest
.ConsoleHandle
= hConsoleOutput
;
2616 Request
->Data
.ReadConsoleOutputAttribRequest
.ReadCoord
= dwReadCoord
;
2618 if (nLength
> CSRSS_MAX_READ_CONSOLE_OUTPUT_ATTRIB
/ sizeof(WORD
))
2619 Size
= CSRSS_MAX_READ_CONSOLE_OUTPUT_ATTRIB
/ sizeof(WCHAR
);
2623 Request
->Data
.ReadConsoleOutputAttribRequest
.NumAttrsToRead
= Size
;
2625 Status
= CsrClientCallServer(Request
,
2628 max(sizeof(CSR_API_MESSAGE
),
2629 CSR_API_MESSAGE_HEADER_SIZE(CSRSS_READ_CONSOLE_OUTPUT_ATTRIB
) + Size
* sizeof(WORD
)));
2630 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Request
->Status
))
2632 RtlFreeHeap(RtlGetProcessHeap(), 0, Request
);
2633 SetLastErrorByStatus(Status
);
2637 memcpy(lpAttribute
, Request
->Data
.ReadConsoleOutputAttribRequest
.Attribute
, Size
* sizeof(WORD
));
2638 lpAttribute
+= Size
;
2640 Request
->Data
.ReadConsoleOutputAttribRequest
.ReadCoord
= Request
->Data
.ReadConsoleOutputAttribRequest
.EndCoord
;
2643 RtlFreeHeap(RtlGetProcessHeap(), 0, Request
);
2651 IntWriteConsoleOutputCharacter(HANDLE hConsoleOutput
,
2655 LPDWORD lpNumberOfCharsWritten
,
2658 PCSR_API_MESSAGE Request
;
2661 ULONG SizeBytes
, CharSize
, nChars
;
2664 CharSize
= (bUnicode
? sizeof(WCHAR
) : sizeof(CHAR
));
2666 nChars
= min(nLength
, CSRSS_MAX_WRITE_CONSOLE_OUTPUT_CHAR
/ CharSize
);
2667 SizeBytes
= nChars
* CharSize
;
2669 Request
= RtlAllocateHeap(RtlGetProcessHeap(), 0,
2670 max(sizeof(CSR_API_MESSAGE
),
2671 CSR_API_MESSAGE_HEADER_SIZE(CSRSS_WRITE_CONSOLE_OUTPUT_CHAR
)
2672 + min (nChars
, CSRSS_MAX_WRITE_CONSOLE_OUTPUT_CHAR
/ CharSize
) * CharSize
));
2673 if (Request
== NULL
)
2675 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2679 CsrRequest
= MAKE_CSR_API(WRITE_CONSOLE_OUTPUT_CHAR
, CSR_CONSOLE
);
2680 Request
->Data
.WriteConsoleOutputCharRequest
.Coord
= dwWriteCoord
;
2686 Request
->Data
.WriteConsoleOutputCharRequest
.ConsoleHandle
= hConsoleOutput
;
2687 Request
->Data
.WriteConsoleOutputCharRequest
.Unicode
= bUnicode
;
2688 Request
->Data
.WriteConsoleOutputCharRequest
.Length
= (WORD
)min(nLength
, nChars
);
2689 BytesWrite
= Request
->Data
.WriteConsoleOutputCharRequest
.Length
* CharSize
;
2691 memcpy(Request
->Data
.WriteConsoleOutputCharRequest
.String
, lpCharacter
, BytesWrite
);
2693 Status
= CsrClientCallServer(Request
,
2696 max(sizeof(CSR_API_MESSAGE
),
2697 CSR_API_MESSAGE_HEADER_SIZE(CSRSS_WRITE_CONSOLE_OUTPUT_CHAR
) + BytesWrite
));
2699 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
->Status
))
2701 RtlFreeHeap(RtlGetProcessHeap(), 0, Request
);
2702 SetLastErrorByStatus(Status
);
2706 nLength
-= Request
->Data
.WriteConsoleOutputCharRequest
.NrCharactersWritten
;
2707 lpCharacter
= (PVOID
)((ULONG_PTR
)lpCharacter
+ (ULONG_PTR
)(Request
->Data
.WriteConsoleOutputCharRequest
.NrCharactersWritten
* CharSize
));
2708 Written
+= Request
->Data
.WriteConsoleOutputCharRequest
.NrCharactersWritten
;
2710 Request
->Data
.WriteConsoleOutputCharRequest
.Coord
= Request
->Data
.WriteConsoleOutputCharRequest
.EndCoord
;
2713 if (lpNumberOfCharsWritten
!= NULL
)
2715 *lpNumberOfCharsWritten
= Written
;
2718 RtlFreeHeap(RtlGetProcessHeap(), 0, Request
);
2724 /*--------------------------------------------------------------
2725 * WriteConsoleOutputCharacterA
2731 WriteConsoleOutputCharacterA(HANDLE hConsoleOutput
,
2735 LPDWORD lpNumberOfCharsWritten
)
2737 return IntWriteConsoleOutputCharacter(hConsoleOutput
,
2741 lpNumberOfCharsWritten
,
2746 /*--------------------------------------------------------------
2747 * WriteConsoleOutputCharacterW
2753 WriteConsoleOutputCharacterW(HANDLE hConsoleOutput
,
2754 LPCWSTR lpCharacter
,
2757 LPDWORD lpNumberOfCharsWritten
)
2759 return IntWriteConsoleOutputCharacter(hConsoleOutput
,
2763 lpNumberOfCharsWritten
,
2768 /*--------------------------------------------------------------
2769 * WriteConsoleOutputAttribute
2775 WriteConsoleOutputAttribute(HANDLE hConsoleOutput
,
2776 CONST WORD
*lpAttribute
,
2779 LPDWORD lpNumberOfAttrsWritten
)
2781 PCSR_API_MESSAGE Request
;
2786 Request
= RtlAllocateHeap(RtlGetProcessHeap(),
2788 max(sizeof(CSR_API_MESSAGE
),
2789 CSR_API_MESSAGE_HEADER_SIZE(CSRSS_WRITE_CONSOLE_OUTPUT_ATTRIB
)
2790 + min(nLength
, CSRSS_MAX_WRITE_CONSOLE_OUTPUT_ATTRIB
/ sizeof(WORD
)) * sizeof(WORD
)));
2791 if (Request
== NULL
)
2793 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2797 CsrRequest
= MAKE_CSR_API(WRITE_CONSOLE_OUTPUT_ATTRIB
, CSR_CONSOLE
);
2798 Request
->Data
.WriteConsoleOutputAttribRequest
.Coord
= dwWriteCoord
;
2800 if (lpNumberOfAttrsWritten
)
2801 *lpNumberOfAttrsWritten
= nLength
;
2804 Size
= (WORD
)min(nLength
, CSRSS_MAX_WRITE_CONSOLE_OUTPUT_ATTRIB
/ sizeof(WORD
));
2805 Request
->Data
.WriteConsoleOutputAttribRequest
.ConsoleHandle
= hConsoleOutput
;
2806 Request
->Data
.WriteConsoleOutputAttribRequest
.Length
= Size
;
2807 memcpy(Request
->Data
.WriteConsoleOutputAttribRequest
.Attribute
, lpAttribute
, Size
* sizeof(WORD
));
2809 Status
= CsrClientCallServer(Request
,
2812 max(sizeof(CSR_API_MESSAGE
),
2813 CSR_API_MESSAGE_HEADER_SIZE(CSRSS_WRITE_CONSOLE_OUTPUT_ATTRIB
) + Size
* sizeof(WORD
)));
2815 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
->Status
))
2817 RtlFreeHeap(RtlGetProcessHeap(), 0, Request
);
2818 SetLastErrorByStatus (Status
);
2822 lpAttribute
+= Size
;
2823 Request
->Data
.WriteConsoleOutputAttribRequest
.Coord
= Request
->Data
.WriteConsoleOutputAttribRequest
.EndCoord
;
2826 RtlFreeHeap(RtlGetProcessHeap(), 0, Request
);
2832 /*--------------------------------------------------------------
2833 * FillConsoleOutputAttribute
2839 FillConsoleOutputAttribute(HANDLE hConsoleOutput
,
2843 LPDWORD lpNumberOfAttrsWritten
)
2845 CSR_API_MESSAGE Request
;
2849 CsrRequest
= MAKE_CSR_API(FILL_OUTPUT_ATTRIB
, CSR_CONSOLE
);
2850 Request
.Data
.FillOutputAttribRequest
.ConsoleHandle
= hConsoleOutput
;
2851 Request
.Data
.FillOutputAttribRequest
.Attribute
= (CHAR
)wAttribute
;
2852 Request
.Data
.FillOutputAttribRequest
.Coord
= dwWriteCoord
;
2853 Request
.Data
.FillOutputAttribRequest
.Length
= (WORD
)nLength
;
2855 Status
= CsrClientCallServer(&Request
, NULL
, CsrRequest
, sizeof(CSR_API_MESSAGE
));
2856 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
2858 SetLastErrorByStatus ( Status
);
2862 if (lpNumberOfAttrsWritten
)
2863 *lpNumberOfAttrsWritten
= nLength
;
2869 /*--------------------------------------------------------------
2876 GetConsoleMode(HANDLE hConsoleHandle
,
2879 CSR_API_MESSAGE Request
;
2883 CsrRequest
= MAKE_CSR_API(GET_CONSOLE_MODE
, CSR_CONSOLE
);
2884 Request
.Data
.GetConsoleModeRequest
.ConsoleHandle
= hConsoleHandle
;
2886 Status
= CsrClientCallServer( &Request
, NULL
, CsrRequest
, sizeof( CSR_API_MESSAGE
) );
2887 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
2889 SetLastErrorByStatus ( Status
);
2892 *lpMode
= Request
.Data
.GetConsoleModeRequest
.ConsoleMode
;
2898 /*--------------------------------------------------------------
2899 * GetNumberOfConsoleInputEvents
2905 GetNumberOfConsoleInputEvents(HANDLE hConsoleInput
,
2906 LPDWORD lpNumberOfEvents
)
2908 CSR_API_MESSAGE Request
;
2912 if (lpNumberOfEvents
== NULL
)
2914 SetLastError(ERROR_INVALID_PARAMETER
);
2918 CsrRequest
= MAKE_CSR_API(GET_NUM_INPUT_EVENTS
, CSR_CONSOLE
);
2919 Request
.Data
.GetNumInputEventsRequest
.ConsoleHandle
= hConsoleInput
;
2921 Status
= CsrClientCallServer(&Request
, NULL
, CsrRequest
, sizeof(CSR_API_MESSAGE
));
2922 if(!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
2924 SetLastErrorByStatus(Status
);
2928 *lpNumberOfEvents
= Request
.Data
.GetNumInputEventsRequest
.NumInputEvents
;
2934 /*--------------------------------------------------------------
2935 * GetLargestConsoleWindowSize
2941 GetLargestConsoleWindowSize(HANDLE hConsoleOutput
)
2943 COORD Coord
= {80,25};
2944 DPRINT1("GetLargestConsoleWindowSize(0x%x) UNIMPLEMENTED!\n", hConsoleOutput
);
2945 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2950 /*--------------------------------------------------------------
2951 * GetConsoleCursorInfo
2957 GetConsoleCursorInfo(HANDLE hConsoleOutput
,
2958 PCONSOLE_CURSOR_INFO lpConsoleCursorInfo
)
2960 CSR_API_MESSAGE Request
;
2964 if (!lpConsoleCursorInfo
)
2966 if (!hConsoleOutput
)
2967 SetLastError(ERROR_INVALID_HANDLE
);
2969 SetLastError(ERROR_INVALID_ACCESS
);
2974 CsrRequest
= MAKE_CSR_API(GET_CURSOR_INFO
, CSR_CONSOLE
);
2975 Request
.Data
.GetCursorInfoRequest
.ConsoleHandle
= hConsoleOutput
;
2977 Status
= CsrClientCallServer(&Request
, NULL
, CsrRequest
, sizeof(CSR_API_MESSAGE
));
2979 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
2981 SetLastErrorByStatus(Status
);
2984 *lpConsoleCursorInfo
= Request
.Data
.GetCursorInfoRequest
.Info
;
2990 /*--------------------------------------------------------------
2991 * GetNumberOfConsoleMouseButtons
2997 GetNumberOfConsoleMouseButtons(LPDWORD lpNumberOfMouseButtons
)
2999 DPRINT1("GetNumberOfConsoleMouseButtons(0x%x) UNIMPLEMENTED!\n", lpNumberOfMouseButtons
);
3000 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3005 /*--------------------------------------------------------------
3012 SetConsoleMode(HANDLE hConsoleHandle
,
3015 CSR_API_MESSAGE Request
;
3019 CsrRequest
= MAKE_CSR_API(SET_CONSOLE_MODE
, CSR_CONSOLE
);
3020 Request
.Data
.SetConsoleModeRequest
.ConsoleHandle
= hConsoleHandle
;
3021 Request
.Data
.SetConsoleModeRequest
.Mode
= dwMode
;
3023 Status
= CsrClientCallServer(&Request
, NULL
, CsrRequest
, sizeof(CSR_API_MESSAGE
));
3024 if(!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
3026 SetLastErrorByStatus ( Status
);
3034 /*--------------------------------------------------------------
3035 * SetConsoleActiveScreenBuffer
3041 SetConsoleActiveScreenBuffer(HANDLE hConsoleOutput
)
3043 CSR_API_MESSAGE Request
;
3047 CsrRequest
= MAKE_CSR_API(SET_SCREEN_BUFFER
, CSR_CONSOLE
);
3048 Request
.Data
.SetScreenBufferRequest
.OutputHandle
= hConsoleOutput
;
3050 Status
= CsrClientCallServer(&Request
, NULL
, CsrRequest
, sizeof(CSR_API_MESSAGE
));
3051 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
3053 SetLastErrorByStatus(Status
);
3061 /*--------------------------------------------------------------
3062 * FlushConsoleInputBuffer
3068 FlushConsoleInputBuffer(HANDLE hConsoleInput
)
3070 CSR_API_MESSAGE Request
;
3074 CsrRequest
= MAKE_CSR_API(FLUSH_INPUT_BUFFER
, CSR_CONSOLE
);
3075 Request
.Data
.FlushInputBufferRequest
.ConsoleInput
= hConsoleInput
;
3077 Status
= CsrClientCallServer(&Request
, NULL
, CsrRequest
, sizeof(CSR_API_MESSAGE
));
3078 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
3080 SetLastErrorByStatus(Status
);
3088 /*--------------------------------------------------------------
3089 * SetConsoleScreenBufferSize
3095 SetConsoleScreenBufferSize(HANDLE hConsoleOutput
,
3098 CSR_API_MESSAGE Request
;
3102 CsrRequest
= MAKE_CSR_API(SET_SCREEN_BUFFER_SIZE
, CSR_CONSOLE
);
3103 Request
.Data
.SetScreenBufferSize
.OutputHandle
= hConsoleOutput
;
3104 Request
.Data
.SetScreenBufferSize
.Size
= dwSize
;
3106 Status
= CsrClientCallServer(&Request
, NULL
, CsrRequest
, sizeof(CSR_API_MESSAGE
));
3107 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
3109 SetLastErrorByStatus(Status
);
3116 /*--------------------------------------------------------------
3117 * SetConsoleCursorInfo
3123 SetConsoleCursorInfo(HANDLE hConsoleOutput
,
3124 CONST CONSOLE_CURSOR_INFO
*lpConsoleCursorInfo
)
3126 CSR_API_MESSAGE Request
;
3130 CsrRequest
= MAKE_CSR_API(SET_CURSOR_INFO
, CSR_CONSOLE
);
3131 Request
.Data
.SetCursorInfoRequest
.ConsoleHandle
= hConsoleOutput
;
3132 Request
.Data
.SetCursorInfoRequest
.Info
= *lpConsoleCursorInfo
;
3134 Status
= CsrClientCallServer(&Request
, NULL
, CsrRequest
, sizeof(CSR_API_MESSAGE
));
3135 if(!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
3137 SetLastErrorByStatus(Status
);
3147 IntScrollConsoleScreenBuffer(HANDLE hConsoleOutput
,
3148 const SMALL_RECT
*lpScrollRectangle
,
3149 const SMALL_RECT
*lpClipRectangle
,
3150 COORD dwDestinationOrigin
,
3151 const CHAR_INFO
*lpFill
,
3154 CSR_API_MESSAGE Request
;
3158 CsrRequest
= MAKE_CSR_API(SCROLL_CONSOLE_SCREEN_BUFFER
, CSR_CONSOLE
);
3159 Request
.Data
.ScrollConsoleScreenBufferRequest
.ConsoleHandle
= hConsoleOutput
;
3160 Request
.Data
.ScrollConsoleScreenBufferRequest
.Unicode
= bUnicode
;
3161 Request
.Data
.ScrollConsoleScreenBufferRequest
.ScrollRectangle
= *lpScrollRectangle
;
3163 if (lpClipRectangle
!= NULL
)
3165 Request
.Data
.ScrollConsoleScreenBufferRequest
.UseClipRectangle
= TRUE
;
3166 Request
.Data
.ScrollConsoleScreenBufferRequest
.ClipRectangle
= *lpClipRectangle
;
3170 Request
.Data
.ScrollConsoleScreenBufferRequest
.UseClipRectangle
= FALSE
;
3173 Request
.Data
.ScrollConsoleScreenBufferRequest
.DestinationOrigin
= dwDestinationOrigin
;
3174 Request
.Data
.ScrollConsoleScreenBufferRequest
.Fill
= *lpFill
;
3176 Status
= CsrClientCallServer(&Request
,
3179 sizeof(CSR_API_MESSAGE
));
3181 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
3183 SetLastErrorByStatus(Status
);
3191 /*--------------------------------------------------------------
3192 * ScrollConsoleScreenBufferA
3198 ScrollConsoleScreenBufferA(HANDLE hConsoleOutput
,
3199 CONST SMALL_RECT
*lpScrollRectangle
,
3200 CONST SMALL_RECT
*lpClipRectangle
,
3201 COORD dwDestinationOrigin
,
3202 CONST CHAR_INFO
*lpFill
)
3204 return IntScrollConsoleScreenBuffer(hConsoleOutput
,
3205 (PSMALL_RECT
)lpScrollRectangle
,
3206 (PSMALL_RECT
)lpClipRectangle
,
3207 dwDestinationOrigin
,
3213 /*--------------------------------------------------------------
3214 * ScrollConsoleScreenBufferW
3220 ScrollConsoleScreenBufferW(HANDLE hConsoleOutput
,
3221 CONST SMALL_RECT
*lpScrollRectangle
,
3222 CONST SMALL_RECT
*lpClipRectangle
,
3223 COORD dwDestinationOrigin
,
3224 CONST CHAR_INFO
*lpFill
)
3226 return IntScrollConsoleScreenBuffer(hConsoleOutput
,
3229 dwDestinationOrigin
,
3235 /*--------------------------------------------------------------
3236 * SetConsoleWindowInfo
3242 SetConsoleWindowInfo(HANDLE hConsoleOutput
,
3244 CONST SMALL_RECT
*lpConsoleWindow
)
3246 DPRINT1("SetConsoleWindowInfo(0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", hConsoleOutput
, bAbsolute
, lpConsoleWindow
);
3247 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3252 /*--------------------------------------------------------------
3253 * SetConsoleTextAttribute
3259 SetConsoleTextAttribute(HANDLE hConsoleOutput
,
3262 CSR_API_MESSAGE Request
;
3266 CsrRequest
= MAKE_CSR_API(SET_ATTRIB
, CSR_CONSOLE
);
3267 Request
.Data
.SetAttribRequest
.ConsoleHandle
= hConsoleOutput
;
3268 Request
.Data
.SetAttribRequest
.Attrib
= wAttributes
;
3270 Status
= CsrClientCallServer(&Request
, NULL
, CsrRequest
, sizeof(CSR_API_MESSAGE
));
3271 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
3273 SetLastErrorByStatus(Status
);
3283 AddConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine
)
3285 PHANDLER_ROUTINE
* NewCtrlHandlers
= NULL
;
3287 if (HandlerRoutine
== NULL
)
3289 NtCurrentPeb()->ProcessParameters
->ConsoleFlags
= TRUE
;
3293 if (NrCtrlHandlers
== NrAllocatedHandlers
)
3295 NewCtrlHandlers
= RtlAllocateHeap(RtlGetProcessHeap(),
3297 (NrCtrlHandlers
+ 4) * sizeof(PHANDLER_ROUTINE
));
3298 if (NewCtrlHandlers
== NULL
)
3300 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3304 memmove(NewCtrlHandlers
, CtrlHandlers
, sizeof(PHANDLER_ROUTINE
) * NrCtrlHandlers
);
3306 if (NrAllocatedHandlers
> 1) RtlFreeHeap(RtlGetProcessHeap(), 0, CtrlHandlers
);
3308 CtrlHandlers
= NewCtrlHandlers
;
3309 NrAllocatedHandlers
+= 4;
3312 ASSERT(NrCtrlHandlers
< NrAllocatedHandlers
);
3314 CtrlHandlers
[NrCtrlHandlers
++] = HandlerRoutine
;
3321 RemoveConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine
)
3325 if (HandlerRoutine
== NULL
)
3327 NtCurrentPeb()->ProcessParameters
->ConsoleFlags
= FALSE
;
3331 for (i
= 0; i
< NrCtrlHandlers
; i
++)
3333 if (CtrlHandlers
[i
] == HandlerRoutine
)
3335 if (i
< (NrCtrlHandlers
- 1))
3337 memmove(&CtrlHandlers
[i
],
3339 (NrCtrlHandlers
- i
+ 1) * sizeof(PHANDLER_ROUTINE
));
3347 SetLastError(ERROR_INVALID_PARAMETER
);
3357 SetConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine
,
3362 RtlEnterCriticalSection(&DllLock
);
3365 Ret
= AddConsoleCtrlHandler(HandlerRoutine
);
3369 Ret
= RemoveConsoleCtrlHandler(HandlerRoutine
);
3372 RtlLeaveCriticalSection(&DllLock
);
3377 /*--------------------------------------------------------------
3378 * GenerateConsoleCtrlEvent
3384 GenerateConsoleCtrlEvent(DWORD dwCtrlEvent
,
3385 DWORD dwProcessGroupId
)
3387 CSR_API_MESSAGE Request
;
3391 if (dwCtrlEvent
!= CTRL_C_EVENT
&& dwCtrlEvent
!= CTRL_BREAK_EVENT
)
3393 SetLastError(ERROR_INVALID_PARAMETER
);
3397 CsrRequest
= MAKE_CSR_API(GENERATE_CTRL_EVENT
, CSR_CONSOLE
);
3398 Request
.Data
.GenerateCtrlEvent
.Event
= dwCtrlEvent
;
3399 Request
.Data
.GenerateCtrlEvent
.ProcessGroup
= dwProcessGroupId
;
3401 Status
= CsrClientCallServer(&Request
,
3404 sizeof(CSR_API_MESSAGE
));
3405 if(!NT_SUCCESS(Status
) || !(NT_SUCCESS(Status
= Request
.Status
)))
3407 SetLastErrorByStatus(Status
);
3415 /*--------------------------------------------------------------
3422 GetConsoleTitleW(LPWSTR lpConsoleTitle
,
3425 PCSR_API_MESSAGE Request
;
3429 Request
= RtlAllocateHeap(RtlGetProcessHeap(),
3431 CSR_API_MESSAGE_HEADER_SIZE(CSRSS_GET_TITLE
) + CSRSS_MAX_TITLE_LENGTH
* sizeof(WCHAR
));
3432 if (Request
== NULL
)
3434 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3438 CsrRequest
= MAKE_CSR_API(GET_TITLE
, CSR_CONSOLE
);
3440 Status
= CsrClientCallServer(Request
,
3443 CSR_API_MESSAGE_HEADER_SIZE(CSRSS_GET_TITLE
) + CSRSS_MAX_TITLE_LENGTH
* sizeof(WCHAR
));
3444 if (!NT_SUCCESS(Status
) || !(NT_SUCCESS(Status
= Request
->Status
)))
3446 RtlFreeHeap(RtlGetProcessHeap(), 0, Request
);
3447 SetLastErrorByStatus(Status
);
3451 if (nSize
* sizeof(WCHAR
) <= Request
->Data
.GetTitleRequest
.Length
)
3457 nSize
= Request
->Data
.GetTitleRequest
.Length
/ sizeof (WCHAR
);
3459 memcpy(lpConsoleTitle
, Request
->Data
.GetTitleRequest
.Title
, nSize
* sizeof(WCHAR
));
3460 lpConsoleTitle
[nSize
] = L
'\0';
3462 RtlFreeHeap(RtlGetProcessHeap(), 0, Request
);
3468 /*--------------------------------------------------------------
3477 GetConsoleTitleA(LPSTR lpConsoleTitle
,
3480 WCHAR WideTitle
[CSRSS_MAX_TITLE_LENGTH
+ 1];
3481 DWORD nWideTitle
= CSRSS_MAX_TITLE_LENGTH
+ 1;
3484 if (!lpConsoleTitle
|| !nSize
) return 0;
3485 nWideTitle
= GetConsoleTitleW((LPWSTR
) WideTitle
, nWideTitle
);
3486 if (!nWideTitle
) return 0;
3488 if ((nWritten
= WideCharToMultiByte(CP_ACP
, // ANSI code page
3489 0, // performance and mapping flags
3490 (LPWSTR
) WideTitle
, // address of wide-character string
3491 nWideTitle
, // number of characters in string
3492 lpConsoleTitle
, // address of buffer for new string
3493 nSize
- 1, // size of buffer
3497 lpConsoleTitle
[nWritten
] = '\0';
3505 /*--------------------------------------------------------------
3512 SetConsoleTitleW(LPCWSTR lpConsoleTitle
)
3514 PCSR_API_MESSAGE Request
;
3519 Request
= RtlAllocateHeap(RtlGetProcessHeap(), 0,
3520 max(sizeof(CSR_API_MESSAGE
),
3521 CSR_API_MESSAGE_HEADER_SIZE(CSRSS_SET_TITLE
) +
3522 min(wcslen(lpConsoleTitle
), CSRSS_MAX_TITLE_LENGTH
) * sizeof(WCHAR
)));
3523 if (Request
== NULL
)
3525 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3529 CsrRequest
= MAKE_CSR_API(SET_TITLE
, CSR_CONSOLE
);
3531 for (c
= 0; lpConsoleTitle
[c
] && c
< CSRSS_MAX_TITLE_LENGTH
; c
++)
3532 Request
->Data
.SetTitleRequest
.Title
[c
] = lpConsoleTitle
[c
];
3534 Request
->Data
.SetTitleRequest
.Length
= c
* sizeof(WCHAR
);
3535 Status
= CsrClientCallServer(Request
,
3538 max(sizeof(CSR_API_MESSAGE
),
3539 CSR_API_MESSAGE_HEADER_SIZE(CSRSS_SET_TITLE
) + c
* sizeof(WCHAR
)));
3540 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
->Status
))
3542 RtlFreeHeap(RtlGetProcessHeap(), 0, Request
);
3543 SetLastErrorByStatus(Status
);
3547 RtlFreeHeap(RtlGetProcessHeap(), 0, Request
);
3553 /*--------------------------------------------------------------
3562 SetConsoleTitleA(LPCSTR lpConsoleTitle
)
3564 PCSR_API_MESSAGE Request
;
3569 Request
= RtlAllocateHeap(RtlGetProcessHeap(),
3571 max(sizeof(CSR_API_MESSAGE
),
3572 CSR_API_MESSAGE_HEADER_SIZE(CSRSS_SET_TITLE
) +
3573 min(strlen(lpConsoleTitle
), CSRSS_MAX_TITLE_LENGTH
) * sizeof(WCHAR
)));
3574 if (Request
== NULL
)
3576 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3580 CsrRequest
= MAKE_CSR_API(SET_TITLE
, CSR_CONSOLE
);
3582 for (c
= 0; lpConsoleTitle
[c
] && c
< CSRSS_MAX_TITLE_LENGTH
; c
++)
3583 Request
->Data
.SetTitleRequest
.Title
[c
] = lpConsoleTitle
[c
];
3585 Request
->Data
.SetTitleRequest
.Length
= c
* sizeof(WCHAR
);
3586 Status
= CsrClientCallServer(Request
,
3589 max(sizeof(CSR_API_MESSAGE
),
3590 CSR_API_MESSAGE_HEADER_SIZE(CSRSS_SET_TITLE
) + c
* sizeof(WCHAR
)));
3591 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
->Status
))
3593 RtlFreeHeap(RtlGetProcessHeap(), 0, Request
);
3594 SetLastErrorByStatus(Status
);
3598 RtlFreeHeap(RtlGetProcessHeap(), 0, Request
);
3604 /*--------------------------------------------------------------
3605 * CreateConsoleScreenBuffer
3611 CreateConsoleScreenBuffer(DWORD dwDesiredAccess
,
3613 CONST SECURITY_ATTRIBUTES
*lpSecurityAttributes
,
3615 LPVOID lpScreenBufferData
)
3617 CSR_API_MESSAGE Request
;
3621 if (dwDesiredAccess
& ~(GENERIC_READ
| GENERIC_WRITE
)
3622 || dwShareMode
& ~(FILE_SHARE_READ
| FILE_SHARE_WRITE
)
3623 || dwFlags
!= CONSOLE_TEXTMODE_BUFFER
)
3625 SetLastError(ERROR_INVALID_PARAMETER
);
3626 return INVALID_HANDLE_VALUE
;
3629 Request
.Data
.CreateScreenBufferRequest
.Access
= dwDesiredAccess
;
3630 Request
.Data
.CreateScreenBufferRequest
.ShareMode
= dwShareMode
;
3631 Request
.Data
.CreateScreenBufferRequest
.Inheritable
=
3632 lpSecurityAttributes
? lpSecurityAttributes
->bInheritHandle
: FALSE
;
3634 CsrRequest
= MAKE_CSR_API(CREATE_SCREEN_BUFFER
, CSR_CONSOLE
);
3635 Status
= CsrClientCallServer(&Request
, NULL
, CsrRequest
, sizeof(CSR_API_MESSAGE
));
3636 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
3638 SetLastErrorByStatus(Status
);
3639 return INVALID_HANDLE_VALUE
;
3641 return Request
.Data
.CreateScreenBufferRequest
.OutputHandle
;
3645 /*--------------------------------------------------------------
3654 CSR_API_MESSAGE Request
;
3658 CsrRequest
= MAKE_CSR_API(GET_CONSOLE_CP
, CSR_CONSOLE
);
3659 Status
= CsrClientCallServer(&Request
, NULL
, CsrRequest
, sizeof(CSR_API_MESSAGE
));
3660 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
3662 SetLastErrorByStatus (Status
);
3666 return Request
.Data
.GetConsoleCodePage
.CodePage
;
3670 /*--------------------------------------------------------------
3677 SetConsoleCP(UINT wCodePageID
)
3679 CSR_API_MESSAGE Request
;
3683 CsrRequest
= MAKE_CSR_API(SET_CONSOLE_CP
, CSR_CONSOLE
);
3684 Request
.Data
.SetConsoleCodePage
.CodePage
= wCodePageID
;
3686 Status
= CsrClientCallServer(&Request
, NULL
, CsrRequest
, sizeof(CSR_API_MESSAGE
));
3687 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
3689 SetLastErrorByStatus(Status
);
3692 return NT_SUCCESS(Status
);
3696 /*--------------------------------------------------------------
3697 * GetConsoleOutputCP
3703 GetConsoleOutputCP(VOID
)
3705 CSR_API_MESSAGE Request
;
3709 CsrRequest
= MAKE_CSR_API(GET_CONSOLE_OUTPUT_CP
, CSR_CONSOLE
);
3710 Status
= CsrClientCallServer(&Request
, NULL
, CsrRequest
, sizeof(CSR_API_MESSAGE
));
3711 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
3713 SetLastErrorByStatus (Status
);
3717 return Request
.Data
.GetConsoleOutputCodePage
.CodePage
;
3721 /*--------------------------------------------------------------
3722 * SetConsoleOutputCP
3728 SetConsoleOutputCP(UINT wCodePageID
)
3730 CSR_API_MESSAGE Request
;
3734 CsrRequest
= MAKE_CSR_API(SET_CONSOLE_OUTPUT_CP
, CSR_CONSOLE
);
3735 Request
.Data
.SetConsoleOutputCodePage
.CodePage
= wCodePageID
;
3736 Status
= CsrClientCallServer(&Request
, NULL
, CsrRequest
, sizeof(CSR_API_MESSAGE
));
3737 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
3739 SetLastErrorByStatus(Status
);
3742 return NT_SUCCESS(Status
);
3746 /*--------------------------------------------------------------
3747 * GetConsoleProcessList
3753 GetConsoleProcessList(LPDWORD lpdwProcessList
,
3754 DWORD dwProcessCount
)
3756 PCSR_CAPTURE_BUFFER CaptureBuffer
;
3757 CSR_API_MESSAGE Request
;
3762 if (lpdwProcessList
== NULL
|| dwProcessCount
== 0)
3764 SetLastError(ERROR_INVALID_PARAMETER
);
3768 CaptureBuffer
= CsrAllocateCaptureBuffer(1, dwProcessCount
* sizeof(DWORD
));
3769 if (CaptureBuffer
== NULL
)
3771 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3775 CsrRequest
= MAKE_CSR_API(GET_PROCESS_LIST
, CSR_CONSOLE
);
3776 Request
.Data
.GetProcessListRequest
.nMaxIds
= dwProcessCount
;
3777 CsrAllocateMessagePointer(CaptureBuffer
,
3778 dwProcessCount
* sizeof(DWORD
),
3779 (PVOID
*)&Request
.Data
.GetProcessListRequest
.ProcessId
);
3781 Status
= CsrClientCallServer(&Request
,
3784 sizeof(CSR_API_MESSAGE
));
3785 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
3787 SetLastErrorByStatus (Status
);
3792 nProcesses
= Request
.Data
.GetProcessListRequest
.nProcessIdsTotal
;
3793 if (dwProcessCount
>= nProcesses
)
3795 memcpy(lpdwProcessList
, Request
.Data
.GetProcessListRequest
.ProcessId
, nProcesses
* sizeof(DWORD
));
3799 CsrFreeCaptureBuffer(CaptureBuffer
);
3805 /*--------------------------------------------------------------
3806 * GetConsoleSelectionInfo
3812 GetConsoleSelectionInfo(PCONSOLE_SELECTION_INFO lpConsoleSelectionInfo
)
3814 DPRINT1("GetConsoleSelectionInfo(0x%x) UNIMPLEMENTED!\n", lpConsoleSelectionInfo
);
3815 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3821 /*--------------------------------------------------------------
3828 AttachConsole(DWORD dwProcessId
)
3830 DPRINT1("AttachConsole(0x%x) UNIMPLEMENTED!\n", dwProcessId
);
3834 /*--------------------------------------------------------------
3841 GetConsoleWindow(VOID
)
3843 CSR_API_MESSAGE Request
;
3847 CsrRequest
= MAKE_CSR_API(GET_CONSOLE_WINDOW
, CSR_CONSOLE
);
3848 Status
= CsrClientCallServer(&Request
, NULL
, CsrRequest
, sizeof(CSR_API_MESSAGE
));
3849 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
3851 SetLastErrorByStatus(Status
);
3855 return Request
.Data
.GetConsoleWindowRequest
.WindowHandle
;
3859 /*--------------------------------------------------------------
3866 SetConsoleIcon(HICON hicon
)
3868 CSR_API_MESSAGE Request
;
3872 CsrRequest
= MAKE_CSR_API(SET_CONSOLE_ICON
, CSR_CONSOLE
);
3873 Request
.Data
.SetConsoleIconRequest
.WindowIcon
= hicon
;
3875 Status
= CsrClientCallServer(&Request
, NULL
, CsrRequest
, sizeof(CSR_API_MESSAGE
));
3876 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
3878 SetLastErrorByStatus(Status
);
3882 return NT_SUCCESS(Status
);
3886 /******************************************************************************
3887 * \name SetConsoleInputExeNameW
3888 * \brief Sets the console input file name from a unicode string.
3889 * \param lpInputExeName Pointer to a unicode string with the name.
3890 * \return TRUE if successful, FALSE if unsuccsedful.
3891 * \remarks If lpInputExeName is 0 or the string length is 0 or greater than 255,
3892 * the function fails and sets last error to ERROR_INVALID_PARAMETER.
3896 SetConsoleInputExeNameW(LPCWSTR lpInputExeName
)
3901 || (lenName
= lstrlenW(lpInputExeName
)) == 0
3902 || lenName
> INPUTEXENAME_BUFLEN
- 1)
3904 /* Fail if string is empty or too long */
3905 SetLastError(ERROR_INVALID_PARAMETER
);
3909 RtlEnterCriticalSection(&ConsoleLock
);
3912 RtlCopyMemory(InputExeName
, lpInputExeName
, lenName
* sizeof(WCHAR
));
3913 InputExeName
[lenName
] = L
'\0';
3917 RtlLeaveCriticalSection(&ConsoleLock
);
3925 /******************************************************************************
3926 * \name SetConsoleInputExeNameA
3927 * \brief Sets the console input file name from an ansi string.
3928 * \param lpInputExeName Pointer to an ansi string with the name.
3929 * \return TRUE if successful, FALSE if unsuccsedful.
3930 * \remarks If lpInputExeName is 0 or the string length is 0 or greater than 255,
3931 * the function fails and sets last error to ERROR_INVALID_PARAMETER.
3935 SetConsoleInputExeNameA(LPCSTR lpInputExeName
)
3937 WCHAR Buffer
[INPUTEXENAME_BUFLEN
];
3938 ANSI_STRING InputExeNameA
;
3939 UNICODE_STRING InputExeNameU
;
3943 RtlInitAnsiString(&InputExeNameA
, lpInputExeName
);
3945 if(InputExeNameA
.Length
== 0 ||
3946 InputExeNameA
.Length
> INPUTEXENAME_BUFLEN
- 1)
3948 /* Fail if string is empty or too long */
3949 SetLastError(ERROR_INVALID_PARAMETER
);
3953 InputExeNameU
.Buffer
= Buffer
;
3954 InputExeNameU
.MaximumLength
= sizeof(Buffer
);
3955 InputExeNameU
.Length
= 0;
3956 Status
= RtlAnsiStringToUnicodeString(&InputExeNameU
, &InputExeNameA
, FALSE
);
3957 if(NT_SUCCESS(Status
))
3959 Ret
= SetConsoleInputExeNameW(InputExeNameU
.Buffer
);
3963 SetLastErrorByStatus(Status
);
3971 /******************************************************************************
3972 * \name GetConsoleInputExeNameW
3973 * \brief Retrieves the console input file name as unicode string.
3974 * \param nBufferLength Length of the buffer in WCHARs.
3975 * Specify 0 to recieve the needed buffer length.
3976 * \param lpBuffer Pointer to a buffer that recieves the string.
3977 * \return Needed buffer size if \p nBufferLength is 0.
3978 * Otherwise 1 if successful, 2 if buffer is too small.
3979 * \remarks Sets last error value to ERROR_BUFFER_OVERFLOW if the buffer
3980 * is not big enough.
3984 GetConsoleInputExeNameW(DWORD nBufferLength
, LPWSTR lpBuffer
)
3986 int lenName
= lstrlenW(InputExeName
);
3988 if (nBufferLength
== 0)
3990 /* Buffer size is requested, return it */
3994 if(lenName
+ 1 > nBufferLength
)
3996 /* Buffer is not large enough! */
3997 SetLastError(ERROR_BUFFER_OVERFLOW
);
4001 RtlEnterCriticalSection(&ConsoleLock
);
4004 RtlCopyMemory(lpBuffer
, InputExeName
, lenName
* sizeof(WCHAR
));
4005 lpBuffer
[lenName
] = '\0';
4009 RtlLeaveCriticalSection(&ConsoleLock
);
4013 /* Success, return 1 */
4018 /******************************************************************************
4019 * \name GetConsoleInputExeNameA
4020 * \brief Retrieves the console input file name as ansi string.
4021 * \param nBufferLength Length of the buffer in CHARs.
4022 * \param lpBuffer Pointer to a buffer that recieves the string.
4023 * \return 1 if successful, 2 if buffer is too small.
4024 * \remarks Sets last error value to ERROR_BUFFER_OVERFLOW if the buffer
4025 * is not big enough. The buffer recieves as much characters as fit.
4029 GetConsoleInputExeNameA(DWORD nBufferLength
, LPSTR lpBuffer
)
4031 WCHAR Buffer
[INPUTEXENAME_BUFLEN
];
4033 UNICODE_STRING BufferU
;
4034 ANSI_STRING BufferA
;
4036 /* Get the unicode name */
4037 Ret
= GetConsoleInputExeNameW(sizeof(Buffer
) / sizeof(Buffer
[0]), Buffer
);
4039 /* Initialize strings for conversion */
4040 RtlInitUnicodeString(&BufferU
, Buffer
);
4042 BufferA
.MaximumLength
= nBufferLength
;
4043 BufferA
.Buffer
= lpBuffer
;
4045 /* Convert unicode name to ansi, copying as much chars as fit */
4046 RtlUnicodeStringToAnsiString(&BufferA
, &BufferU
, FALSE
);
4048 /* Error handling */
4049 if(nBufferLength
<= BufferU
.Length
/ sizeof(WCHAR
))
4051 SetLastError(ERROR_BUFFER_OVERFLOW
);
4059 /*--------------------------------------------------------------
4060 * GetConsoleHistoryInfo
4066 GetConsoleHistoryInfo(PCONSOLE_HISTORY_INFO lpConsoleHistoryInfo
)
4068 DPRINT1("GetConsoleHistoryInfo(0x%p) UNIMPLEMENTED!\n", lpConsoleHistoryInfo
);
4069 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
4074 /*--------------------------------------------------------------
4075 * SetConsoleHistoryInfo
4081 SetConsoleHistoryInfo(IN PCONSOLE_HISTORY_INFO lpConsoleHistoryInfo
)
4083 DPRINT1("SetConsoleHistoryInfo(0x%p) UNIMPLEMENTED!\n", lpConsoleHistoryInfo
);
4084 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
4089 /*--------------------------------------------------------------
4090 * GetConsoleOriginalTitleW
4096 GetConsoleOriginalTitleW(OUT LPWSTR lpConsoleTitle
,
4099 DPRINT1("GetConsoleOriginalTitleW(0x%p, 0x%x) UNIMPLEMENTED!\n", lpConsoleTitle
, nSize
);
4100 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
4105 /*--------------------------------------------------------------
4106 * GetConsoleOriginalTitleA
4112 GetConsoleOriginalTitleA(OUT LPSTR lpConsoleTitle
,
4115 DPRINT1("GetConsoleOriginalTitleA(0x%p, 0x%x) UNIMPLEMENTED!\n", lpConsoleTitle
, nSize
);
4116 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
4121 /*--------------------------------------------------------------
4122 * GetConsoleScreenBufferInfoEx
4128 GetConsoleScreenBufferInfoEx(IN HANDLE hConsoleOutput
,
4129 OUT PCONSOLE_SCREEN_BUFFER_INFOEX lpConsoleScreenBufferInfoEx
)
4131 DPRINT1("GetConsoleScreenBufferInfoEx(0x%p, 0x%p) UNIMPLEMENTED!\n", hConsoleOutput
, lpConsoleScreenBufferInfoEx
);
4132 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
4137 /*--------------------------------------------------------------
4138 * SetConsoleScreenBufferInfoEx
4144 SetConsoleScreenBufferInfoEx(IN HANDLE hConsoleOutput
,
4145 IN PCONSOLE_SCREEN_BUFFER_INFOEX lpConsoleScreenBufferInfoEx
)
4147 DPRINT1("SetConsoleScreenBufferInfoEx(0x%p, 0x%p) UNIMPLEMENTED!\n", hConsoleOutput
, lpConsoleScreenBufferInfoEx
);
4148 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
4153 /*--------------------------------------------------------------
4154 * GetCurrentConsoleFontEx
4160 GetCurrentConsoleFontEx(IN HANDLE hConsoleOutput
,
4161 IN BOOL bMaximumWindow
,
4162 OUT PCONSOLE_FONT_INFOEX lpConsoleCurrentFontEx
)
4164 DPRINT1("GetCurrentConsoleFontEx(0x%p, 0x%x, 0x%p) UNIMPLEMENTED!\n", hConsoleOutput
, bMaximumWindow
, lpConsoleCurrentFontEx
);
4165 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);