本文转自http://blog.csdn.net/lujunql/archive/2008/06/10/2532362.aspxless
咱们在说DeviceIoControl函数时其第二个参数dwIoControlCode就是由CTL_CODE宏定义的,下边咱们能够了解一下CTL_CODE的内容。函数
This macro creates a unique system I/O control code (IOCTL).ui
#define CTL_CODE(DeviceType, Function, Method, Access) ( ((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) )
This parameter can be no bigger than a WORD value.this
The values used by Microsoft are in the range 0-32767; the values 32768-65535 are reserved for use by OEMs and IHVs.spa
The following device types are defined by the system:.net
The following device types are specific to Windows CE:code
Function codes 0-2047 are reserved for Microsoft; codes 2048-4095 are reserved for OEMs and IHVs.orm
A function code can be no larger then 4095.blog
The following values are possible for this parameter:ip
This field is ignored by Windows CE. You should always use the METHOD_BUFFERED value unless compatibility with Windows-based desktop platforms is required using a different Method value.
The following table shows the possible flags for this parameter. The FILE_ACCESS_ANY is generally the correct value.
Flag | Description |
---|---|
FILE_ANY_ACCESS | Request all access. |
FILE_READ_ACCESS | Request read access. Can be used with FILE_WRITE_ACCESS. |
FILE_WRITE_ACCESS | Request write access. Can be used with FILE_READ_ACCESS. |
None.
The macro can be used for defining IOCTL and FSCTL function control codes. All IOCTLs must be defined this way to ensure that values used by Microsoft, OEMs, and IHVs do not overlap.
The following illustration shows the format of the resulting IOCTL.
举例说明一下:
我定义两个IOCTL,一个用于对设备的读,一个用于对设备的写
#define ATST2004_IOCTL_READ CTL_CODE(FILE_DEVICE_UNKNOWN, 0x800, METHOD_BUFFERED, FILE_READ_DATA)
#define ATST2004_IOCTL_WRITE CTL_CODE(FILE_DEVICE_UNKNOWN, 0x801, METHOD_BUFFERED, FILE_WRITE_DATA)
在VC中使用不须要进行处理,假如我要在VB中使用这两个IOCTL,就须要进行查值计算了,计算后定义以下:
Private Const ATST2004_IOCTL_READ = &H226000 Private Const ATST2004_IOCTL_WRITE = &H22A004