der source ist aus dem Platform DDK von MS.
der source würde dir nicht viel nutzen da dir die ganzen header fehlen.
so spricht man ihn dann an
Code:void CReadWritePort::WriteByte(BYTE PortNumber,BYTE Data) { GENPORT_WRITE_INPUT InputBuffer; hndFile = CreateFile( "\\\\.\\GpdDev", // Open the Device "file" GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL ); if (hndFile == INVALID_HANDLE_VALUE) // Was the device opened? { MessageBox(NULL,"Unable to open the device.","PortIO",MB_OK); return; } IoctlCode = IOCTL_GPD_WRITE_PORT_UCHAR; InputBuffer.CharData = Data; DataLength = offsetof(GENPORT_WRITE_INPUT, CharData) + sizeof(InputBuffer.CharData); //sscanf("200", "%x", &PortNumber); //PortNumber = 0x3BC; InputBuffer.PortNumber = PortNumber; 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? { ATLTRACE("Wrote data %x to port %x\n", InputBuffer.CharData,InputBuffer.PortNumber); CString Dummy; Dummy.Format("%x",InputBuffer.CharData); if(PortNumber == 0) { SetDlgItemText(m_hMainDlg,IDC_DATEN_EDIT,Dummy); } if(PortNumber == 2) { SetDlgItemText(m_hMainDlg,IDC_STEUEROUT_EDIT,Dummy); } } else { ATLTRACE("Ioctl failed with code %ld\n", GetLastError() ); CString csMsg; csMsg.Format("Ioctl failed with code %ld",GetLastError()); MessageBox(NULL,csMsg,"PortIO",MB_OK); } if (!CloseHandle(hndFile)) // Close the Device "file". { ATLTRACE("Failed to close device.\n"); MessageBox(NULL,"Failed to close device","PortIO",MB_OK); } }







Zitieren

Lesezeichen