4.函数使用说明
CreateFile(devDetail->DevicePath,//
设备路径
GENERIC_READ | GENERIC_WRITE,//
访问方式
FILE_SHARE_READ | FILE_SHARE_WRITE,//
共享模式
NULL,
OPEN_EXISTING,//
文件不存在时,返回
失败
FILE_FLAG_OVERLAPPED,//
以重叠(异步)
模式打开
NULL);
在这里,CreateFile 用于打开 HID 设备,其中设备路径通过函数
SetupDiGetInterfaceDeviceDetail 取得。CreateFile 有以下几点需要注意:
-访问方式:如果是系统独占设备,例如鼠标、键盘等等,应将此参
数设置为 0,否则后续函数操作将失败(譬如 HidD_GetAttributes);也
就是说,不能对独占设备进行除了查询以外的任何操作,所以能够使用
的函数也是很有限的,下文的一些函数并不一定适合这些设备。在此顺
便列出 MSDN 上关于此参数的说明:
If this parameter is zero, the application can query le
and device attributes without accessing the device. This
is useful if an application wants to determine the size of
a %oppy disk drive and the formats it supports without
requiring a %oppy in the drive. It can also be used to test
for the le's or directory's existence without opening it
for read or write access。
评论0