Asynchronous Operations and VxDs

You can direct a VxD to process a control code asynchronously. In an asynchronous operation, the DeviceIoControl function returns immediately, regardless of whether the VxD has finished processing the control code. Asynchronous operation allows an application to continue while the VxD processes the control code in the background. You request an asynchronous operation by specifying the address of an OVERLAPPED structure in the DeviceIoControl function. The hDevice member of OVERLAPPED specifies the handle of an event that the system sets to the signaled state when the VxD has completed the operation.

Asynchronous (overlapped) operations are useful for lengthy operations, such as formatting a disk. To perform an asynchronous operation, you must specify the FILE_FLAG_OVERLAPPED value when calling CreateFile to obtain a device handle. When calling DeviceIoControl, you must specify the address of an OVERLAPPED structure in the lpOverlapped parameter and the handle of a manual reset event in the hEvent member of the structure. The system ignores all other members.

If DeviceIoControl completes the operation before returning, it returns TRUE; otherwise, it returns FALSE. When the operation is finished, the system signals the manual reset event. You should call GetOverlappedResult when the thread that called DeviceIoControl needs to wait (that is, stop executing) until the operation has finished.