// This is a somewhat reduced version of the test2.c program found at: // http://www.hytherion.com/beattidp/comput/pport.htm #include #include #include /* prototype (function typedef) for DLL function Inp32: */ typedef short (_stdcall *inpfuncPtr)(short portaddr); typedef void (_stdcall *oupfuncPtr)(short portaddr, short datum); #define PPORT_BASE 0xD010 /* After successful initialization, these 2 variables will contain function pointers. */ inpfuncPtr inp32fp; oupfuncPtr oup32fp; // Wrapper functions for the function pointers short Inp32 (short portaddr) { return (inp32fp)(portaddr); } void Out32 (short portaddr, short datum) { (oup32fp)(portaddr,datum); } int main(void) { HINSTANCE hLib; short x=0xAA; /* Load the library */ hLib = LoadLibrary("inpout32.dll"); if (hLib == NULL) { fprintf(stderr,"LoadLibrary Failed.\n"); return -1; } /* get the address of the function */ inp32fp = (inpfuncPtr) GetProcAddress(hLib, "Inp32"); if (inp32fp == NULL) { fprintf(stderr,"GetProcAddress for Inp32 Failed.\n"); return -1; } oup32fp = (oupfuncPtr) GetProcAddress(hLib, "Out32"); if (oup32fp == NULL) { fprintf(stderr,"GetProcAddress for Oup32 Failed.\n"); return -1; } // INITIALIZATION COMPLETE Out32(PPORT_BASE,x); /* finished - unload library and exit */ FreeLibrary(hLib); return 0; }