Windows下USB磁盘开发系列四:SetupDiEnumDeviceInterfaces()返回ERROR_NO_MORE_ITEMS 259错误代码的原因
2013-11-15 11:30
477 查看
在调用API SetupDiEnumDeviceInterfaces()查询USB设备接口的时候,遇到了259的错误代码:ERROR_NO_MORE_ITEMS。开始不得其解,后来仔细察看了相关的msdn,发现是我调用SetupDiGetClassDevs()的参数使用错了。
定义如下:
第一个参数的说明如下:
ClassGuid [in, optional]
A pointer to the GUID for a device setup class or a
device interface class. This pointer is optional and can be NULL. For more information about how to set ClassGuid, see the following Remarks section.
我开始一直使用下面的方式获取设备句柄:
然后调用的时候总是返回失败,使用GetLastError()返回259。
正确的做法是要用一个device interface class来获取设备句柄,将上面的调用代码改为:
再调用numDeviceInterfaces()就可以了。
定义如下:
HDEVINFO SetupDiGetClassDevs( _In_opt_ const GUID *ClassGuid, _In_opt_ PCTSTR Enumerator, _In_opt_ HWND hwndParent, _In_ DWORD Flags );
第一个参数的说明如下:
ClassGuid [in, optional]
A pointer to the GUID for a device setup class or a
device interface class. This pointer is optional and can be NULL. For more information about how to set ClassGuid, see the following Remarks section.
我开始一直使用下面的方式获取设备句柄:
hDevInfo = SetupDiGetClassDevs(&GUID_DEVCLASS_USB, 0, 0, DIGCF_PRESENT);
然后调用的时候总是返回失败,使用GetLastError()返回259。
正确的做法是要用一个device interface class来获取设备句柄,将上面的调用代码改为:
hDevInfo = SetupDiGetClassDevs(&GUID_DEVINTERFACE_DISK, 0, 0, DIGCF_PRESENT|DIGCF_DEVICEINTERFACE);
再调用numDeviceInterfaces()就可以了。
相关文章推荐
- SetupDiEnumDeviceInterfaces返回false WIN7/WIN8
- Windows下USB磁盘开发系列二:枚举系统中所有USB设备
- Windows下USB磁盘开发系列三:枚举系统中U盘、并获取其设备信息
- SetupDiEnumDeviceInterfaces返回false WIN7/WIN8
- 函数 SetupDiEnumDeviceInterfaces 总返回false
- 关于Windows下USB函数SetupDiEnumDeviceInfo()与SetupDiEnumDeviceInterfaces()的心得
- Windows下USB磁盘开发系列一:枚举系统中U盘的盘符
- Windows下USB磁盘开发系列三:枚举系统中U盘、并获取其设备信息
- Windows下USB磁盘开发系列一:枚举系统中U盘的盘符
- Windows下USB磁盘开发系列二:枚举系统中所有USB设备
- Windows下USB磁盘开发系列二:枚举系统中所有USB设备
- 国外网站上解决SetupDiEnumDeviceInterfaces返回false的方法 (转)
- 提示如下错误:No space left ondevice,通过 df -h 查看磁盘空间,发现没满,请问可能原因是什么?
- SetupDiEnumDeviceInterfaces function
- SetupDiEnumDeviceInfo-使用SetupDi系列函数进行设备信息的管理(二)
- no space left on device 磁盘空间不足原因及排查方法
- ubuntu windows 双系统 磁盘乱搞 grub 导致 error:no such partition grub rescue>
- Linux下 打开多个USB 2.0 摄像头的问题( libv4l2: error turning on stream: No space left on device )
- ios开发调用OpenAL的alcOpenDevice(NULL)方法返回NULL的原因之一
- Eclipse android开发 error: device not found链接不上手机的原因