阅读:5422回复:3
DeviceIoControl的异步问题
MSDN上讲DeviceIoControl时, 如果目标设备是用FILE_FLAG_OVERLAPPED标记打开, DeviceIoControl时必须指定一个有效的OVERLAPPED,
搞笑的是我指定一个OVERLAPPED时老返回false, GetLastError是ERROR_IO_PENDDING, 然后我Wait这个OVERLAPPED里的event对象时一直不返回, 如果直接给一个NULL而不指定OVERLAPPED反而能正确返回, 见鬼, MSDN不是说不指定就会fail吗? 原话如下, 请指点一下 If hDevice was opened with the FILE_FLAG_OVERLAPPED flag, this parameter must point to a valid OVERLAPPED structure. In this case, DeviceIoControl is performed as an overlapped (asynchronous) operation. If the device was opened with FILE_FLAG_OVERLAPPED and lpOverlapped is NULL, the function fails in unpredictable ways. |
|
最新喜欢:![]()
|
沙发#
发布于:2004-05-09 16:50
返回PENDING说明驱动没有处理完请求,你等待event是对的,但你的event是否正确呢?
|
|
|
板凳#
发布于:2004-05-10 08:50
OVERLAPPED结构里的event,
OVERLAPPED ol; ... ol.hEvent = myEvent; //myEvent是手动event, 全局变量 //专门用于这个DeviceIoControl, 别的地方不会用到 ResetEvent(myEvent); BOOL bRet = DeviceIoControl(...., &ol); .... WaitForSingleObject(myEvent, INFINITE); //永远死在这里 .. 上面的代码有问题?? |
|
|
地板#
发布于:2004-05-14 17:23
你把你的ol首先全部置零
memset( &ol, 0, sizeof( OVERLAPPED ) 然后在ol.hEvent = myEvent; 呵呵,给分吧。 |
|