2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: dll/win32/kernel32/client/console/console.c
5 * PURPOSE: Win32 server console functions
6 * PROGRAMMERS: James Tabor
7 * <jimtabor@adsl-64-217-116-74.dsl.hstntx.swbell.net>
10 /* INCLUDES *******************************************************************/
18 /* GLOBALS ********************************************************************/
20 extern RTL_CRITICAL_SECTION ConsoleLock
;
21 extern BOOL ConsoleInitialized
;
22 extern BOOL WINAPI
IsDebuggerPresent(VOID
);
24 /* Console reserved "file" names */
25 static LPCWSTR BaseConFileName
= CONSOLE_FILE_NAME
;
26 static LPCWSTR BaseConInputFileName
= CONSOLE_INPUT_FILE_NAME
;
27 static LPCWSTR BaseConOutputFileName
= CONSOLE_OUTPUT_FILE_NAME
;
29 PHANDLER_ROUTINE InitialHandler
[1];
30 PHANDLER_ROUTINE
* CtrlHandlers
;
32 ULONG NrAllocatedHandlers
;
34 HANDLE InputWaitHandle
= INVALID_HANDLE_VALUE
;
36 #define INPUTEXENAME_BUFLEN 256
37 static WCHAR InputExeName
[INPUTEXENAME_BUFLEN
];
40 /* Default Console Control Handler ********************************************/
44 DefaultConsoleCtrlHandler(DWORD Event
)
46 DPRINT("Default handler called: %lx\n", Event
);
50 DPRINT("Ctrl-C Event\n");
53 case CTRL_BREAK_EVENT
:
54 DPRINT("Ctrl-Break Event\n");
57 case CTRL_CLOSE_EVENT
:
58 DPRINT("Ctrl Close Event\n");
61 case CTRL_LOGOFF_EVENT
:
62 DPRINT("Ctrl Logoff Event\n");
65 case CTRL_SHUTDOWN_EVENT
:
66 DPRINT("Ctrl Shutdown Event\n");
70 ExitProcess(CONTROL_C_EXIT
);
76 ConsoleControlDispatcher(IN LPVOID lpThreadParameter
)
79 DWORD CodeAndFlag
= PtrToUlong(lpThreadParameter
);
80 DWORD nCode
= CodeAndFlag
& MAXLONG
;
82 EXCEPTION_RECORD erException
;
84 DPRINT1("Console Dispatcher Active: %lx %lx\n", CodeAndFlag
, nCode
);
85 SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST
);
90 case CTRL_BREAK_EVENT
:
92 if (IsDebuggerPresent())
94 erException
.ExceptionCode
= (nCode
== CTRL_C_EVENT
?
95 DBG_CONTROL_C
: DBG_CONTROL_BREAK
);
96 erException
.ExceptionFlags
= 0;
97 erException
.ExceptionRecord
= NULL
;
98 erException
.ExceptionAddress
= DefaultConsoleCtrlHandler
;
99 erException
.NumberParameters
= 0;
103 RtlRaiseException(&erException
);
105 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
107 RtlEnterCriticalSection(&ConsoleLock
);
109 if ((nCode
!= CTRL_C_EVENT
) ||
110 (NtCurrentPeb()->ProcessParameters
->ConsoleFlags
!= 1))
112 for (i
= NrCtrlHandlers
; i
> 0; i
--)
114 if (CtrlHandlers
[i
- 1](nCode
)) break;
118 RtlLeaveCriticalSection(&ConsoleLock
);
127 case CTRL_CLOSE_EVENT
:
128 case CTRL_LOGOFF_EVENT
:
129 case CTRL_SHUTDOWN_EVENT
:
137 ExitProcess(CONTROL_C_EXIT
);
145 ASSERT(ConsoleInitialized
);
147 RtlEnterCriticalSection(&ConsoleLock
);
150 if ((nCode
!= CTRL_C_EVENT
) || (NtCurrentPeb()->ProcessParameters
->ConsoleFlags
!= 1))
152 for (i
= NrCtrlHandlers
; i
> 0; i
--)
155 (CodeAndFlag
& MINLONG
) &&
156 ((nCode
== CTRL_LOGOFF_EVENT
) || (nCode
== CTRL_SHUTDOWN_EVENT
)))
158 DPRINT("Skipping system/service apps\n");
162 if (CtrlHandlers
[i
- 1](nCode
))
166 case CTRL_CLOSE_EVENT
:
167 case CTRL_LOGOFF_EVENT
:
168 case CTRL_SHUTDOWN_EVENT
:
170 nExitCode
= CodeAndFlag
;
178 RtlLeaveCriticalSection(&ConsoleLock
);
180 ExitThread(nExitCode
);
181 return STATUS_SUCCESS
;
186 InitConsoleCtrlHandling(VOID
)
188 /* Initialize Console Ctrl Handler */
189 NrAllocatedHandlers
= NrCtrlHandlers
= 1;
190 CtrlHandlers
= InitialHandler
;
191 CtrlHandlers
[0] = DefaultConsoleCtrlHandler
;
195 /* FUNCTIONS ******************************************************************/
198 IntCheckForConsoleFileName(IN LPCWSTR pszName
,
199 IN DWORD dwDesiredAccess
)
201 LPCWSTR ConsoleName
= pszName
;
202 ULONG DeviceNameInfo
;
205 * Check whether we deal with a DOS device, and if so,
206 * strip the path till the file name.
207 * Therefore, things like \\.\CON or C:\some_path\CONIN$
208 * are transformed into CON or CONIN$, for example.
210 DeviceNameInfo
= RtlIsDosDeviceName_U(pszName
);
211 if (DeviceNameInfo
!= 0)
213 ConsoleName
= (LPCWSTR
)((ULONG_PTR
)ConsoleName
+ ((DeviceNameInfo
>> 16) & 0xFFFF));
216 /* Return a standard console "file" name according to what we passed in parameters */
217 if (_wcsicmp(ConsoleName
, BaseConInputFileName
) == 0)
219 return BaseConInputFileName
;
221 else if (_wcsicmp(ConsoleName
, BaseConOutputFileName
) == 0)
223 return BaseConOutputFileName
;
225 else if (_wcsicmp(ConsoleName
, BaseConFileName
) == 0)
227 if ((dwDesiredAccess
& (GENERIC_READ
| GENERIC_WRITE
)) == GENERIC_READ
)
229 return BaseConInputFileName
;
231 else if ((dwDesiredAccess
& (GENERIC_READ
| GENERIC_WRITE
)) == GENERIC_WRITE
)
233 return BaseConOutputFileName
;
237 /* If we are there, that means that either the file name or the desired access are wrong */
243 * @implemented (Undocumented)
244 * @note See http://undoc.airesoft.co.uk/kernel32.dll/ConsoleMenuControl.php
248 ConsoleMenuControl(HANDLE hConsoleOutput
,
252 CONSOLE_API_MESSAGE ApiMessage
;
253 PCONSOLE_MENUCONTROL MenuControlRequest
= &ApiMessage
.Data
.MenuControlRequest
;
255 MenuControlRequest
->OutputHandle
= hConsoleOutput
;
256 MenuControlRequest
->dwCmdIdLow
= dwCmdIdLow
;
257 MenuControlRequest
->dwCmdIdHigh
= dwCmdIdHigh
;
258 MenuControlRequest
->hMenu
= NULL
;
260 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
262 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepMenuControl
),
263 sizeof(CONSOLE_MENUCONTROL
));
265 return MenuControlRequest
->hMenu
;
274 DuplicateConsoleHandle(HANDLE hConsole
,
275 DWORD dwDesiredAccess
,
280 CONSOLE_API_MESSAGE ApiMessage
;
281 PCONSOLE_DUPLICATEHANDLE DuplicateHandleRequest
= &ApiMessage
.Data
.DuplicateHandleRequest
;
283 if ( (dwOptions
& ~(DUPLICATE_CLOSE_SOURCE
| DUPLICATE_SAME_ACCESS
)) ||
284 (!(dwOptions
& DUPLICATE_SAME_ACCESS
) &&
285 (dwDesiredAccess
& ~(GENERIC_READ
| GENERIC_WRITE
))) )
287 SetLastError (ERROR_INVALID_PARAMETER
);
288 return INVALID_HANDLE_VALUE
;
291 DuplicateHandleRequest
->ConsoleHandle
= hConsole
;
292 DuplicateHandleRequest
->Access
= dwDesiredAccess
;
293 DuplicateHandleRequest
->Inheritable
= bInheritHandle
;
294 DuplicateHandleRequest
->Options
= dwOptions
;
296 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
298 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepDuplicateHandle
),
299 sizeof(CONSOLE_DUPLICATEHANDLE
));
300 if (!NT_SUCCESS(Status
))
302 BaseSetLastNTError(Status
);
303 return INVALID_HANDLE_VALUE
;
306 return DuplicateHandleRequest
->ConsoleHandle
;
315 GetConsoleDisplayMode(LPDWORD lpModeFlags
)
318 CONSOLE_API_MESSAGE ApiMessage
;
319 PCONSOLE_GETDISPLAYMODE GetDisplayModeRequest
= &ApiMessage
.Data
.GetDisplayModeRequest
;
321 if (lpModeFlags
== NULL
)
323 SetLastError(ERROR_INVALID_PARAMETER
);
327 // GetDisplayModeRequest->OutputHandle = hConsoleOutput;
329 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
331 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetDisplayMode
),
332 sizeof(CONSOLE_GETDISPLAYMODE
));
333 if (!NT_SUCCESS(Status
))
335 BaseSetLastNTError(Status
);
339 *lpModeFlags
= GetDisplayModeRequest
->DisplayMode
;
345 * @unimplemented (Undocumented)
349 GetConsoleFontInfo(DWORD Unknown0
,
354 DPRINT1("GetConsoleFontInfo(0x%x, 0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
, Unknown2
, Unknown3
);
355 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
365 GetConsoleFontSize(HANDLE hConsoleOutput
,
368 COORD Empty
= {0, 0};
369 DPRINT1("GetConsoleFontSize(0x%x, 0x%x) UNIMPLEMENTED!\n", hConsoleOutput
, nFont
);
370 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
376 * @implemented (Undocumented)
380 GetConsoleHardwareState(HANDLE hConsoleOutput
,
385 CONSOLE_API_MESSAGE ApiMessage
;
386 PCONSOLE_GETSETHWSTATE HardwareStateRequest
= &ApiMessage
.Data
.HardwareStateRequest
;
388 DPRINT1("GetConsoleHardwareState(%d, 0x%p) UNIMPLEMENTED!\n", Flags
, State
);
392 SetLastError(ERROR_INVALID_PARAMETER
);
396 HardwareStateRequest
->OutputHandle
= hConsoleOutput
;
398 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
400 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetHardwareState
),
401 sizeof(CONSOLE_GETSETHWSTATE
));
402 if (!NT_SUCCESS(Status
))
404 BaseSetLastNTError(Status
);
408 *State
= HardwareStateRequest
->State
;
414 * @implemented (Undocumented)
418 GetConsoleInputWaitHandle(VOID
)
420 return InputWaitHandle
;
429 GetCurrentConsoleFont(HANDLE hConsoleOutput
,
431 PCONSOLE_FONT_INFO lpConsoleCurrentFont
)
433 DPRINT1("GetCurrentConsoleFont(0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", hConsoleOutput
, bMaximumWindow
, lpConsoleCurrentFont
);
434 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
440 * @unimplemented (Undocumented)
444 GetNumberOfConsoleFonts(VOID
)
446 DPRINT1("GetNumberOfConsoleFonts() UNIMPLEMENTED!\n");
447 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
453 * @implemented (Undocumented)
454 * @note See http://blog.airesoft.co.uk/2012/10/things-ms-can-do-that-they-dont-tell-you-about-console-graphics/
458 InvalidateConsoleDIBits(IN HANDLE hConsoleOutput
,
459 IN PSMALL_RECT lpRect
)
462 CONSOLE_API_MESSAGE ApiMessage
;
463 PCONSOLE_INVALIDATEDIBITS InvalidateDIBitsRequest
= &ApiMessage
.Data
.InvalidateDIBitsRequest
;
467 SetLastError(ERROR_INVALID_PARAMETER
);
471 InvalidateDIBitsRequest
->OutputHandle
= hConsoleOutput
;
472 InvalidateDIBitsRequest
->Region
= *lpRect
;
474 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
476 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepInvalidateBitMapRect
),
477 sizeof(CONSOLE_INVALIDATEDIBITS
));
478 if (!NT_SUCCESS(Status
))
480 BaseSetLastNTError(Status
);
489 * @unimplemented (Undocumented)
493 OpenConsoleW(LPCWSTR wsName
,
494 DWORD dwDesiredAccess
,
498 NTSTATUS Status
= STATUS_SUCCESS
;
499 CONSOLE_API_MESSAGE ApiMessage
;
500 PCONSOLE_OPENCONSOLE OpenConsoleRequest
= &ApiMessage
.Data
.OpenConsoleRequest
;
501 CONSOLE_HANDLE_TYPE HandleType
;
503 if (wsName
&& 0 == _wcsicmp(wsName
, BaseConInputFileName
))
505 HandleType
= HANDLE_INPUT
;
507 else if (wsName
&& 0 == _wcsicmp(wsName
, BaseConOutputFileName
))
509 HandleType
= HANDLE_OUTPUT
;
513 SetLastError(ERROR_INVALID_PARAMETER
);
514 return INVALID_HANDLE_VALUE
;
517 if ( (dwDesiredAccess
& ~(GENERIC_READ
| GENERIC_WRITE
)) ||
518 (dwShareMode
& ~(FILE_SHARE_READ
| FILE_SHARE_WRITE
)) )
520 SetLastError(ERROR_INVALID_PARAMETER
);
521 return INVALID_HANDLE_VALUE
;
524 OpenConsoleRequest
->HandleType
= HandleType
;
525 OpenConsoleRequest
->Access
= dwDesiredAccess
;
526 OpenConsoleRequest
->Inheritable
= bInheritHandle
;
527 OpenConsoleRequest
->ShareMode
= dwShareMode
;
529 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
531 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepOpenConsole
),
532 sizeof(CONSOLE_OPENCONSOLE
));
533 if (!NT_SUCCESS(Status
))
535 BaseSetLastNTError(Status
);
536 return INVALID_HANDLE_VALUE
;
539 return OpenConsoleRequest
->ConsoleHandle
;
544 * @implemented (Undocumented)
545 * @note See http://undoc.airesoft.co.uk/kernel32.dll/SetConsoleCursor.php
549 SetConsoleCursor(HANDLE hConsoleOutput
,
553 CONSOLE_API_MESSAGE ApiMessage
;
554 PCONSOLE_SETCURSOR SetCursorRequest
= &ApiMessage
.Data
.SetCursorRequest
;
556 SetCursorRequest
->OutputHandle
= hConsoleOutput
;
557 SetCursorRequest
->hCursor
= hCursor
;
559 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
561 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetCursor
),
562 sizeof(CONSOLE_SETCURSOR
));
563 if (!NT_SUCCESS(Status
))
565 BaseSetLastNTError(Status
);
578 SetConsoleDisplayMode(HANDLE hConsoleOutput
,
580 PCOORD lpNewScreenBufferDimensions
)
583 CONSOLE_API_MESSAGE ApiMessage
;
584 PCONSOLE_SETDISPLAYMODE SetDisplayModeRequest
= &ApiMessage
.Data
.SetDisplayModeRequest
;
586 SetDisplayModeRequest
->OutputHandle
= hConsoleOutput
;
587 SetDisplayModeRequest
->DisplayMode
= dwFlags
;
588 SetDisplayModeRequest
->NewSBDim
.X
= 0;
589 SetDisplayModeRequest
->NewSBDim
.Y
= 0;
591 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
593 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetDisplayMode
),
594 sizeof(CONSOLE_SETDISPLAYMODE
));
595 if (!NT_SUCCESS(Status
))
597 BaseSetLastNTError(Status
);
601 if (lpNewScreenBufferDimensions
)
602 *lpNewScreenBufferDimensions
= SetDisplayModeRequest
->NewSBDim
;
609 * @unimplemented (Undocumented)
613 SetConsoleFont(DWORD Unknown0
,
616 DPRINT1("SetConsoleFont(0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
);
617 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
623 * @implemented (Undocumented)
627 SetConsoleHardwareState(HANDLE hConsoleOutput
,
632 CONSOLE_API_MESSAGE ApiMessage
;
633 PCONSOLE_GETSETHWSTATE HardwareStateRequest
= &ApiMessage
.Data
.HardwareStateRequest
;
635 DPRINT1("SetConsoleHardwareState(%d, %d) UNIMPLEMENTED!\n", Flags
, State
);
637 HardwareStateRequest
->OutputHandle
= hConsoleOutput
;
638 HardwareStateRequest
->State
= State
;
640 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
642 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetHardwareState
),
643 sizeof(CONSOLE_GETSETHWSTATE
));
644 if (!NT_SUCCESS(Status
))
646 BaseSetLastNTError(Status
);
655 * @unimplemented (Undocumented)
659 SetConsoleKeyShortcuts(DWORD Unknown0
,
664 DPRINT1("SetConsoleKeyShortcuts(0x%x, 0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
, Unknown2
, Unknown3
);
665 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
671 * @implemented (Undocumented)
672 * @note See http://undoc.airesoft.co.uk/kernel32.dll/SetConsoleMaximumWindowSize.php
673 * Does nothing, returns TRUE only. Checked on Windows Server 2003.
677 SetConsoleMaximumWindowSize(HANDLE hConsoleOutput
,
680 DPRINT1("SetConsoleMaximumWindowSize(0x%x, {%d, %d}) does nothing\n",
681 hConsoleOutput
, dwMaximumSize
.X
, dwMaximumSize
.Y
);
687 * @implemented (Undocumented)
691 SetConsoleMenuClose(BOOL bEnable
)
694 CONSOLE_API_MESSAGE ApiMessage
;
695 PCONSOLE_SETMENUCLOSE SetMenuCloseRequest
= &ApiMessage
.Data
.SetMenuCloseRequest
;
697 SetMenuCloseRequest
->Enable
= bEnable
;
699 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
701 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetMenuClose
),
702 sizeof(CONSOLE_SETMENUCLOSE
));
703 if (!NT_SUCCESS(Status
))
705 BaseSetLastNTError(Status
);
714 * @unimplemented (Undocumented)
718 SetConsolePalette(DWORD Unknown0
,
722 DPRINT1("SetConsolePalette(0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
, Unknown2
);
723 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
728 * @implemented (Undocumented)
729 * @note See http://undoc.airesoft.co.uk/kernel32.dll/ShowConsoleCursor.php
733 ShowConsoleCursor(HANDLE hConsoleOutput
,
736 CONSOLE_API_MESSAGE ApiMessage
;
737 PCONSOLE_SHOWCURSOR ShowCursorRequest
= &ApiMessage
.Data
.ShowCursorRequest
;
739 ShowCursorRequest
->OutputHandle
= hConsoleOutput
;
740 ShowCursorRequest
->Show
= bShow
;
741 ShowCursorRequest
->RefCount
= 0;
743 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
745 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepShowCursor
),
746 sizeof(CONSOLE_SHOWCURSOR
));
748 return ShowCursorRequest
->RefCount
;
753 * FUNCTION: Checks whether the given handle is a valid console handle.
756 * Handle - Handle to be checked
759 * TRUE: Handle is a valid console handle
760 * FALSE: Handle is not a valid console handle.
762 * STATUS: Officially undocumented
768 VerifyConsoleIoHandle(HANDLE Handle
)
771 CONSOLE_API_MESSAGE ApiMessage
;
773 ApiMessage
.Data
.VerifyHandleRequest
.ConsoleHandle
= Handle
;
775 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
777 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepVerifyIoHandle
),
778 sizeof(CONSOLE_VERIFYHANDLE
));
779 if (!NT_SUCCESS(Status
))
781 BaseSetLastNTError(Status
);
794 WriteConsoleInputVDMA(DWORD Unknown0
,
799 DPRINT1("WriteConsoleInputVDMA(0x%x, 0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
, Unknown2
, Unknown3
);
800 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
810 WriteConsoleInputVDMW(DWORD Unknown0
,
815 DPRINT1("WriteConsoleInputVDMW(0x%x, 0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0
, Unknown1
, Unknown2
, Unknown3
);
816 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
822 * @implemented (Undocumented)
826 CloseConsoleHandle(HANDLE Handle
)
829 CONSOLE_API_MESSAGE ApiMessage
;
831 ApiMessage
.Data
.CloseHandleRequest
.ConsoleHandle
= Handle
;
833 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
835 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepCloseHandle
),
836 sizeof(CONSOLE_CLOSEHANDLE
));
837 if (!NT_SUCCESS(Status
))
839 BaseSetLastNTError(Status
);
852 GetStdHandle(DWORD nStdHandle
)
854 * FUNCTION: Get a handle for the standard input, standard output
855 * and a standard error device.
858 * nStdHandle - Specifies the device for which to return the handle.
860 * RETURNS: If the function succeeds, the return value is the handle
861 * of the specified device. Otherwise the value is INVALID_HANDLE_VALUE.
864 PRTL_USER_PROCESS_PARAMETERS Ppb
= NtCurrentPeb()->ProcessParameters
;
868 case STD_INPUT_HANDLE
:
869 return Ppb
->StandardInput
;
871 case STD_OUTPUT_HANDLE
:
872 return Ppb
->StandardOutput
;
874 case STD_ERROR_HANDLE
:
875 return Ppb
->StandardError
;
878 SetLastError(ERROR_INVALID_HANDLE
);
879 return INVALID_HANDLE_VALUE
;
888 SetStdHandle(DWORD nStdHandle
,
891 * FUNCTION: Set the handle for the standard input, standard output or
892 * the standard error device.
895 * nStdHandle - Specifies the handle to be set.
896 * hHandle - The handle to set.
898 * RETURNS: TRUE if the function succeeds, FALSE otherwise.
901 PRTL_USER_PROCESS_PARAMETERS Ppb
= NtCurrentPeb()->ProcessParameters
;
903 /* no need to check if hHandle == INVALID_HANDLE_VALUE */
907 case STD_INPUT_HANDLE
:
908 Ppb
->StandardInput
= hHandle
;
911 case STD_OUTPUT_HANDLE
:
912 Ppb
->StandardOutput
= hHandle
;
915 case STD_ERROR_HANDLE
:
916 Ppb
->StandardError
= hHandle
;
920 /* Windows for whatever reason sets the last error to ERROR_INVALID_HANDLE here */
921 SetLastError(ERROR_INVALID_HANDLE
);
926 /*--------------------------------------------------------------
936 PRTL_USER_PROCESS_PARAMETERS Parameters
= NtCurrentPeb()->ProcessParameters
;
937 CONSOLE_API_MESSAGE ApiMessage
;
938 PCONSOLE_ALLOCCONSOLE AllocConsoleRequest
= &ApiMessage
.Data
.AllocConsoleRequest
;
939 PCSR_CAPTURE_BUFFER CaptureBuffer
;
941 if (Parameters
->ConsoleHandle
)
943 DPRINT1("AllocConsole: Allocating a console to a process already having one\n");
944 SetLastError(ERROR_ACCESS_DENIED
);
948 CaptureBuffer
= CsrAllocateCaptureBuffer(1, sizeof(CONSOLE_START_INFO
));
949 if (CaptureBuffer
== NULL
)
951 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
952 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
956 CsrAllocateMessagePointer(CaptureBuffer
,
957 sizeof(CONSOLE_START_INFO
),
958 (PVOID
*)&AllocConsoleRequest
->ConsoleStartInfo
);
960 InitConsoleInfo(AllocConsoleRequest
->ConsoleStartInfo
,
961 &Parameters
->ImagePathName
);
963 AllocConsoleRequest
->Console
= NULL
;
964 AllocConsoleRequest
->CtrlDispatcher
= ConsoleControlDispatcher
;
965 AllocConsoleRequest
->PropDispatcher
= PropDialogHandler
;
967 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
969 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepAlloc
),
970 sizeof(CONSOLE_ALLOCCONSOLE
));
972 CsrFreeCaptureBuffer(CaptureBuffer
);
974 if (!NT_SUCCESS(Status
))
976 BaseSetLastNTError(Status
);
980 Parameters
->ConsoleHandle
= AllocConsoleRequest
->Console
;
981 SetStdHandle(STD_INPUT_HANDLE
, AllocConsoleRequest
->InputHandle
);
982 SetStdHandle(STD_OUTPUT_HANDLE
, AllocConsoleRequest
->OutputHandle
);
983 SetStdHandle(STD_ERROR_HANDLE
, AllocConsoleRequest
->ErrorHandle
);
985 /* Initialize Console Ctrl Handler */
986 InitConsoleCtrlHandling();
988 InputWaitHandle
= AllocConsoleRequest
->InputWaitHandle
;
994 /*--------------------------------------------------------------
1003 // AG: I'm not sure if this is correct (what happens to std handles?)
1004 // but I just tried to reverse what AllocConsole() does...
1007 CONSOLE_API_MESSAGE ApiMessage
;
1009 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1011 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepFree
),
1012 sizeof(CONSOLE_FREECONSOLE
));
1013 if (!NT_SUCCESS(Status
))
1015 BaseSetLastNTError(Status
);
1019 NtCurrentPeb()->ProcessParameters
->ConsoleHandle
= NULL
;
1021 CloseHandle(InputWaitHandle
);
1022 InputWaitHandle
= INVALID_HANDLE_VALUE
;
1028 /*--------------------------------------------------------------
1029 * GetConsoleScreenBufferInfo
1035 GetConsoleScreenBufferInfo(HANDLE hConsoleOutput
,
1036 PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo
)
1039 CONSOLE_API_MESSAGE ApiMessage
;
1041 if (lpConsoleScreenBufferInfo
== NULL
)
1043 SetLastError(ERROR_INVALID_PARAMETER
);
1047 ApiMessage
.Data
.ScreenBufferInfoRequest
.OutputHandle
= hConsoleOutput
;
1049 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1051 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetScreenBufferInfo
),
1052 sizeof(CONSOLE_GETSCREENBUFFERINFO
));
1053 if (!NT_SUCCESS(Status
))
1055 BaseSetLastNTError(Status
);
1059 *lpConsoleScreenBufferInfo
= ApiMessage
.Data
.ScreenBufferInfoRequest
.Info
;
1065 /*--------------------------------------------------------------
1066 * SetConsoleCursorPosition
1072 SetConsoleCursorPosition(HANDLE hConsoleOutput
,
1073 COORD dwCursorPosition
)
1076 CONSOLE_API_MESSAGE ApiMessage
;
1078 ApiMessage
.Data
.SetCursorPositionRequest
.OutputHandle
= hConsoleOutput
;
1079 ApiMessage
.Data
.SetCursorPositionRequest
.Position
= dwCursorPosition
;
1081 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1083 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetCursorPosition
),
1084 sizeof(CONSOLE_SETCURSORPOSITION
));
1085 if (!NT_SUCCESS(Status
))
1087 BaseSetLastNTError(Status
);
1095 /*--------------------------------------------------------------
1102 GetConsoleMode(HANDLE hConsoleHandle
,
1106 CONSOLE_API_MESSAGE ApiMessage
;
1107 PCONSOLE_GETSETCONSOLEMODE ConsoleModeRequest
= &ApiMessage
.Data
.ConsoleModeRequest
;
1111 SetLastError(ERROR_INVALID_PARAMETER
);
1115 ConsoleModeRequest
->ConsoleHandle
= hConsoleHandle
;
1117 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1119 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetMode
),
1120 sizeof(CONSOLE_GETSETCONSOLEMODE
));
1121 if (!NT_SUCCESS(Status
))
1123 BaseSetLastNTError(Status
);
1127 *lpMode
= ConsoleModeRequest
->ConsoleMode
;
1133 /*--------------------------------------------------------------
1134 * GetNumberOfConsoleInputEvents
1140 GetNumberOfConsoleInputEvents(HANDLE hConsoleInput
,
1141 LPDWORD lpNumberOfEvents
)
1144 CONSOLE_API_MESSAGE ApiMessage
;
1145 PCONSOLE_GETNUMINPUTEVENTS GetNumInputEventsRequest
= &ApiMessage
.Data
.GetNumInputEventsRequest
;
1147 GetNumInputEventsRequest
->InputHandle
= hConsoleInput
;
1148 GetNumInputEventsRequest
->NumInputEvents
= 0;
1150 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1152 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetNumberOfInputEvents
),
1153 sizeof(CONSOLE_GETNUMINPUTEVENTS
));
1154 if (!NT_SUCCESS(Status
))
1156 BaseSetLastNTError(Status
);
1160 if (lpNumberOfEvents
== NULL
)
1162 SetLastError(ERROR_INVALID_ACCESS
);
1166 *lpNumberOfEvents
= GetNumInputEventsRequest
->NumInputEvents
;
1172 /*--------------------------------------------------------------
1173 * GetLargestConsoleWindowSize
1179 GetLargestConsoleWindowSize(HANDLE hConsoleOutput
)
1182 CONSOLE_API_MESSAGE ApiMessage
;
1183 PCONSOLE_GETLARGESTWINDOWSIZE GetLargestWindowSizeRequest
= &ApiMessage
.Data
.GetLargestWindowSizeRequest
;
1185 GetLargestWindowSizeRequest
->OutputHandle
= hConsoleOutput
;
1186 GetLargestWindowSizeRequest
->Size
.X
= 0;
1187 GetLargestWindowSizeRequest
->Size
.Y
= 0;
1189 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1191 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetLargestWindowSize
),
1192 sizeof(CONSOLE_GETLARGESTWINDOWSIZE
));
1193 if (!NT_SUCCESS(Status
))
1195 BaseSetLastNTError(Status
);
1198 DPRINT1("GetLargestConsoleWindowSize, X = %d, Y = %d\n", GetLargestWindowSizeRequest
->Size
.X
, GetLargestWindowSizeRequest
->Size
.Y
);
1199 return GetLargestWindowSizeRequest
->Size
;
1203 /*--------------------------------------------------------------
1204 * GetConsoleCursorInfo
1210 GetConsoleCursorInfo(HANDLE hConsoleOutput
,
1211 PCONSOLE_CURSOR_INFO lpConsoleCursorInfo
)
1214 CONSOLE_API_MESSAGE ApiMessage
;
1216 if (!lpConsoleCursorInfo
)
1218 if (!hConsoleOutput
)
1219 SetLastError(ERROR_INVALID_HANDLE
);
1221 SetLastError(ERROR_INVALID_ACCESS
);
1226 ApiMessage
.Data
.CursorInfoRequest
.OutputHandle
= hConsoleOutput
;
1228 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1230 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetCursorInfo
),
1231 sizeof(CONSOLE_GETSETCURSORINFO
));
1232 if (!NT_SUCCESS(Status
))
1234 BaseSetLastNTError(Status
);
1238 *lpConsoleCursorInfo
= ApiMessage
.Data
.CursorInfoRequest
.Info
;
1244 /*--------------------------------------------------------------
1245 * GetNumberOfConsoleMouseButtons
1251 GetNumberOfConsoleMouseButtons(LPDWORD lpNumberOfMouseButtons
)
1253 DPRINT1("GetNumberOfConsoleMouseButtons(0x%x) UNIMPLEMENTED!\n", lpNumberOfMouseButtons
);
1254 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1259 /*--------------------------------------------------------------
1266 SetConsoleMode(HANDLE hConsoleHandle
,
1270 CONSOLE_API_MESSAGE ApiMessage
;
1271 PCONSOLE_GETSETCONSOLEMODE ConsoleModeRequest
= &ApiMessage
.Data
.ConsoleModeRequest
;
1273 ConsoleModeRequest
->ConsoleHandle
= hConsoleHandle
;
1274 ConsoleModeRequest
->ConsoleMode
= dwMode
;
1276 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1278 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetMode
),
1279 sizeof(CONSOLE_GETSETCONSOLEMODE
));
1280 if (!NT_SUCCESS(Status
))
1282 BaseSetLastNTError(Status
);
1290 /*--------------------------------------------------------------
1291 * SetConsoleActiveScreenBuffer
1297 SetConsoleActiveScreenBuffer(HANDLE hConsoleOutput
)
1300 CONSOLE_API_MESSAGE ApiMessage
;
1302 ApiMessage
.Data
.SetScreenBufferRequest
.OutputHandle
= hConsoleOutput
;
1304 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1306 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetActiveScreenBuffer
),
1307 sizeof(CONSOLE_SETACTIVESCREENBUFFER
));
1308 if (!NT_SUCCESS(Status
))
1310 BaseSetLastNTError(Status
);
1318 /*--------------------------------------------------------------
1319 * FlushConsoleInputBuffer
1325 FlushConsoleInputBuffer(HANDLE hConsoleInput
)
1328 CONSOLE_API_MESSAGE ApiMessage
;
1330 ApiMessage
.Data
.FlushInputBufferRequest
.InputHandle
= hConsoleInput
;
1332 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1334 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepFlushInputBuffer
),
1335 sizeof(CONSOLE_FLUSHINPUTBUFFER
));
1336 if (!NT_SUCCESS(Status
))
1338 BaseSetLastNTError(Status
);
1346 /*--------------------------------------------------------------
1347 * SetConsoleScreenBufferSize
1353 SetConsoleScreenBufferSize(HANDLE hConsoleOutput
,
1357 CONSOLE_API_MESSAGE ApiMessage
;
1359 ApiMessage
.Data
.SetScreenBufferSizeRequest
.OutputHandle
= hConsoleOutput
;
1360 ApiMessage
.Data
.SetScreenBufferSizeRequest
.Size
= dwSize
;
1362 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1364 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetScreenBufferSize
),
1365 sizeof(CONSOLE_SETSCREENBUFFERSIZE
));
1366 if (!NT_SUCCESS(Status
))
1368 BaseSetLastNTError(Status
);
1376 /*--------------------------------------------------------------
1377 * SetConsoleCursorInfo
1383 SetConsoleCursorInfo(HANDLE hConsoleOutput
,
1384 CONST CONSOLE_CURSOR_INFO
*lpConsoleCursorInfo
)
1387 CONSOLE_API_MESSAGE ApiMessage
;
1389 ApiMessage
.Data
.CursorInfoRequest
.OutputHandle
= hConsoleOutput
;
1390 ApiMessage
.Data
.CursorInfoRequest
.Info
= *lpConsoleCursorInfo
;
1392 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1394 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetCursorInfo
),
1395 sizeof(CONSOLE_GETSETCURSORINFO
));
1396 if (!NT_SUCCESS(Status
))
1398 BaseSetLastNTError(Status
);
1408 IntScrollConsoleScreenBuffer(HANDLE hConsoleOutput
,
1409 const SMALL_RECT
*lpScrollRectangle
,
1410 const SMALL_RECT
*lpClipRectangle
,
1411 COORD dwDestinationOrigin
,
1412 const CHAR_INFO
*lpFill
,
1416 CONSOLE_API_MESSAGE ApiMessage
;
1417 PCONSOLE_SCROLLSCREENBUFFER ScrollScreenBufferRequest
= &ApiMessage
.Data
.ScrollScreenBufferRequest
;
1419 ScrollScreenBufferRequest
->OutputHandle
= hConsoleOutput
;
1420 ScrollScreenBufferRequest
->Unicode
= bUnicode
;
1421 ScrollScreenBufferRequest
->ScrollRectangle
= *lpScrollRectangle
;
1423 if (lpClipRectangle
!= NULL
)
1425 ScrollScreenBufferRequest
->UseClipRectangle
= TRUE
;
1426 ScrollScreenBufferRequest
->ClipRectangle
= *lpClipRectangle
;
1430 ScrollScreenBufferRequest
->UseClipRectangle
= FALSE
;
1433 ScrollScreenBufferRequest
->DestinationOrigin
= dwDestinationOrigin
;
1434 ScrollScreenBufferRequest
->Fill
= *lpFill
;
1436 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1438 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepScrollScreenBuffer
),
1439 sizeof(CONSOLE_SCROLLSCREENBUFFER
));
1441 if (!NT_SUCCESS(Status
))
1443 BaseSetLastNTError(Status
);
1451 /*--------------------------------------------------------------
1452 * ScrollConsoleScreenBufferA
1458 ScrollConsoleScreenBufferA(HANDLE hConsoleOutput
,
1459 CONST SMALL_RECT
*lpScrollRectangle
,
1460 CONST SMALL_RECT
*lpClipRectangle
,
1461 COORD dwDestinationOrigin
,
1462 CONST CHAR_INFO
*lpFill
)
1464 return IntScrollConsoleScreenBuffer(hConsoleOutput
,
1465 (PSMALL_RECT
)lpScrollRectangle
,
1466 (PSMALL_RECT
)lpClipRectangle
,
1467 dwDestinationOrigin
,
1473 /*--------------------------------------------------------------
1474 * ScrollConsoleScreenBufferW
1480 ScrollConsoleScreenBufferW(HANDLE hConsoleOutput
,
1481 CONST SMALL_RECT
*lpScrollRectangle
,
1482 CONST SMALL_RECT
*lpClipRectangle
,
1483 COORD dwDestinationOrigin
,
1484 CONST CHAR_INFO
*lpFill
)
1486 return IntScrollConsoleScreenBuffer(hConsoleOutput
,
1489 dwDestinationOrigin
,
1495 /*--------------------------------------------------------------
1496 * SetConsoleWindowInfo
1502 SetConsoleWindowInfo(HANDLE hConsoleOutput
,
1504 CONST SMALL_RECT
*lpConsoleWindow
)
1507 CONSOLE_API_MESSAGE ApiMessage
;
1508 PCONSOLE_SETWINDOWINFO SetWindowInfoRequest
= &ApiMessage
.Data
.SetWindowInfoRequest
;
1510 if (lpConsoleWindow
== NULL
)
1512 SetLastError(ERROR_INVALID_PARAMETER
);
1516 SetWindowInfoRequest
->OutputHandle
= hConsoleOutput
;
1517 SetWindowInfoRequest
->Absolute
= bAbsolute
;
1518 SetWindowInfoRequest
->WindowRect
= *lpConsoleWindow
;
1520 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1522 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetWindowInfo
),
1523 sizeof(CONSOLE_SETWINDOWINFO
));
1524 if (!NT_SUCCESS(Status
))
1526 BaseSetLastNTError(Status
);
1534 /*--------------------------------------------------------------
1535 * SetConsoleTextAttribute
1541 SetConsoleTextAttribute(HANDLE hConsoleOutput
,
1545 CONSOLE_API_MESSAGE ApiMessage
;
1547 ApiMessage
.Data
.SetTextAttribRequest
.OutputHandle
= hConsoleOutput
;
1548 ApiMessage
.Data
.SetTextAttribRequest
.Attrib
= wAttributes
;
1550 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1552 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetTextAttribute
),
1553 sizeof(CONSOLE_SETTEXTATTRIB
));
1554 if (!NT_SUCCESS(Status
))
1556 BaseSetLastNTError(Status
);
1566 AddConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine
)
1568 PHANDLER_ROUTINE
* NewCtrlHandlers
= NULL
;
1570 if (HandlerRoutine
== NULL
)
1572 NtCurrentPeb()->ProcessParameters
->ConsoleFlags
= TRUE
;
1576 if (NrCtrlHandlers
== NrAllocatedHandlers
)
1578 NewCtrlHandlers
= RtlAllocateHeap(RtlGetProcessHeap(),
1580 (NrCtrlHandlers
+ 4) * sizeof(PHANDLER_ROUTINE
));
1581 if (NewCtrlHandlers
== NULL
)
1583 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1587 memmove(NewCtrlHandlers
, CtrlHandlers
, sizeof(PHANDLER_ROUTINE
) * NrCtrlHandlers
);
1589 if (NrAllocatedHandlers
> 1) RtlFreeHeap(RtlGetProcessHeap(), 0, CtrlHandlers
);
1591 CtrlHandlers
= NewCtrlHandlers
;
1592 NrAllocatedHandlers
+= 4;
1595 ASSERT(NrCtrlHandlers
< NrAllocatedHandlers
);
1597 CtrlHandlers
[NrCtrlHandlers
++] = HandlerRoutine
;
1604 RemoveConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine
)
1608 if (HandlerRoutine
== NULL
)
1610 NtCurrentPeb()->ProcessParameters
->ConsoleFlags
= FALSE
;
1614 for (i
= 0; i
< NrCtrlHandlers
; i
++)
1616 if (CtrlHandlers
[i
] == HandlerRoutine
)
1618 if (i
< (NrCtrlHandlers
- 1))
1620 memmove(&CtrlHandlers
[i
],
1622 (NrCtrlHandlers
- i
+ 1) * sizeof(PHANDLER_ROUTINE
));
1630 SetLastError(ERROR_INVALID_PARAMETER
);
1640 SetConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine
,
1645 RtlEnterCriticalSection(&BaseDllDirectoryLock
);
1648 Ret
= AddConsoleCtrlHandler(HandlerRoutine
);
1652 Ret
= RemoveConsoleCtrlHandler(HandlerRoutine
);
1655 RtlLeaveCriticalSection(&BaseDllDirectoryLock
);
1660 /*--------------------------------------------------------------
1661 * GenerateConsoleCtrlEvent
1667 GenerateConsoleCtrlEvent(DWORD dwCtrlEvent
,
1668 DWORD dwProcessGroupId
)
1671 CONSOLE_API_MESSAGE ApiMessage
;
1673 if (dwCtrlEvent
!= CTRL_C_EVENT
&& dwCtrlEvent
!= CTRL_BREAK_EVENT
)
1675 SetLastError(ERROR_INVALID_PARAMETER
);
1679 ApiMessage
.Data
.GenerateCtrlEventRequest
.Event
= dwCtrlEvent
;
1680 ApiMessage
.Data
.GenerateCtrlEventRequest
.ProcessGroup
= dwProcessGroupId
;
1682 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1684 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGenerateCtrlEvent
),
1685 sizeof(CONSOLE_GENERATECTRLEVENT
));
1686 if (!NT_SUCCESS(Status
))
1688 BaseSetLastNTError(Status
);
1697 IntGetConsoleTitle(LPVOID lpConsoleTitle
, DWORD nSize
, BOOL bUnicode
)
1700 CONSOLE_API_MESSAGE ApiMessage
;
1701 PCONSOLE_GETSETCONSOLETITLE TitleRequest
= &ApiMessage
.Data
.TitleRequest
;
1702 PCSR_CAPTURE_BUFFER CaptureBuffer
;
1704 if (nSize
== 0) return 0;
1706 TitleRequest
->Length
= nSize
* (bUnicode
? 1 : sizeof(WCHAR
));
1707 CaptureBuffer
= CsrAllocateCaptureBuffer(1, TitleRequest
->Length
);
1708 if (CaptureBuffer
== NULL
)
1710 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
1711 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1715 CsrAllocateMessagePointer(CaptureBuffer
,
1716 TitleRequest
->Length
,
1717 (PVOID
*)&TitleRequest
->Title
);
1719 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1721 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetTitle
),
1722 sizeof(CONSOLE_GETSETCONSOLETITLE
));
1723 if (!NT_SUCCESS(Status
))
1725 CsrFreeCaptureBuffer(CaptureBuffer
);
1726 BaseSetLastNTError(Status
);
1732 if (nSize
>= sizeof(WCHAR
))
1733 wcscpy((LPWSTR
)lpConsoleTitle
, TitleRequest
->Title
);
1737 if (nSize
< TitleRequest
->Length
/ sizeof(WCHAR
) ||
1738 !WideCharToMultiByte(CP_ACP
, // ANSI code page
1739 0, // performance and mapping flags
1740 TitleRequest
->Title
, // address of wide-character string
1741 -1, // number of characters in string
1742 (LPSTR
)lpConsoleTitle
, // address of buffer for new string
1743 nSize
, // size of buffer
1747 /* Yes, if the buffer isn't big enough, it returns 0... Bad API */
1748 *(LPSTR
)lpConsoleTitle
= '\0';
1749 TitleRequest
->Length
= 0;
1752 CsrFreeCaptureBuffer(CaptureBuffer
);
1754 return TitleRequest
->Length
/ sizeof(WCHAR
);
1758 /*--------------------------------------------------------------
1765 GetConsoleTitleW(LPWSTR lpConsoleTitle
,
1768 return IntGetConsoleTitle(lpConsoleTitle
, nSize
, TRUE
);
1772 /*--------------------------------------------------------------
1779 GetConsoleTitleA(LPSTR lpConsoleTitle
,
1782 return IntGetConsoleTitle(lpConsoleTitle
, nSize
, FALSE
);
1786 /*--------------------------------------------------------------
1793 SetConsoleTitleW(LPCWSTR lpConsoleTitle
)
1796 CONSOLE_API_MESSAGE ApiMessage
;
1797 PCONSOLE_GETSETCONSOLETITLE TitleRequest
= &ApiMessage
.Data
.TitleRequest
;
1798 PCSR_CAPTURE_BUFFER CaptureBuffer
;
1800 TitleRequest
->Length
= wcslen(lpConsoleTitle
) * sizeof(WCHAR
);
1802 CaptureBuffer
= CsrAllocateCaptureBuffer(1, TitleRequest
->Length
);
1803 if (CaptureBuffer
== NULL
)
1805 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
1806 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1810 CsrCaptureMessageBuffer(CaptureBuffer
,
1811 (PVOID
)lpConsoleTitle
,
1812 TitleRequest
->Length
,
1813 (PVOID
*)&TitleRequest
->Title
);
1815 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1817 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetTitle
),
1818 sizeof(CONSOLE_GETSETCONSOLETITLE
));
1820 CsrFreeCaptureBuffer(CaptureBuffer
);
1822 if (!NT_SUCCESS(Status
))
1824 BaseSetLastNTError(Status
);
1832 /*--------------------------------------------------------------
1839 SetConsoleTitleA(LPCSTR lpConsoleTitle
)
1842 ULONG Length
= strlen(lpConsoleTitle
) + 1;
1843 LPWSTR WideTitle
= HeapAlloc(GetProcessHeap(), 0, Length
* sizeof(WCHAR
));
1847 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1851 MultiByteToWideChar(CP_ACP
, 0, lpConsoleTitle
, -1, WideTitle
, Length
);
1853 Ret
= SetConsoleTitleW(WideTitle
);
1855 HeapFree(GetProcessHeap(), 0, WideTitle
);
1860 /*--------------------------------------------------------------
1861 * CreateConsoleScreenBuffer
1867 CreateConsoleScreenBuffer(DWORD dwDesiredAccess
,
1869 CONST SECURITY_ATTRIBUTES
*lpSecurityAttributes
,
1871 LPVOID lpScreenBufferData
)
1874 CONSOLE_API_MESSAGE ApiMessage
;
1875 PCONSOLE_CREATESCREENBUFFER CreateScreenBufferRequest
= &ApiMessage
.Data
.CreateScreenBufferRequest
;
1876 PCSR_CAPTURE_BUFFER CaptureBuffer
= NULL
;
1877 PCONSOLE_GRAPHICS_BUFFER_INFO GraphicsBufferInfo
= /*(PCONSOLE_GRAPHICS_BUFFER_INFO)*/lpScreenBufferData
;
1879 if ( (dwDesiredAccess
& ~(GENERIC_READ
| GENERIC_WRITE
)) ||
1880 (dwShareMode
& ~(FILE_SHARE_READ
| FILE_SHARE_WRITE
)) ||
1881 (dwFlags
!= CONSOLE_TEXTMODE_BUFFER
&& dwFlags
!= CONSOLE_GRAPHICS_BUFFER
) )
1883 SetLastError(ERROR_INVALID_PARAMETER
);
1884 return INVALID_HANDLE_VALUE
;
1887 CreateScreenBufferRequest
->ScreenBufferType
= dwFlags
;
1888 CreateScreenBufferRequest
->Access
= dwDesiredAccess
;
1889 CreateScreenBufferRequest
->ShareMode
= dwShareMode
;
1890 CreateScreenBufferRequest
->Inheritable
=
1891 (lpSecurityAttributes
? lpSecurityAttributes
->bInheritHandle
: FALSE
);
1893 if (dwFlags
== CONSOLE_GRAPHICS_BUFFER
)
1895 if (CreateScreenBufferRequest
->Inheritable
|| GraphicsBufferInfo
== NULL
)
1897 SetLastError(ERROR_INVALID_PARAMETER
);
1898 return INVALID_HANDLE_VALUE
;
1901 CreateScreenBufferRequest
->GraphicsBufferInfo
= *GraphicsBufferInfo
;
1903 CaptureBuffer
= CsrAllocateCaptureBuffer(1, GraphicsBufferInfo
->dwBitMapInfoLength
);
1904 if (CaptureBuffer
== NULL
)
1906 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1910 CsrCaptureMessageBuffer(CaptureBuffer
,
1911 (PVOID
)GraphicsBufferInfo
->lpBitMapInfo
,
1912 GraphicsBufferInfo
->dwBitMapInfoLength
,
1913 (PVOID
*)&CreateScreenBufferRequest
->GraphicsBufferInfo
.lpBitMapInfo
);
1916 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1918 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepCreateScreenBuffer
),
1919 sizeof(CONSOLE_CREATESCREENBUFFER
));
1922 CsrFreeCaptureBuffer(CaptureBuffer
);
1924 if (!NT_SUCCESS(Status
))
1926 BaseSetLastNTError(Status
);
1927 return INVALID_HANDLE_VALUE
;
1930 if (dwFlags
== CONSOLE_GRAPHICS_BUFFER
&& GraphicsBufferInfo
)
1932 GraphicsBufferInfo
->hMutex
= CreateScreenBufferRequest
->GraphicsBufferInfo
.hMutex
;
1933 GraphicsBufferInfo
->lpBitMap
= CreateScreenBufferRequest
->GraphicsBufferInfo
.lpBitMap
;
1936 return CreateScreenBufferRequest
->OutputHandle
;
1940 /*--------------------------------------------------------------
1950 CONSOLE_API_MESSAGE ApiMessage
;
1952 /* Get the Input Code Page */
1953 ApiMessage
.Data
.ConsoleCPRequest
.InputCP
= TRUE
;
1954 ApiMessage
.Data
.ConsoleCPRequest
.CodePage
= 0;
1956 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1958 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetCP
),
1959 sizeof(CONSOLE_GETSETINPUTOUTPUTCP
));
1961 if (!NT_SUCCESS(Status
)) BaseSetLastNTError(Status
);
1963 return ApiMessage
.Data
.ConsoleCPRequest
.CodePage
;
1967 /*--------------------------------------------------------------
1974 SetConsoleCP(UINT wCodePageID
)
1977 CONSOLE_API_MESSAGE ApiMessage
;
1979 /* Set the Input Code Page */
1980 ApiMessage
.Data
.ConsoleCPRequest
.InputCP
= TRUE
;
1981 ApiMessage
.Data
.ConsoleCPRequest
.CodePage
= wCodePageID
;
1983 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
1985 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetCP
),
1986 sizeof(CONSOLE_GETSETINPUTOUTPUTCP
));
1988 if (!NT_SUCCESS(Status
)) BaseSetLastNTError(Status
);
1990 return NT_SUCCESS(Status
);
1994 /*--------------------------------------------------------------
1995 * GetConsoleOutputCP
2001 GetConsoleOutputCP(VOID
)
2004 CONSOLE_API_MESSAGE ApiMessage
;
2006 /* Get the Output Code Page */
2007 ApiMessage
.Data
.ConsoleCPRequest
.InputCP
= FALSE
;
2008 ApiMessage
.Data
.ConsoleCPRequest
.CodePage
= 0;
2010 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2012 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetCP
),
2013 sizeof(CONSOLE_GETSETINPUTOUTPUTCP
));
2015 if (!NT_SUCCESS(Status
)) BaseSetLastNTError(Status
);
2017 return ApiMessage
.Data
.ConsoleCPRequest
.CodePage
;
2021 /*--------------------------------------------------------------
2022 * SetConsoleOutputCP
2028 SetConsoleOutputCP(UINT wCodePageID
)
2031 CONSOLE_API_MESSAGE ApiMessage
;
2033 /* Set the Output Code Page */
2034 ApiMessage
.Data
.ConsoleCPRequest
.InputCP
= FALSE
;
2035 ApiMessage
.Data
.ConsoleCPRequest
.CodePage
= wCodePageID
;
2037 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2039 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetCP
),
2040 sizeof(CONSOLE_GETSETINPUTOUTPUTCP
));
2042 if (!NT_SUCCESS(Status
)) BaseSetLastNTError(Status
);
2044 return NT_SUCCESS(Status
);
2048 /*--------------------------------------------------------------
2049 * GetConsoleProcessList
2055 GetConsoleProcessList(LPDWORD lpdwProcessList
,
2056 DWORD dwProcessCount
)
2059 CONSOLE_API_MESSAGE ApiMessage
;
2060 PCONSOLE_GETPROCESSLIST GetProcessListRequest
= &ApiMessage
.Data
.GetProcessListRequest
;
2061 PCSR_CAPTURE_BUFFER CaptureBuffer
;
2064 if (lpdwProcessList
== NULL
|| dwProcessCount
== 0)
2066 SetLastError(ERROR_INVALID_PARAMETER
);
2070 CaptureBuffer
= CsrAllocateCaptureBuffer(1, dwProcessCount
* sizeof(DWORD
));
2071 if (CaptureBuffer
== NULL
)
2073 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
2074 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2078 GetProcessListRequest
->nMaxIds
= dwProcessCount
;
2080 CsrAllocateMessagePointer(CaptureBuffer
,
2081 dwProcessCount
* sizeof(DWORD
),
2082 (PVOID
*)&GetProcessListRequest
->pProcessIds
);
2084 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2086 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetProcessList
),
2087 sizeof(CONSOLE_GETPROCESSLIST
));
2088 if (!NT_SUCCESS(Status
))
2090 BaseSetLastNTError (Status
);
2095 nProcesses
= GetProcessListRequest
->nProcessIdsTotal
;
2096 if (dwProcessCount
>= nProcesses
)
2098 memcpy(lpdwProcessList
, GetProcessListRequest
->pProcessIds
, nProcesses
* sizeof(DWORD
));
2102 CsrFreeCaptureBuffer(CaptureBuffer
);
2107 /*--------------------------------------------------------------
2108 * GetConsoleSelectionInfo
2114 GetConsoleSelectionInfo(PCONSOLE_SELECTION_INFO lpConsoleSelectionInfo
)
2117 CONSOLE_API_MESSAGE ApiMessage
;
2119 if (lpConsoleSelectionInfo
== NULL
)
2121 SetLastError(ERROR_INVALID_PARAMETER
);
2125 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2127 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetSelectionInfo
),
2128 sizeof(CONSOLE_GETSELECTIONINFO
));
2129 if (!NT_SUCCESS(Status
))
2131 BaseSetLastNTError(Status
);
2135 *lpConsoleSelectionInfo
= ApiMessage
.Data
.GetSelectionInfoRequest
.Info
;
2140 /*--------------------------------------------------------------
2145 * @note Strongly inspired by AllocConsole.
2149 AttachConsole(DWORD dwProcessId
)
2152 PRTL_USER_PROCESS_PARAMETERS Parameters
= NtCurrentPeb()->ProcessParameters
;
2153 CONSOLE_API_MESSAGE ApiMessage
;
2154 PCONSOLE_ATTACHCONSOLE AttachConsoleRequest
= &ApiMessage
.Data
.AttachConsoleRequest
;
2156 if (Parameters
->ConsoleHandle
)
2158 DPRINT1("AttachConsole: Attaching a console to a process already having one\n");
2159 SetLastError(ERROR_ACCESS_DENIED
);
2163 AttachConsoleRequest
->ProcessId
= dwProcessId
;
2164 AttachConsoleRequest
->CtrlDispatcher
= ConsoleControlDispatcher
;
2165 AttachConsoleRequest
->PropDispatcher
= PropDialogHandler
;
2167 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2169 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepAttach
),
2170 sizeof(CONSOLE_ATTACHCONSOLE
));
2171 if (!NT_SUCCESS(Status
))
2173 BaseSetLastNTError(Status
);
2177 Parameters
->ConsoleHandle
= AttachConsoleRequest
->Console
;
2178 SetStdHandle(STD_INPUT_HANDLE
, AttachConsoleRequest
->InputHandle
);
2179 SetStdHandle(STD_OUTPUT_HANDLE
, AttachConsoleRequest
->OutputHandle
);
2180 SetStdHandle(STD_ERROR_HANDLE
, AttachConsoleRequest
->ErrorHandle
);
2182 /* Initialize Console Ctrl Handler */
2183 InitConsoleCtrlHandling();
2185 InputWaitHandle
= AttachConsoleRequest
->InputWaitHandle
;
2191 /*--------------------------------------------------------------
2198 GetConsoleWindow(VOID
)
2201 CONSOLE_API_MESSAGE ApiMessage
;
2203 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2205 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetConsoleWindow
),
2206 sizeof(CONSOLE_GETWINDOW
));
2207 if (!NT_SUCCESS(Status
))
2209 BaseSetLastNTError(Status
);
2213 return ApiMessage
.Data
.GetWindowRequest
.WindowHandle
;
2217 /*--------------------------------------------------------------
2224 SetConsoleIcon(HICON hicon
)
2227 CONSOLE_API_MESSAGE ApiMessage
;
2229 ApiMessage
.Data
.SetIconRequest
.WindowIcon
= hicon
;
2231 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
2233 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetIcon
),
2234 sizeof(CONSOLE_SETICON
));
2235 if (!NT_SUCCESS(Status
))
2237 BaseSetLastNTError(Status
);
2241 return NT_SUCCESS(Status
);
2245 /******************************************************************************
2246 * \name SetConsoleInputExeNameW
2247 * \brief Sets the console input file name from a unicode string.
2248 * \param lpInputExeName Pointer to a unicode string with the name.
2249 * \return TRUE if successful, FALSE if unsuccsedful.
2250 * \remarks If lpInputExeName is 0 or the string length is 0 or greater than 255,
2251 * the function fails and sets last error to ERROR_INVALID_PARAMETER.
2255 SetConsoleInputExeNameW(LPCWSTR lpInputExeName
)
2259 if ( !lpInputExeName
||
2260 (lenName
= lstrlenW(lpInputExeName
)) == 0 ||
2261 lenName
> INPUTEXENAME_BUFLEN
- 1 )
2263 /* Fail if string is empty or too long */
2264 SetLastError(ERROR_INVALID_PARAMETER
);
2268 RtlEnterCriticalSection(&ConsoleLock
);
2271 RtlCopyMemory(InputExeName
, lpInputExeName
, lenName
* sizeof(WCHAR
));
2272 InputExeName
[lenName
] = L
'\0';
2276 RtlLeaveCriticalSection(&ConsoleLock
);
2284 /******************************************************************************
2285 * \name SetConsoleInputExeNameA
2286 * \brief Sets the console input file name from an ansi string.
2287 * \param lpInputExeName Pointer to an ansi string with the name.
2288 * \return TRUE if successful, FALSE if unsuccsedful.
2289 * \remarks If lpInputExeName is 0 or the string length is 0 or greater than 255,
2290 * the function fails and sets last error to ERROR_INVALID_PARAMETER.
2294 SetConsoleInputExeNameA(LPCSTR lpInputExeName
)
2296 WCHAR Buffer
[INPUTEXENAME_BUFLEN
];
2297 ANSI_STRING InputExeNameA
;
2298 UNICODE_STRING InputExeNameU
;
2301 RtlInitAnsiString(&InputExeNameA
, lpInputExeName
);
2303 if ( InputExeNameA
.Length
== 0 ||
2304 InputExeNameA
.Length
> INPUTEXENAME_BUFLEN
- 1 )
2306 /* Fail if string is empty or too long */
2307 SetLastError(ERROR_INVALID_PARAMETER
);
2311 InputExeNameU
.Buffer
= Buffer
;
2312 InputExeNameU
.MaximumLength
= sizeof(Buffer
);
2313 InputExeNameU
.Length
= 0;
2315 Status
= RtlAnsiStringToUnicodeString(&InputExeNameU
, &InputExeNameA
, FALSE
);
2316 if (!NT_SUCCESS(Status
))
2318 BaseSetLastNTError(Status
);
2322 return SetConsoleInputExeNameW(InputExeNameU
.Buffer
);
2326 /******************************************************************************
2327 * \name GetConsoleInputExeNameW
2328 * \brief Retrieves the console input file name as unicode string.
2329 * \param nBufferLength Length of the buffer in WCHARs.
2330 * Specify 0 to receive the needed buffer length.
2331 * \param lpBuffer Pointer to a buffer that receives the string.
2332 * \return Needed buffer size if \p nBufferLength is 0.
2333 * Otherwise 1 if successful, 2 if buffer is too small.
2334 * \remarks Sets last error value to ERROR_BUFFER_OVERFLOW if the buffer
2335 * is not big enough.
2339 GetConsoleInputExeNameW(DWORD nBufferLength
, LPWSTR lpBuffer
)
2341 ULONG lenName
= lstrlenW(InputExeName
);
2343 if (nBufferLength
== 0)
2345 /* Buffer size is requested, return it */
2349 if (lenName
+ 1 > nBufferLength
)
2351 /* Buffer is not large enough! */
2352 SetLastError(ERROR_BUFFER_OVERFLOW
);
2356 RtlEnterCriticalSection(&ConsoleLock
);
2359 RtlCopyMemory(lpBuffer
, InputExeName
, lenName
* sizeof(WCHAR
));
2360 lpBuffer
[lenName
] = '\0';
2364 RtlLeaveCriticalSection(&ConsoleLock
);
2368 /* Success, return 1 */
2373 /******************************************************************************
2374 * \name GetConsoleInputExeNameA
2375 * \brief Retrieves the console input file name as ansi string.
2376 * \param nBufferLength Length of the buffer in CHARs.
2377 * \param lpBuffer Pointer to a buffer that receives the string.
2378 * \return 1 if successful, 2 if buffer is too small.
2379 * \remarks Sets last error value to ERROR_BUFFER_OVERFLOW if the buffer
2380 * is not big enough. The buffer receives as much characters as fit.
2384 GetConsoleInputExeNameA(DWORD nBufferLength
, LPSTR lpBuffer
)
2386 WCHAR Buffer
[INPUTEXENAME_BUFLEN
];
2388 UNICODE_STRING BufferU
;
2389 ANSI_STRING BufferA
;
2391 /* Get the unicode name */
2392 Ret
= GetConsoleInputExeNameW(sizeof(Buffer
) / sizeof(Buffer
[0]), Buffer
);
2394 /* Initialize strings for conversion */
2395 RtlInitUnicodeString(&BufferU
, Buffer
);
2397 BufferA
.MaximumLength
= (USHORT
)nBufferLength
;
2398 BufferA
.Buffer
= lpBuffer
;
2400 /* Convert unicode name to ansi, copying as much chars as fit */
2401 RtlUnicodeStringToAnsiString(&BufferA
, &BufferU
, FALSE
);
2403 /* Error handling */
2404 if (nBufferLength
<= BufferU
.Length
/ sizeof(WCHAR
))
2406 SetLastError(ERROR_BUFFER_OVERFLOW
);
2415 GetConsoleCharType(HANDLE hConsole
, COORD Coord
, PDWORD Type
)
2423 GetConsoleCursorMode(HANDLE hConsole
, PBOOL pUnknown1
, PBOOL pUnknown2
)
2431 GetConsoleNlsMode(HANDLE hConsole
, LPDWORD lpMode
)
2439 SetConsoleCursorMode(HANDLE hConsole
, BOOL Unknown1
, BOOL Unknown2
)
2447 SetConsoleLocalEUDC(DWORD Unknown1
, DWORD Unknown2
, DWORD Unknown3
, DWORD Unknown4
)
2455 SetConsoleNlsMode(HANDLE hConsole
, DWORD dwMode
)
2463 RegisterConsoleIME(HWND hWnd
, LPDWORD ThreadId
)
2471 RegisterConsoleOS2(BOOL bUnknown
)
2479 SetConsoleOS2OemFormat(BOOL bUnknown
)
2487 UnregisterConsoleIME(VOID
)
2497 BOOL WINAPI
GetConsoleKeyboardLayoutNameA(LPSTR name
)
2506 BOOL WINAPI
GetConsoleKeyboardLayoutNameW(LPWSTR name
)
2517 SetLastConsoleEventActive(VOID
)