Device Input and Output Control (IOCTL)
Windows中的DeviceIoControl 函数提供了一个设备输入和输出控制(IOCTL)接口,应用程序可通过该接口与设备驱动程序直接通信。DeviceIoControl 函数是一个通用接口,可以向各种设备发送控制代码。每个控制代码都代表驱动程序要执行的操作。例如,控制代码可以要求设备驱动程序返回相应设备的信息,或指示驱动程序在设备上执行一项操作,如格式化磁盘。
The DeviceIoControl function provides a device input and output control (IOCTL) interface through which an application can communicate directly with a device driver. The DeviceIoControl function is a general-purpose interface that can send control codes to a variety of devices. Each control code represents an operation for the driver to perform. For example, a control code can ask a device driver to return information about the corresponding device, or direct the driver to carry out an action on the device, such as formatting a disk.
直接向指定设备驱动程序发送控制代码,使相应设备执行相应操作。
Sends a control code directly to a specified device driver, causing the corresponding device to perform the corresponding operation.
SDK 头文件中定义了许多标准控制代码。此外,设备驱动程序还可以定义自己的特定设备控制代码。有关 SDK 文档中包含的标准控制代码列表,请参阅 DeviceIoControl 的备注部分。
A number of standard control codes are defined in the SDK header files. In addition, device drivers can define their own device-specific control codes. For a list of standard control codes included in the SDK documentation, see the Remarks section of DeviceIoControl.
可以指定的控制代码类型取决于访问的设备和运行应用程序的平台。应用程序可以使用标准控制代码或特定设备控制代码,在软盘驱动器、硬盘驱动器、磁带驱动器或 CD-ROM 驱动器上执行直接输入和输出操作。
The types of control codes you can specify depend on the device being accessed and the platform on which your application is running. Applications can use the standard control codes or device-specific control codes to perform direct input and output operations on a floppy disk drive, hard disk drive, tape drive, or CD-ROM drive.
Calling DeviceIoControl (调用)
下面的示例演示了如何检索系统中第一个物理驱动器的信息。该示例使用 CreateFile 函数检索第一个物理驱动器的设备句柄,然后使用带有 IOCTL_DISK_GET_DRIVE_GEOMETRY 控制代码的 DeviceIoControl 将驱动器的信息填充到 DISK_GEOMETRY 结构中。
The following example demonstrates how to retrieve information about the first physical drive in the system. It uses the CreateFile function to retrieve the device handle to the first physical drive, and then uses DeviceIoControl with the IOCTL_DISK_GET_DRIVE_GEOMETRY control code to fill a DISK_GEOMETRY structure with information about the drive.
C++ Syntax
BOOL DeviceIoC

最低0.47元/天 解锁文章
8869

被折叠的 条评论
为什么被折叠?



