Created
August 14, 2012 17:20
-
-
Save skhaz/3350974 to your computer and use it in GitHub Desktop.
A tribute to XKCD: the light comes on when I compile!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Based on this picture | |
* http://imgur.com/ZZxFy | |
*/ | |
#include <cstdio> | |
#include <stdio.h> | |
#include <windows.h> | |
#include <tlhelp32.h> | |
int main(int, char **) | |
{ | |
HANDLE device; | |
if ((device = CreateFile("LPT1", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) { | |
printf("Port couldn't be opend: %li\n", GetLastError()); | |
return -1; | |
} | |
PROCESSENTRY32 entry; | |
entry.dwSize = sizeof(PROCESSENTRY32); | |
const char* processName = "make"; | |
for (;;) { | |
unsigned char data = 0x00; | |
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL); | |
if (Process32First(snapshot, &entry)) { | |
while (Process32Next(snapshot, &entry)) { | |
if (stricmp(entry.szExeFile, processName) == 0) { | |
data = ~data; | |
break; | |
} | |
} | |
} | |
WriteFile(device, &data, sizeof(data), NULL, NULL); | |
CloseHandle(snapshot); | |
Sleep(500); | |
} | |
CloseHandle(device); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment