本文轉自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