hConsoleHandle , GENERIC_WRITE, .
fdevMode . , , (input) (output). , .
ENABLE_LINE_INPUT (ReadConsole) .
ENABLE_ECHO_INPUT - .
ENABLE_PROCESSED_INPUT , .
ENABLE_PROCESSED_OUTPUT , , , .
ENABLE_WRAP_AT_EOL_OUTPUT , - .
SetConsoleMode , FALSE. , GetLastError.
ReadConsole WriteConsole ReadFile WriteFile.
BOOL ReadConsole(HANDLE hConsoleInput, LPVOID lpBuffer, DWORD cchToRead, LPDWORD lpcchRead, LPVOID lpReserved)
: , , TRUE, FALSE.
, ReadFile. , (cchToRead) (lpcchRead) , , , lpReserved NULL. , , lpReserved, . WriteConsole . Read-Console WriteConsole, , , , .
. , , . , , GUI-, , . , .
BOOL FreeConsole(VOID)
|
|
BOOL AllocConsole(VOID)
FreeConsole , AllocConsole , , , . , AllocConsole ; , FreeConsole.
GUI- Windows , WriteConsole printf . . , , 6.
/, , (, ) . , , , , , . , , .
, Windows , UNIX, UNIX, . [40] UNIX / ( 11), ( 19).
, Windows , . GUI , , , GUI-.
:
ConsolePrompt, 2.1, , . - , . / . Print-Strings PrintMsg; , . , , . PrintStrings va_start, va_arg va_end .
, .
, Web- , , , Windows.
|
|
, Envirmnt.h ( Web- ), . UNICODE _UNICODE ( ""; , Unicode, ), , . , Web-, , , .
2.1. PrintMsg:
/* PrintMsg.: ConsolePrompt, PrintStrings, PrintMsg */
#include "Envirmnt.h" /* #define #undef UNICODE. */
#include <windows.h>
#include <stdarg.h>
BOOL PrintStrings (HANDLE hOut,...)
/* . */
{
DWORD MsgLen, Count;
LPCTSTR pMsg;
va_list pMsgList; /* . */
va_start (pMsgList, hOut); /* . */
while ((pMsg = va_arg(pMsgList, LPCTSTR))!= NULL) {
MsgLen = _tcslen(pMsg);
/* WriteConsole . */
if (!WriteConsole(hOut, pMsg, MsgLen, &Count, NULL)
/* WriteFile WriteConsole. */
&&!WriteFile(hOut, pMsg, MsgLen * sizeof (TCHAR), &Count, NULL)) return FALSE;
}
va_end(pMsgList);
return TRUE;
}
BOOL PrintMsg(HANDLE hOut, LPCTSTR pMsg)
/* PrintStrings . */
{
return PrintStrings(hOut, pMsg, NULL);
}
BOOL ConsolePrompt(LPCTSTR pPromptMsg, LPTSTR pResponse, DWORD MaxTchar, BOOL Echo)
/* . */
{
HANDLE hStdIn, hStdOut;
DWORD TcharIn, EchoFlag;
BOOL Success;
hStdIn = CreateFile(_T("CONIN$"), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
hStdOut = CreateFile(_T("CONOUT$"), GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
EchoFlag = Echo? ENABLE_ECHO_INPUT: 0;
Success = SetConsoleMode(hStdIn, ENABLE_LINE_INPUT | EchoFlag | ENABLE_PROCESSED_INPUT) &&
SetConsoleMode (hStdOut, ENABLE_WRAP_AT_EOL_OUTPUT | ENABLE_PROCESSED_OUTPUT) &&
PrintStrings (hStdOut, pPromptMsg, NULL) &&
ReadConsole (hStdIn, pResponse, MaxTchar, &TcharIn, NULL);
if (Success) pResponse [TcharIn 2] = '\0';
CloseHandle (hStdIn);
CloseHandle (hStdOut);
return Success;
}
, Success, , , , , ANSI "" ; , , "" (&&), FALSE, , , , . , , , . GetLastError. Windows .
|
|
; , , .
, WriteConsole , , . . , .
, ReadConsole , .
:
1.2 , , DWORD GetLastError. , , UNIX errno, ( 7), .
FormatMessage , , .
2.2 ReportError, perror, [40] err_sys err_ret. ReportError , , , , . , .
FormatMessage. , GetLastError, a . , , . , . , . Format-Message , .
ReportError , . 4 .
2.2 EvryThng.h. , <windows.h>, Envirmnt.h , 2.1. , , PrintMsg, PrintStrings ReportError. , .
HeapFree, . 5.