Is the example on my download site not enough - I guess not for C++
Anyway its relatively easy
I recommend that your don't statically link the dll (i.e. at compile time) but rather use runtime linking as that's the most flexible, you can swap out for different versions so long as the C interface does not change (and that's not likely).
You don't need to worry about the .sys that is installed automatically when you load the DLL, however it does men that the first time you load the DLL you have to be running with elevated permissions (so run it from an installer, or use the InstallDriver.exe supplied.
Make sure your using the latest version from my website
as the x64 compatible links on http://www.logix4u.net
(the original author) are out of date and do not work.
If you are writing a 32bit app, you must use the InpOut32.dll (even on x64 windows).
If your writing a 64bit (x64) C++ application use InpOutx64.dll.
Then put the DLL in the same folder as your compiled exe (or anywhere in the system path) and use something like the following (really basic 32bit) code (that I just wrote):
Code: Select all
// InpoutTest.cpp : Defines the entry point for the console application.
typedef void (__stdcall *lpOut32)(short, short);
typedef short (__stdcall *lpInp32)(short);
typedef BOOL (__stdcall *lpIsInpOutDriverOpen)(void);
typedef BOOL (__stdcall *lpIsXP64Bit)(void);
//Some global function pointers (messy but fine for an example)
void Beep(unsigned int freq)
gfpOut32(0x42, (freq & 0xFF));
gfpOut32(0x42, (freq >> 9));
gfpOut32(0x61, gfpInp32(0x61) | 0x03);
gfpOut32(0x61, (gfpInp32(0x61) & 0xFC));
int main(int argc, char* argv)
//too few command line arguments, show usage
printf("Error : too few arguments\n\n***** Usage *****\n\nInpoutTest read <ADDRESS> \nor \nInpoutTest write <ADDRESS> <DATA>\n\n\n\n\n");
//Dynamically load the DLL at runtime (not linked at compile time)
HINSTANCE hInpOutDll ;
hInpOutDll = LoadLibrary ( "InpOut32.DLL" ) ; //The 32bit DLL. If we are building x64 C++
//applicaiton then use InpOutx64.dll
if ( hInpOutDll != NULL )
gfpOut32 = (lpOut32)GetProcAddress(hInpOutDll, "Out32");
gfpInp32 = (lpInp32)GetProcAddress(hInpOutDll, "Inp32");
gfpIsInpOutDriverOpen = (lpIsInpOutDriverOpen)GetProcAddress(hInpOutDll, "IsInpOutDriverOpen");
gfpIsXP64Bit = (lpIsXP64Bit)GetProcAddress(hInpOutDll, "IsXP64Bit");
//Make some noise through the PC Speaker - hey it can do more that a single beep using InpOut32
short iPort = atoi(argv);
WORD wData = gfpInp32(iPort); //Read the port
printf("Data read from address %s is %d \n\n\n\n", argv, wData);
printf("Error in arguments supplied");
printf("\n***** Usage *****\n\nInpoutTest read <ADDRESS> \nor \nInpoutTest write <ADDRESS> <DATA>\n\n\n\n\n");
short iPort = atoi(argv);
WORD wData = atoi(argv);
printf("data written to %s\n\n\n", argv);
printf("Unable to open InpOut32 Driver!\n");
FreeLibrary ( hInpOutDll ) ;
printf("Unable to load InpOut32 DLL!\n");