ReactOS 0.4.16-dev-1028-g8602629
initconin.cpp
Go to the documentation of this file.
1//
2// initconin.cpp
3//
4// Copyright (c) Microsoft Corporation. All rights reserved.
5//
6// Defines the global console input handle and the __dcrt_lowio_initialize_console_input() and
7// __dcrt_terminate_console_input() functions, which initialize and close that handle.
8// Also defines functions that can be used instead of the Console API to enable retry behavior
9// in case the cached console handle is freed.
10
12
13_CRT_LINKER_FORCE_INCLUDE(__dcrt_console_input_terminator);
14
15// The global console input handle.
17
18// Initializes the global console input handle
20{
22 L"CONIN$",
25 nullptr,
27 0,
28 nullptr);
29}
30
32{
34 {
36 }
37
39 {
40 return FALSE;
41 }
42 return TRUE;
43}
44
45// Closes the global console input handle
47{
50 {
52 }
53}
54
55template <typename Func>
56static BOOL console_input_reopen_and_retry(Func const& fp) throw()
57{
58 BOOL result = fp();
62 result = fp();
63 }
64 return result;
65}
66
71 )
72{
75 {
76 return ::ReadConsoleInputW(
79 nLength,
81 );
82 });
83}
84
88 _Out_ LPDWORD lpNumberOfCharsRead
89 )
90{
92 [lpBuffer, nNumberOfCharsToRead, lpNumberOfCharsRead]()
93 {
94 return ::ReadConsoleW(
98 lpNumberOfCharsRead,
99 nullptr
100 );
101 });
102}
103
105 _Out_ LPDWORD lpcNumberOfEvents
106 )
107{
109 [lpcNumberOfEvents]()
110 {
111 return ::GetNumberOfConsoleInputEvents(
113 lpcNumberOfEvents
114 );
115 });
116}
117
122 )
123{
126 {
127 return ::PeekConsoleInputA(
129 lpBuffer,
130 nLength,
132 );
133 });
134}
135
137 _Out_ LPDWORD lpMode
138 )
139{
141 [lpMode]()
142 {
143 return ::GetConsoleMode(
145 lpMode
146 );
147 });
148}
149
151 _In_ DWORD dwMode
152 )
153{
155 [dwMode]()
156 {
157 return ::SetConsoleMode(
159 dwMode
160 );
161 });
162}
#define __cdecl
Definition: accygwin.h:79
#define _CRT_LINKER_FORCE_INCLUDE(name)
const HANDLE _console_invalid_handle
const HANDLE _console_uninitialized_handle
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:175
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define OPEN_EXISTING
Definition: compat.h:775
#define GENERIC_READ
Definition: compat.h:135
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
#define CreateFileW
Definition: compat.h:741
#define FILE_SHARE_READ
Definition: compat.h:136
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint64EXT * result
Definition: glext.h:11304
BOOL __cdecl __dcrt_read_console(_Out_ LPVOID lpBuffer, _In_ DWORD nNumberOfCharsToRead, _Out_ LPDWORD lpNumberOfCharsRead)
Definition: initconin.cpp:85
static BOOL console_input_reopen_and_retry(Func const &fp)
Definition: initconin.cpp:56
BOOL __cdecl __dcrt_read_console_input(_Out_ PINPUT_RECORD lpBuffer, _In_ DWORD nLength, _Out_ LPDWORD lpNumberOfEventsRead)
Definition: initconin.cpp:67
BOOL __cdecl __dcrt_peek_console_input_a(_Out_ PINPUT_RECORD lpBuffer, _In_ DWORD nLength, _Out_ LPDWORD lpNumberOfEventsRead)
Definition: initconin.cpp:118
static HANDLE __dcrt_lowio_console_input_handle
Definition: initconin.cpp:16
BOOL __cdecl __dcrt_get_input_console_mode(_Out_ LPDWORD lpMode)
Definition: initconin.cpp:136
BOOL __cdecl __dcrt_get_number_of_console_input_events(_Out_ LPDWORD lpcNumberOfEvents)
Definition: initconin.cpp:104
BOOL __cdecl __dcrt_lowio_ensure_console_input_initialized()
Definition: initconin.cpp:31
static void __dcrt_lowio_initialize_console_input()
Definition: initconin.cpp:19
void __cdecl __dcrt_terminate_console_input()
Definition: initconin.cpp:46
BOOL __cdecl __dcrt_set_input_console_mode(_In_ DWORD dwMode)
Definition: initconin.cpp:150
#define _Out_
Definition: no_sal2.h:160
#define _In_
Definition: no_sal2.h:158
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define GENERIC_WRITE
Definition: nt_native.h:90
#define L(x)
Definition: ntvdm.h:50
void(* Func)(int)
uint32_t * LPDWORD
Definition: typedefs.h:59
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
_In_ DWORD _Out_ LPDWORD lpNumberOfEventsRead
Definition: wincon.h:474
_In_ DWORD nNumberOfCharsToRead
Definition: wincon.h:491
_In_ DWORD nLength
Definition: wincon.h:473