Hi,
What happens if you perform a synchronous I/O operation on a handle opened for asynchronous operation? In particular, what should happen if the following code is executed?
Code:
...
path_io="P:\\oints_to\\a_usb\\dev.ice"
...
handle = CreateFile(path_io,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL|FILE_FLAG_OVERLAPPED,NULL);
...
if(!DeviceIoControl(handle,IOCTL_MCHPUSB_GET_DESCRIPTOR,&DscParam,sizeof(DscParam),pDevDsc,dwLen,pLength,NULL))
{
    printf("Get dsc error: %d",GetLastError());
    return MPUSB_FAIL;
}
...
CloseHandle(handle)
...
The things to note here are that handle is created with FILE_FLAG_OVERLAPPED, but then DeviceIoControl is called without passing an OVERLAPPED structure as the last parameter, signifying a synchronous operation.

At this point you might be wondering why on earth I would want to do that. Well, it's not my choice, it occurs inside a dll that I have to use (if I don't want to completely rewrite my code that is).

When I run this code, the DeviceIoControl function performs as required, despite the synchronisation issue. Yet, about half the time I get a blue screen error and have to reboot my computer before the program finishes. The details are:
Code:
0x000000CE
DRIVER_UNLOADED_WITHOUT_CANCELLING_PENDING_OPERATIONS
Can anyone explain what the code should do and whether it could even possibly be causing the blue screen of death?

My interpretation is that the DeviceIoControl function operates synchronously in this case and hence retrieves the required data immediately (explaining why the function still seems to work), but somehow the operation is still 'pending' because the handle is meant to operate asynchronously. This means that when CloseHandle is called, depending on how quick the in between code executes, the operation might still be pending. If it is, then the program would attempt to close a handle for which an async io is still pending. Could this possibly relate to the blue screen error?
One thing that supports my interpretation is that when I step through the program there is never a blue screen, only when I let it run freely do I get it.

Is my interpretation valid/possible/likely?? What do you think? What should happen if a synchronous operation is performed on an async handle? Anyone know?

Cheers,
Philipp