DeviceIoControl

  BOOL DeviceIoControl(hDevice, dwIoControlCode, lpInBuffer, nInBufferSize, lpOutBuffer, nOutBufferSize, lpBytesReturned, lpOverlapped)    
  HANDLE hDevice;    
  DWORD dwIoControlCode;    
  LPVOID lpInBuffer;    
  DWORD nInBufferSize;    
  LPVOID lpOutBuffer;    
  DWORD nOutBufferSize;    
  LPDWORD lpBytesReturned;    
  LPOVERLAPPED lpOverlapped;    

The DeviceIoControl function allows an application to call a device driver directly. The application must have an open handle to the device.

Parameters

hDevice

Specifies an open handle for the device to be called.

dwIoControlCode

Specifies the control code for the operation. This control code determines on which type of device the operation must be performed and determines exactly what operation is to be performed.

lpInBuffer

Points to a buffer that contains the data required to perform the operation. This parameter may be NULL if dwIoControlCode specifies an operation that does not require input data.

nInBufferSize

Specifies the length of the input buffer in bytes.

lpOutBuffer

Points to a buffer that receives output data from the operation. This parameter may be NULL if dwIoControlCode specifies an operation that does not produce output data.

nOutBufferSize

Specifies the length of the output buffer in bytes.

lpBytesReturned

Points to a variable that receives the actual length of the data returned in the output buffer.

lpOverlapped

Points to an OVERLAPPED structure to be used with the operation. To use this parameter, hDevice must have been opened with the FILE_FLAG_OVERLAPPED flag. This parameter may be NULL if overlapped I/O is not requested.

Return Value

The return value is TRUE if the function was successful, or FALSE if an error occurred. Use the GetLastError function to obtain extended error information.

Comments

If lpOverlapped is NULL or hDevice was opened without FILE_FLAG_OVERLAPPED then this function will not return until the operation completes.

When lpOverlapped points to an OVERLAPPED structure and FILE_FLAG_OVERLAPPED was specified when the handle was created, this function may return before the operation completes (this function returns FALSE and GetLastError returns ERROR_IO_PENDING).

This allows the caller to continue processing while the operation completes. The event specified in the OVERLAPPED structure is set to the not-signalled state before the function returns. When the operation completes, the event is set to the signalled state. The GetOverlappedResult function can be used to determine the result when ERROR_IO_PENDING is returned.