#include #include #include #include #include #include "gpioctl.h" // This defines the IOCTL constants. int main(int argc, char *argv[]) { // The following is returned by IOCTL. It is true if the write succeeds. BOOL IoctlResult; // The following parameters are used in the IOCTL call HANDLE hndFile; // Handle to device, obtain from CreateFile GENPORT_WRITE_INPUT InputBuffer; // Input buffer for DeviceIoControl LONG IoctlCode; ULONG DataValue; ULONG DataLength; ULONG ReturnedLength; // Number of bytes returned in output buffer hndFile = CreateFile( "\\\\.\\GpdDev", // Open the Device "file" GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); sscanf(argv[1],"%x",&DataValue); IoctlCode = IOCTL_GPD_WRITE_PORT_UCHAR; InputBuffer.CharData = (UCHAR)DataValue; DataLength = offsetof(GENPORT_WRITE_INPUT, CharData) + sizeof(InputBuffer.CharData); InputBuffer.PortNumber=2; IoctlResult = DeviceIoControl( hndFile, // Handle to device IoctlCode, // IO Control code for Write &InputBuffer, // Buffer to driver. Holds port & data. DataLength, // Length of buffer in bytes. NULL, // Buffer from driver. Not used. 0, // Length of buffer in bytes. &ReturnedLength, // Bytes placed in outbuf. Should be 0. NULL // NULL means wait till I/O completes. ); if (IoctlResult) // Did the IOCTL succeed? { return (0); } else { printf( "Ioctl failed with code %ld\n", GetLastError() ); } if (!CloseHandle(hndFile)) // Close the Device "file". { printf("Failed to close device.\n"); } }