本文整理汇总了C++中ReadConsole函数的典型用法代码示例。如果您正苦于以下问题:C++ ReadConsole函数的具体用法?C++ ReadConsole怎么用?C++ ReadConsole使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ReadConsole函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: read_win32
ssize_t
read_win32(int fildes, void *buf, size_t nbyte)
{
DWORD val=0;
DWORD filetype = GetFileType((HANDLE) fildes);
if (fildes == fileno(stdin))
{
ReadConsole(GetStdHandle(STD_INPUT_HANDLE), buf, nbyte, &val, NULL);
}
else if (filetype == FILE_TYPE_DISK)
{
ReadFile((HANDLE)fildes, buf, nbyte, &val, NULL);
}
else if (filetype == FILE_TYPE_CHAR)
{
ReadConsole(GetStdHandle(STD_INPUT_HANDLE), buf, nbyte, &val, NULL);
}
else
{
OVERLAPPED overlap;
overlap.hEvent = (HANDLE)NULL;
if (ReadFile((HANDLE) fildes, buf, nbyte, &val, &overlap)==FALSE)
{
if (!GetOverlappedResult((HANDLE) fildes, &overlap, &val, TRUE))
{
const DWORD error = GetLastError();
cerr << "read_win32, error is: " << error << " - "
<< " - " << fildes << endl;
}
}
}
return val;
}
示例2: lock
std::tstring Console::ReadLine(void)
{
std::vector<tchar_t> accumulator; // Character accumulator
DWORD mode = 0; // Original console mode
DWORD read = 0; // Characters read from the console
tchar_t next; // Next character read from console
// Prevent multiple threads from reading the console at the same time
std::lock_guard<std::recursive_mutex> lock(m_readlock);
// Ensure LINE_INPUT and ECHO_INPUT are enabled for the input mode
if(!GetConsoleMode(m_stdin, &mode)) throw Win32Exception();
if(!SetConsoleMode(m_stdin, mode | ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT)) throw Win32Exception();
try {
// Repeatedly read characters from the console until CR has been detected
if(!ReadConsole(m_stdin, &next, 1, &read, nullptr)) throw Win32Exception();
while(next != _T('\n')) {
if(next != _T('\r')) accumulator.push_back(next);
if(!ReadConsole(m_stdin, &next, 1, &read, nullptr)) throw Win32Exception();
}
}
// Be sure the restore the original console mode flags on any exception
catch(...) { SetConsoleMode(m_stdin, mode); throw; }
// Restore the previously set input mode flags
SetConsoleMode(m_stdin, mode);
// Convert the accumulated character data as a tstring instance
return std::tstring(accumulator.data(), accumulator.size());
}
示例3: SetUserThreshold
/*-----------------------------------------------------------------------------
SetUserThreshold(IDiskQuotaControl* lpDiskQuotaControl)
Set the warning threshold limit for a specific user
Parameters
lpDiskQuotaControl - Pointer to an object that implements the
IDiskQuotaControl interface
Return Value
TRUE - Success
FALSE - Failure
-----------------------------------------------------------------------------*/
BOOL SetUserThreshold(IDiskQuotaControl* lpDiskQuotaControl)
{
HRESULT hr;
IDiskQuotaUser* lpDiskQuotaUser;
WCHAR szUser[MAX_PATH] = {0};
DWORD dwCharsRead;
LONGLONG llLimit = 0;
HANDLE hStdIn = GetStdHandle(STD_INPUT_HANDLE);
wprintf(L"\n\nEnter the logon name of the user ");
wprintf(L"(ie. DOMAIN\\USERNAME): ");
// Get the user for which to set a hard limit
ReadConsole(hStdIn, szUser, MAX_PATH, &dwCharsRead, NULL);
szUser[MAX_PATH-1] = L'\0'; // make sure szUSer is NULL terminated
// Strip the line feed and carriage return
LfcrToNull(szUser);
// Check if the name is valid
hr = lpDiskQuotaControl->FindUserName((LPCWSTR)szUser, &lpDiskQuotaUser);
if (SUCCEEDED(hr))
{
WCHAR szLimit[MAX_PATH] = {0};
wprintf(L"\nEnter the new hard limit in bytes (-1 == No Limit): ");
// Read the threshold from the console
ReadConsole(hStdIn, szLimit, MAX_PATH, &dwCharsRead, NULL);
LfcrToNull(szLimit);
llLimit = _wtoi64(szLimit);
if (llLimit >= -1)
{
// Set the warning threshold for the user
hr = lpDiskQuotaUser->SetQuotaThreshold(llLimit, TRUE);
if (FAILED(hr))
{
wprintf(L"\nCould not set the quota limit for %s", szUser);
wprintf(L"to %i64 bytes\n", llLimit);
}
}
else
{
wprintf(L"\nInvalid limit!");
}
lpDiskQuotaUser->Release();
}
else
{
PrintError(hr);
}
return SUCCEEDED(hr);
}
示例4: pointerToHandle
JNIEXPORT jstring JNICALL Java_com_yifanlu_Josh_Josh_READCONSOLE
(JNIEnv *env, jclass jcls, jlong pointer)
{
HANDLE hIn = pointerToHandle(pointer);
char ReadBuffer[1024] = {0};
DWORD dwBytesRead = 0;
ReadConsole(hIn, &ReadBuffer, 1024, &dwBytesRead, NULL);
char input[1024];
int count = 0;
for(int i=0; i<1024; i++)
if(ReadBuffer[i] != '\0' && count < dwBytesRead)
{
input[count] = ReadBuffer[i];
count++;
}
int len = dwBytesRead - 2;
jchar* unicodeChars = new jchar[len];
for (int i=0; i<len; i++)
unicodeChars[i] = input[i];
jstring jInput = env->NewString(unicodeChars, len);
delete[] unicodeChars;
return jInput;
}
示例5: gengetchar
globle int gengetchar(
void *theEnv)
{
#if WIN_BTC || WIN_MVC
if (SystemDependentData(theEnv)->getcLength ==
SystemDependentData(theEnv)->getcPosition)
{
TCHAR tBuffer = 0;
DWORD count = 0;
WCHAR wBuffer = 0;
ReadConsole(GetStdHandle(STD_INPUT_HANDLE),&tBuffer,1,&count,NULL);
wBuffer = tBuffer;
SystemDependentData(theEnv)->getcLength =
WideCharToMultiByte(CP_UTF8,0,&wBuffer,1,
(char *) SystemDependentData(theEnv)->getcBuffer,
7,NULL,NULL);
SystemDependentData(theEnv)->getcPosition = 0;
}
return SystemDependentData(theEnv)->getcBuffer[SystemDependentData(theEnv)->getcPosition++];
#else
return(getc(stdin));
#endif
}
示例6: AddUser
/*-----------------------------------------------------------------------------
AddUser(IDiskQuotaControl* lpDiskQuotaControl)
Add a user for which to track quota data
Parameters
lpDiskQuotaControl - Pointer to an object that implements the
IDiskQuotaControl interface
Return Value
TRUE - Success
FALSE - Failure
-----------------------------------------------------------------------------*/
BOOL AddUser(IDiskQuotaControl* lpDiskQuotaControl)
{
HRESULT hr;
IDiskQuotaUser* lpDiskQuotaUser;
WCHAR szUser[MAX_PATH] = {0};
DWORD dwCharsRead;
HANDLE hStdIn = GetStdHandle(STD_INPUT_HANDLE);
wprintf(L"\n\nEnter the logon name of the user (ie. DOMAIN\\USERNAME): ");
// Get the user for which to track quota information
ReadConsole(hStdIn, szUser, MAX_PATH, &dwCharsRead, NULL);
LfcrToNull(szUser);
// Add the user
hr = lpDiskQuotaControl->AddUserName(szUser,
DISKQUOTA_USERNAME_RESOLVE_SYNC,
&lpDiskQuotaUser);
if (FAILED(hr))
{
PrintError(hr);
return FALSE;
}
lpDiskQuotaUser->Release();
return TRUE;
}
示例7: read_wincon
/*
* read-wrapper to support reading from stdin on Windows.
*/
static ssize_t read_wincon(int fd, void *buf, size_t count)
{
HANDLE handle = NULL;
DWORD mode, rcount = 0;
BOOL success;
if(fd == fileno(stdin)) {
handle = GetStdHandle(STD_INPUT_HANDLE);
}
else {
return read(fd, buf, count);
}
if(GetConsoleMode(handle, &mode)) {
success = ReadConsole(handle, buf, curlx_uztoul(count), &rcount, NULL);
}
else {
success = ReadFile(handle, buf, curlx_uztoul(count), &rcount, NULL);
}
if(success) {
return rcount;
}
errno = GetLastError();
return -1;
}
示例8: ReadConsoleBytes
static BOOL
ReadConsoleBytes(
HANDLE hConsole,
LPVOID lpBuffer,
DWORD nbytes,
LPDWORD nbytesread)
{
DWORD ntchars;
BOOL result;
int tcharsize = sizeof(TCHAR);
/*
* If user types a Ctrl-Break or Ctrl-C, ReadConsole will return
* success with ntchars == 0 and GetLastError() will be
* ERROR_OPERATION_ABORTED. We do not want to treat this case
* as EOF so we will loop around again. If no Ctrl signal handlers
* have been established, the default signal OS handler in a separate
* thread will terminate the program. If a Ctrl signal handler
* has been established (through an extension for example), it
* will run and take whatever action it deems appropriate.
*/
do {
result = ReadConsole(hConsole, lpBuffer, nbytes / tcharsize, &ntchars,
NULL);
} while (result && ntchars == 0 && GetLastError() == ERROR_OPERATION_ABORTED);
if (nbytesread != NULL) {
*nbytesread = ntchars * tcharsize;
}
return result;
}
示例9: input_thread
static DWORD WINAPI input_thread(LPVOID arg)
{
struct ui_st *st = arg;
/* Switch to raw mode */
SetConsoleMode(st->hstdin, 0);
while (st->run) {
char buf[4];
DWORD i, count = 0;
ReadConsole(st->hstdin, buf, sizeof(buf), &count, NULL);
for (i=0; i<count; i++) {
int ch = buf[i];
if (ch == '\r')
ch = '\n';
/*
* The keys are read from a thread so we have
* to send them to the RE main event loop via
* a message queue
*/
mqueue_push(st->mq, ch, 0);
}
}
return 0;
}
示例10: r_cons_readchar
R_API int r_cons_readchar() {
void *bed;
char buf[2];
buf[0] = -1;
if (readbuffer_length > 0) {
int ch = *readbuffer;
readbuffer_length--;
memmove (readbuffer, readbuffer + 1, readbuffer_length);
return ch;
}
#if __WINDOWS__ && !__CYGWIN__ //&& !MINGW32
#if 1 // if something goes wrong set this to 0. skuater.....
return readchar_win(0);
#endif
BOOL ret;
DWORD out;
DWORD mode;
HANDLE h = GetStdHandle (STD_INPUT_HANDLE);
GetConsoleMode (h, &mode);
SetConsoleMode (h, 0); // RAW
bed = r_cons_sleep_begin ();
ret = ReadConsole (h, buf, 1, &out, NULL);
r_cons_sleep_end (bed);
FlushConsoleInputBuffer (h);
if (!ret) {
return -1;
}
SetConsoleMode (h, mode);
#else
r_cons_set_raw (1);
bed = r_cons_sleep_begin ();
// Blocks until either stdin has something to read or a signal happens.
// This serves to check if the terminal window was resized. It avoids the race
// condition that could happen if we did not use pselect or select in case SIGWINCH
// was handled immediately before the blocking call (select or read). The race is
// prevented from happening by having SIGWINCH blocked process-wide except for in
// pselect (that is what pselect is for).
fd_set readfds;
sigset_t sigmask;
FD_ZERO (&readfds);
FD_SET (STDIN_FILENO, &readfds);
r_signal_sigmask (0, NULL, &sigmask);
sigdelset (&sigmask, SIGWINCH);
pselect (STDIN_FILENO + 1, &readfds, NULL, NULL, NULL, &sigmask);
if (sigwinchFlag != 0) {
resizeWin ();
}
ssize_t ret = read (STDIN_FILENO, buf, 1);
r_cons_sleep_end (bed);
if (ret != 1) {
return -1;
}
if (bufactive) {
r_cons_set_raw (0);
}
#endif
return r_cons_controlz (buf[0]);
}
示例11: console_input
/**
* Very simplistic console input
*/
static void console_input(void)
{
TCHAR inp;
DWORD read;
if(!ReadConsole(events[1], &inp, 1, &read, NULL))
return;
switch(inp) {
case 8:
if(console_ptr > 0) {
console_ptr--;
printf("\b \b");
}
break;
case 13:
printf("\n\r");
console_buf[console_ptr++] = 0;
console_ptr = 0;
enable_console = 0;
cmd_exec_unparsed(console_buf);
break;
default:
if(console_ptr < sizeof(console_buf) - 1) {
printf("%c", (char)inp);
console_buf[console_ptr++] = inp;
}
break;
}
}
示例12: GetPasswordText
static void GetPasswordText(wchar *Str,uint MaxLength)
{
if (MaxLength==0)
return;
#ifdef _WIN_ALL
HANDLE hConIn=GetStdHandle(STD_INPUT_HANDLE);
HANDLE hConOut=GetStdHandle(STD_OUTPUT_HANDLE);
DWORD ConInMode,ConOutMode;
DWORD Read=0;
GetConsoleMode(hConIn,&ConInMode);
GetConsoleMode(hConOut,&ConOutMode);
SetConsoleMode(hConIn,ENABLE_LINE_INPUT);
SetConsoleMode(hConOut,ENABLE_PROCESSED_OUTPUT|ENABLE_WRAP_AT_EOL_OUTPUT);
ReadConsole(hConIn,Str,MaxLength-1,&Read,NULL);
Str[Read]=0;
SetConsoleMode(hConIn,ConInMode);
SetConsoleMode(hConOut,ConOutMode);
#else
char StrA[MAXPASSWORD];
#if defined(_EMX) || defined (__VMS) || defined(__AROS__)
fgets(StrA,ASIZE(StrA)-1,stdin);
#elif defined(__sun)
strncpyz(StrA,getpassphrase(""),ASIZE(StrA));
#else
strncpyz(StrA,getpass(""),ASIZE(StrA));
#endif
CharToWide(StrA,Str,MaxLength);
cleandata(StrA,sizeof(StrA));
#endif
Str[MaxLength-1]=0;
RemoveLF(Str);
}
示例13: r_cons_readchar
R_API int r_cons_readchar() {
char buf[2];
buf[0] = -1;
#if __WINDOWS__ && !__CYGWIN__ //&& !MINGW32
#if 1 // if something goes wrong set this to 0. skuater.....
return readchar_win(0);
#endif
BOOL ret;
DWORD out;
DWORD mode;
HANDLE h = GetStdHandle (STD_INPUT_HANDLE);
GetConsoleMode (h, &mode);
SetConsoleMode (h, 0); // RAW
ret = ReadConsole (h, buf, 1, &out, NULL);
FlushConsoleInputBuffer (h);
if (!ret) {
return -1;
}
SetConsoleMode (h, mode);
#else
r_cons_set_raw (1);
if (read (0, buf, 1) == -1) {
return -1;
}
r_cons_set_raw (0);
#endif
return r_cons_controlz (buf[0]);
}
示例14: PeekConsoleInput
INPUT_RECORD *TThreads::get_next_event(void) {
if (evpending) return &ir;
PeekConsoleInput(chandle[cnInput],&ir,1,&evpending);
if (evpending) {
int code = event_type(ir);
// printf("evtype = %d\n",code);
switch (code) {
case IO_RAW_EVENT:
ReadConsoleInput(chandle[cnInput],&ir,1,&evpending);
break;
case IO_CHR_EVENT:
char chr;
// printf("before readconsole\n");
ReadConsole(chandle[cnInput],&chr,1,&evpending,NULL);
// printf("key %x %d\n",chr,evpending);
ir.Event.KeyEvent.uChar.AsciiChar = chr;
break;
case IO_IGN_EVENT:
ReadConsoleInput(chandle[cnInput],&ir,1,&evpending);
accept_event();
break;
}
}
return evpending ? &ir : NULL;
}
示例15: SetDefaultThreshold
/*-----------------------------------------------------------------------------
SetDefaultThreshold(IDiskQuotaControl* lpDiskQuotaControl)
Set the default warning threshold of the volume.
Parameters
lpDiskQuotaControl - Pointer to an object that implements the
IDiskQuotaControl interface
Return Value
TRUE - Success
FALSE - Failure
-----------------------------------------------------------------------------*/
BOOL SetDefaultThreshold(IDiskQuotaControl* lpDiskQuotaControl)
{
HRESULT hr;
LONGLONG llLimit = 0;
WCHAR szLimit[MAX_PATH] = {0};
DWORD dwCharsRead;
HANDLE hStdIn = GetStdHandle(STD_INPUT_HANDLE);
wprintf(L"\n\nEnter the new default threshold in Bytes ");
wprintf(L"(-1 == No Limit): ");
// Get the limit from the command prompt
ReadConsole(hStdIn, szLimit, MAX_PATH, &dwCharsRead, NULL);
LfcrToNull(szLimit);
llLimit = _wtoi64(szLimit);
if (llLimit < -1)
{
wprintf(L"\nInvalid limit!");
return FALSE;
}
// Set the default warning threshold
hr = lpDiskQuotaControl->SetDefaultQuotaThreshold(llLimit);
if (FAILED(hr))
{
PrintError(hr);
return FALSE;
}
return TRUE;
}