File: wintest.cpp

package info (click to toggle)
norm 1.5.9%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 9,680 kB
  • sloc: cpp: 123,494; xml: 7,536; tcl: 5,460; makefile: 3,442; python: 1,898; java: 1,750; ansic: 642; sh: 21; csh: 8
file content (57 lines) | stat: -rw-r--r-- 1,109 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
 

#include "win32InputHandler.cpp"  // for class Win32InputHandler

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>

#define BUFSIZE 4096

int main(int argc, char** argv)
{
	HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);

	if (argc > 1)
	{
		// Generate random output
		const char* text = "This is some text to output\n";
		int textlen = strlen(text);

		while (true)
		{
			int count = rand() % 100;
		    while (count > 0)
			{
				printf(text);
				DWORD dwWritten;
				BOOL fSuccess = WriteFile(hStdout, text, textlen, &dwWritten, NULL);
				count -= textlen;
			}

			int delay = (rand() % 1000);
			Sleep(1000);

		}

		return 0;
	}

	Win32InputHandler inputHandler;

	inputHandler.Open();

	while (true)
	{
		char buffer[BUFSIZE];
		WaitForSingleObject(inputHandler.GetEventHandle(), INFINITE);
		int numBytes = inputHandler.ReadData(buffer, 1024);
		if (numBytes < 0) break;

		DWORD dwWritten;
		BOOL fSuccess = WriteFile(hStdout, buffer, numBytes, &dwWritten, NULL);
	}
	inputHandler.Close();

    return 0;
}  //  end main()