#include #include #include #include /* definitions on what port is what base address depends, so use this */ #define LPT1 0x378 #define LPT2 0x278 #define LPT3 0x3BC /* register offsets */ #define DATA 0 #define STATUS 1 #define CONTROLL 2 #define BASE_ADDRESS LPT1 /* this is the address we use (modify here if you need to) */ typedef short _stdcall (*INP32)(short PortAddress); typedef void _stdcall (*OUT32)(short PortAddress, short Data); using namespace std; int main(void) { short value; HINSTANCE hLib; INP32 Inp32; OUT32 Out32; /******************** LIBRARY INIT ***********************/ if ((hLib = LoadLibrary("inpout32.dll")) == NULL) { printf("Unable to load inpout32.dll, did you copy it to the system folder?\n"); return 0; } if ((Inp32 = (INP32)GetProcAddress(hLib, "Inp32")) == NULL) { printf("Unable to establish handle to input function.\n"); return 0; } if ((Out32 = (OUT32)GetProcAddress(hLib, "Out32")) == NULL) { printf("Unable to establish handle to output function.\n"); return 0; } /*********************** MAIN CODE **************************/ //do while (tf != 3) { int tf; cout << "Please indicate to clear or activate the leds. 0 for clear, 1 for activate. 3 to exit.\n"; cin >> tf; if (tf = 0) { // Write to the data register printf("You typed 0"); value = 0x00; printf("Writing 0x%2X to port 0x%X...\n" ,value ,BASE_ADDRESS ); Out32( BASE_ADDRESS , value ); // Read it back value = Inp32(BASE_ADDRESS); printf("\n(Reading) Port %04X = %04X\n", BASE_ADDRESS, value); } if (tf = 1) { // Now use a different value printf("You hit 1"); value = 0xff; printf("\nWriting 0x%2X to port 0x%X...\n" ,value ,BASE_ADDRESS ); Out32(BASE_ADDRESS, value); // Read it back value = Inp32(BASE_ADDRESS); printf("\n(Reading) Port %04X = %04X\n\n", BASE_ADDRESS, value); } //} /******************** CLEANUP ******************************/ // GO FREEE LITTLE LIBRARIES!, GO FREEEEE!!! FreeLibrary(hLib); // were done. printf("Press any key to exit.\n"); getch(); return 1; }