#include #include #include /* Definitions in the build of inpout32.dll are: */ /* short _stdcall Inp32(short PortAddress); */ /* void _stdcall Out32(short PortAddress, short data); */ /* prototype (function typedef) for DLL function Inp32: */ typedef short _stdcall (*inpfuncPtr)(short portaddr); typedef void _stdcall (*oupfuncPtr)(short portaddr, short datum); int main(void) { HINSTANCE hLib; inpfuncPtr inp32; oupfuncPtr oup32; short x; int i; /* Chargement de la librairie*/ hLib = LoadLibrary("inpout32.dll"); if (hLib == NULL) { printf("LoadLibrary Failed.\n"); return -1; } /* Récupération de l'adresse de la fonction avec "GetProcAddress" */ inp32 = (inpfuncPtr) GetProcAddress(hLib, "Inp32"); /* Vérification que la fonction existe */ if (inp32 == NULL) { printf("GetProcAddress for Inp32 Failed.\n"); return -1; } /* Récupération de l'adresse de la fonction avec "GetProcAddress" */ oup32 = (oupfuncPtr) GetProcAddress(hLib, "Out32"); /* Vérification que la fonction existe */ if (oup32 == NULL) { printf("GetProcAddress for Oup32 Failed.\n"); return -1; } //initialisation du port, (oup32)(0x378 + 2, 0x00); //allumer ma LED (oup32)(0x378, 1 << 3); //etteindre ma led //(oup32)(0x378, 0 << 3); /***************************************************************/ /* now test the functions */ /* Try to read 0x378..0x37F, LPT1: */ for (i=0x378; (i<0x380); i++) { x = (inp32)(i); printf("port read (%04X)= %04X\n",i,x); } /***** Write the data register */ i=0x378; x=0x77; (oup32)(i,x); printf("port write to 0x%X, datum=0x%2X\n" ,i ,x); /***** And read back to verify */ x = (inp32)(i); printf("port read (%04X)= %04X\n",i,x); /***** One more time, different value */ i=0x378; x=0x0; (oup32)(i,x); printf("port write to 0x%X, datum=0x%2X\n" ,i ,x); /***** And read back to verify */ x = (inp32)(i); printf("port read (%04X)= %04X\n",i,x); FreeLibrary(hLib); return 0; }