/* DAn Williams Aug 14 2004 Demo of parallel port access and controll. uses inpout.dll Enjoy. */ #include <conio.h> #include <stdio.h> #include <windows.h>
/* 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);
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 **************************/
// Write to the data register value = 0x55; 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);
// Now use a different value value = 0xAA; 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; }
|