阅读:2075回复:3
关于并口(有源码)!
斗胆请教各位,我用VTOOLSD做了一个监控并口的程序,目的为了拿到应用程序向并口发送数据,但我用下面的程序反复测试,结果共测试了3台电脑,而只有1台机在DOS状态下发送的并口数据能被handler函数检测到,我使用DEBUGVIEW调试的。好迷惘,请各位指教
程序代码如下: 头文件: #include #define DEVICE_CLASS PortDevice #define PORT_DeviceID UNDEFINED_DEVICE_ID #define PORT_Init_Order UNDEFINED_INIT_ORDER #define PORT_Major 1 #define PORT_Minor 0 //#define DIOC_MY_IO CTL_CODE(FILE_DEVICE_UNKNOWN,1,METHOD_NEITHER,FILE_ANY_ACCESS) //struct PortStruct{WORD wPort;WORD wVal;BOOL bInput;}; class MyPort: public VIOPort { public: MyPort():VIOPort(0x378){}; virtual DWORD handler(VMHANDLE hVM,DWORD port, CLIENT_STRUCT *pRegs, DWORD iotype, DWORD outdata); DWORD Count; BYTE *buffer; }; class PortDevice : public VDevice { public: virtual BOOL OnSysDynamicDeviceInit(); virtual BOOL OnSysDynamicDeviceExit(); virtual DWORD OnW32DeviceIoControl(PIOCTLPARAMS pDIOCParams); }; cpp文件: #define DEVICE_MAIN #include "port.h" Declare_Virtual_Device(PORT) #undef DEVICE_MAIN MyPort *pio; BOOL PortDevice::OnSysDynamicDeviceInit() { pio=new MyPort(); if(pio) { dout<<"hook failed pio"< if(pio->hook()) { dout<<"hook success"< pio->Count=0; pio->buffer=new BYTE[65535]; } else { dout<<"hook failed liyu"< // return FALSE; } } else return FALSE; return TRUE; } BOOL PortDevice::OnSysDynamicDeviceExit() { if(pio) { if(pio->unhook()) { dout<<"unhook success"< delete pio->buffer; } delete pio; } return TRUE; } DWORD PortDevice::OnW32DeviceIoControl(PIOCTLPARAMS pDIOCParams) { switch(pDIOCParams->dioc_IOCtlCode) { case DIOC_OPEN: dout<<"DIOC_OPEN"< break; case DIOC_CLOSEHANDLE: dout<<"DIOC_close"< break; case 112: dout<<"HELLO LIUTAO"< pio->globalEnable(); break; case 111: dout<<"liutao"< int size=pDIOCParams->dioc_cbOutBuf; size=pio->CountCount:size; memcpy(pDIOCParams->dioc_OutBuf,pio->buffer,size*sizeof(BYTE)); *pDIOCParams->dioc_bytesret=size; break; } return 0; } DWORD MyPort::handler(VMHANDLE hVM,DWORD port,CLIENT_STRUCT *pRegs,DWORD iotype,DWORD outdata) { char data; dout<<"byte output"< switch(iotype) { case BYTE_OUTPUT: data=_outp(port,outdata); if(data>31&data<123) { buffer[Count]=outdata; if(++Count>=65535) Count=65535; } dout<<"byte output"< return data; case STRING_IO: dout<<"STRING_IO"< return 0; } return 0; } |
|
最新喜欢:stoney... |
沙发#
发布于:2001-08-17 08:52
请不要发重帖!!已经三帖了按本站规定是要封帐号的.请自己删除剩下的两帖!
|
|
|
板凳#
发布于:2001-08-18 02:46
你试试在DIOC_OPEN的时候 new MyPort();
看看行不行 |
|
|
地板#
发布于:2004-05-15 12:53
你的中断函数中最后要清空中断
|
|