DeviceIoControl

DeviceIoControl sends a control code directly to a specified file system driver, causing the corresponding device to perform the specified operation.

Syntax

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

Parameters

hDevice

A handle to the device that is to perform the operation. Call CreateFile to obtain a device handle.

IoControlCode

The control code for the operation. This value identifies the specific operation to be performed and the type of device on which the operation is to be performed. The following values are defined:

Value Definition

IOCTL_DISK_CHECK_VERIFY

Obsolete. Use IOCTL_STORAGE_CHECK_VERIFY

IOCTL_DISK_EJECT_MEDIA

Obsolete. Use IOCTL_STORAGE_EJECT_MEDIA

IOCTL_DISK_FORMAT_TRACKS

Formats a contiguous set of disk tracks.

IOCTL_DISK_GET_DRIVE_GEOMETRY

Obtains information on the physical disk's geometry.

IOCTL_DISK_GET_DRIVE_LAYOUT

Provides information about each partition on a disk.

IOCTL_DISK_GET_MEDIA_TYPES

Obsolete. Use IOCTL_STORAGE_GET_MEDIA_TYPES

IOCTL_DISK_GET_PARTITION_INFO

Obtains disk partition information.

IOCTL_DISK_LOAD_MEDIA

Obsolete. Use IOCTL_STORAGE_LOAD_MEDIA

IOCTL_DISK_MEDIA_REMOVAL

Obsolete. Use IOCTL_STORAGE_MEDIA_REMOVAL

IOCTL_DISK_PERFORMANCE

Provides disk performance information.

IOCTL_DISK_REASSIGN_BLOCKS

Maps disk blocks to spare-block pool.

IOCTL_DISK_SET_DRIVE_LAYOUT

Partitions a disk.

IOCTL_DISK_SET_PARTITION_INFO

Sets the disk partition type.

IOCTL_DISK_VERIFY

Performs logical format of a disk extent.

IOCTL_SERIAL_LSRMST_INSERT

Enables or disables placement of a line and modem status data into the data stream.

IOCTL_DISK_STORAGE_CHECK_VERIFY

Checks for change in a removable-media device.

IOCTL_DISK_STORAGE_EJECT_MEDIA

Ejects media from a SCSI device.

IOCTL_DISK_STORAGE_GET_MEDIA_TYPES

Obtains information about media support.

IOCTL_DISK_STORAGE_LOAD_MEDIA

Loads media into a device.

IOCTL_DISK_STORAGE_MEDIA_REMOVAL

Enables or disables the media eject mechanism.

For more detailed information on each control code, see its topic in the Microsoft documentation. In particular, each topic provides details on the usage of the lpInBuffer, nInBufferSize, lpOutBuffer, nOutBufferSize, and lpBytesReturned parameters.

lpInBuffer

A pointer to a buffer that contains the data required to perform the operation.

This parameter can be NULL if the IoControlCode parameter specifies an operation that does not require input data.

nInBufferSize

The size, in bytes, of the buffer pointed to by lpInBuffer.

lpOutBuffer

A pointer to a buffer that receives the operation's output data.

This parameter can be NULL if the IoControlCode parameter specifies an operation that does not produce output data.

nOutBufferSize

The size, in bytes, of the buffer pointed to by lpOutBuffer.

lpBytesReturned

A pointer to a variable that receives the size, in bytes, of the data stored into the buffer pointed to by lpOutBuffer.

lpOverlapped

Ignored. This parameter should be set to NULL.

Return Value

TRUE if the function succeeds, FALSE if the function fails

To get extended error information, call GetLastError.

Requirements

Minimum Supported Version RTX64 2013
Header windows.h
Library Rtx_Rtss.lib

See Also:

CreateFile