Tech Support > Microsoft Windows > Development Resources > ReadFile Usage
ReadFile Usage
Posted by abc.bhaskar@gmail.com on September 24th, 2007


Dear All,

I implemented sample asynchronous ReadFile.

gOverlapped.Offset = 0;
gOverlapped.OffsetHigh = 0;
gOverlapped.hEvent = hReadEvent; //created event

/* open the device */
/* Attempt an asynchronous read operation */
bResult = ReadFile(hFile, pinBuf, 21, (PULONG)&nBytesRead,
&gOverlapped);

/* close the opened handles */

The program gets executed as expected but only on first attempt. From
the second time onwards, the application hangs after the ReadFile
call. Even ctrl + C does not break it. I have to manually close the
application. By this its not getting killed and the name appears in
the taskbar.

Can anyone guide to the right pointer about the hanging of the
application from the second time.

Regards.

Posted by abc.bhaskar@gmail.com on September 24th, 2007


I have kept a breakpoint at the last return 0 statement of the main
program and the control is coming to it and the program gets
terminated normally. The problem is when I directly run using ctrl +
F5


On Sep 24, 4:09 am, abc.bhas...@gmail.com wrote:


Posted by Jeffrey Adler on September 25th, 2007



<abc.bhaskar@gmail.com> wrote in message
news:1190640135.585184.295740@o80g2000hse.googlegr oups.com...
I'm not completely sure that this will fix your entire problem, BUT...

After the ReadFile w/overlapped I/O, you need to wait until the overlapped
operation completes, i.e.

ReadFile (....);
WaitForSingleObject (gOverlapped.hEvent, INFINITE);

before closing the open file.

HTH.




Similar Posts