打开句柄
HANDLE hCom = CreateFile(m_strPath,GENERIC_READ|GENERIC_WRITE,
0,NULL,OPEN_EXISTING,FILE_FLAG_OVERLAPPED,NULL);
读设备
char InputReport[16];
memset(InputReport, 0, 16);
InputReport[0]=1;
DWORD BytesRead;
OVERLAPPED Overlapped;
HANDLE hEventObject= CreateEvent(NULL,TRUE,FALSE,NULL);
Overlapped.hEvent=hEventObject;
Overlapped.Offset=0;
Overlapped.OffsetHigh=0;
BOOL Result=ReadFile( hCom,InputReport,16,&BytesRead,&Overlapped );
if(!Result)
{
DWORD dw = GetLastError();
DWORD sucess=WaitForSingleObject(hEventObject,5000);
sucess返回ox102(超时)
在读设备之前或者之后加入Writefile都没有错误sucess均返回0x00000000(核心对象已被激活)
我用同步方式也读过,但是总是会一直阻塞在Result=ReadFile( hCom,InputReport,16,&BytesRead,NULL );不往下执行 |