home *** CD-ROM | disk | FTP | other *** search
-
- #include <windows.h>
-
- #define MAXBUF 4096
-
- DWORD ConsPuts(char *pszString);
- DWORD ConsGets(char *pszString, DWORD nLen);
-
-
- //
- // ConsPuts:
- // Print a string to StdOut on the console
- //
- DWORD ConsPuts(char *pszString)
- {
- DWORD nLen = strlen(pszString);
- DWORD nWritten;
- HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
- BOOL bRet;
-
- bRet = WriteConsole(hOutput, pszString, nLen, &nWritten, NULL);
- return (!bRet || (nWritten != nLen)) ? 0 : nLen;
- }
-
-
-
- //
- // ConsGets:
- // Get a string to StdIn on the console
- //
- DWORD ConsGets(char *pszString, DWORD nLen)
- {
- DWORD nRead;
- HANDLE hInput = GetStdHandle(STD_INPUT_HANDLE);
- BOOL bRet;
-
- bRet = ReadConsole(hInput, pszString, nLen, &nRead, NULL);
- return (!bRet) ? 0 : nLen;
- }
-
-
-
- int main(int argc, char *argv[])
- {
- char szBuffer[MAXBUF];
- DWORD nRead;
-
- ConsPuts("Welcome to the your second console program.\r\n");
- nRead = ConsGets(szBuffer, MAXBUF);
- szBuffer[nRead] = '\0';
- ConsPuts(szBuffer);
- return 0;
- }
-
-
-
-