Skip to content

Instantly share code, notes, and snippets.

@skhaz
Created August 14, 2012 17:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skhaz/3350974 to your computer and use it in GitHub Desktop.
Save skhaz/3350974 to your computer and use it in GitHub Desktop.
A tribute to XKCD: the light comes on when I compile!
/*
* 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