// // Ioctl.cpp // // RomaNets Software, 2005 // // Uses: WinNT driver MyExample.sys // Source: D:\_RNH\_DEV\IBMPC\_DRIVERS\RoPortsDrv\install\MyExample.inf // // Write to LPT1 port 0x0378 // Read from LPT1 port 0x0379 // #include "stdafx.h" #include #include "Ioctl.h" /////////////////////////////////////////////////////////////////////////////// int write_driver( UCHAR myByte) /////////////////////////////////////////////////////////////////////////////// { HANDLE hHandle = // Получаем доступ к драйверу CreateFile( "\\\\.\\MyExample", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ); if(hHandle==INVALID_HANDLE_VALUE) { //printf("ERR: can not access driver Example.sys !\n"); return (-1); } DWORD BytesReturned; unsigned long ioctlCode; ioctlCode=IOCTL_TOUCH_PORT_378H; UCHAR InputBuffer = myByte; //0xF; ULONG DataLength = 1; if( !DeviceIoControl( hHandle, ioctlCode, //NULL, 0, // Input &InputBuffer, DataLength, NULL, 0, // Output &BytesReturned, NULL ) ) { //printf( "Error in IOCTL_TOUCH_PORT_378H!" ); return(-1); } CloseHandle(hHandle); return 0; } /////////////////////////////////////////////////////////////////////////////// UCHAR read_driver() /////////////////////////////////////////////////////////////////////////////// { HANDLE hHandle = // Получаем доступ к драйверу CreateFile( "\\\\.\\MyExample", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ); if(hHandle==INVALID_HANDLE_VALUE) { //printf("ERR: can not access driver Example.sys !\n"); return (-1); } DWORD BytesReturned; unsigned long ioctlCode; UCHAR myByte = 0x00; ioctlCode=IOCTL_SEND_BYTE_TO_USER; if( !DeviceIoControl( hHandle, ioctlCode, NULL, 0, // Input &myByte, sizeof(myByte),// Output &BytesReturned, NULL ) ) { //printf( "Error in IOCTL_SEND_BYTE_TO_USER!" ); return(-1); } CloseHandle(hHandle); return myByte; }