The DeviceIoControl function sends a control code directly to a specified device driver, causing the corresponding driver to perform the associated operation.
Handle to the device on which the operation will be performed. Obtained by calling CreateFile.
dwIoControlCode
Control code of the operation to perform. Defined in the driver-specific header files.
lpInBuffer
Pointer to the input buffer that contains the data required to perform the operation. Can be NULL if not needed.
nInBufferSize
Size of the input buffer, in bytes.
lpOutBuffer
Pointer to the output buffer that receives the data returned by the device. Can be NULL if not needed.
nOutBufferSize
Size of the output buffer, in bytes.
lpBytesReturned
Pointer to a variable that receives the size of the data stored in the output buffer.
lpOverlapped
Pointer to an OVERLAPPED structure for asynchronous operations. Can be NULL for synchronous calls.
Return value
Returns TRUE if the operation succeeds; otherwise FALSE. For extended error information, call GetLastError.
Remarks
DeviceIoControl is the primary way applications communicate with drivers. The control code defines the request and the expected input/output buffers. Drivers must validate all buffers and return appropriate status codes.
When performing I/O with removable media, ensure the device handle was opened with the FILE_FLAG_OVERLAPPED flag for asynchronous operations.