How do I find out what's wrong with the device info set returned? I'm re-writing my code again and I'm still hitting the same stumbling block.
如何找出返回的设备信息集有什么问题?我正在重新编写代码,我仍然遇到同样的绊脚石。
deviceInfoSet = SetupDiGetClassDevs(ref tGuid, 0, IntPtr.Zero, (uint)SetupDiFlags.DIGCF_PRESENT );
if (deviceInfoSet.ToInt32() == INVALID_DEVICE_HANDLE)
{
int errCode = Marshal.GetLastWin32Error();
errorMessage = new Win32Exception(Marshal.GetLastWin32Error()).Message;
statusLabel.Text += "Invalid deviceinfoset returned: " + errCode + " => " + errorMessage + ".";
}
The above code doesn't cause any errors but when I use the code below:
上面的代码不会导致任何错误,但是当我使用下面的代码时:
result = true;
while (result)
{
result = SetupDiEnumDeviceInterfaces(deviceInfoSet, IntPtr.Zero, ref tGuid, Index, ref anInterface);
if (!result)
{
int errCode = Marshal.GetLastWin32Error();
errorMessage = new Win32Exception(Marshal.GetLastWin32Error()).Message;
statusLabel.Text += "\nSetDiEnumDeviceInterface Error: " + errCode + " => " + errorMessage + ".";
break;
}
Index++;
}
to try and access the device info set list, error code 259 (No more data is available) is returned. I am at a loss as to what I'm doing wrong.
尝试访问设备信息集列表,返回错误代码259(没有更多数据可用)。我不知道自己做错了什么。
4 个解决方案
#1
Are you sure you're using the right GUID?
你确定你使用的是正确的GUID吗?
Check out http://blogs.msdn.com/doronh/archive/2006/02/15/532679.aspx
查看http://blogs.msdn.com/doronh/archive/2006/02/15/532679.aspx
Edit: Everything else looks by-the-book and correct.
编辑:其他所有东西看起来都是正确的。
Edit2: Trying including DIGCF_DEVICEINTERFACE in call to SetupDiGetClassDevs, and see if that works for you. That is, both DIGCF_PRESENT and DIGCF_DEVICEINTERFACE.
Edit2:尝试在调用SetupDiGetClassDevs时包含DIGCF_DEVICEINTERFACE,看看它是否适合您。也就是说,DIGCF_PRESENT和DIGCF_DEVICEINTERFACE都是。
Edit3: For the 64bit issue (@Thies), check out http://social.msdn.microsoft.com/Forums/en-US/windowssdk/thread/ea816aea-f718-4a0e-b013-0aa273de037f
编辑3:对于64位问题(@Thies),请查看http://social.msdn.microsoft.com/Forums/en-US/windowssdk/thread/ea816aea-f718-4a0e-b013-0aa273de037f
#2
I'm not familiar with this particular interface but it doesn't appear you are doing anything wrong. It simply appears that you are trying to read data from a device which currently has no data to offer.
我不熟悉这个特殊的界面,但看起来你做错了什么。您似乎只是试图从当前没有数据提供的设备读取数据。
Is that the case? Do you know for sure that the device is currently trying to return data to you?
是这样的吗?您是否确定该设备当前正在尝试向您返回数据?
#3
I had simular problems which were due to running on 64-bit Windows. I never quite figured it out, and ended up hardcoding the device path in my code - which is not recommended.
我有类似的问题是由于在64位Windows上运行。我从来没有弄明白,并最终在我的代码中硬编码设备路径 - 这是不推荐的。
I think it has to do with the API structures not setup correct for 64-bit.
我认为这与64位未正确设置的API结构有关。
Hope this may help lead someone else to an answer (and maybe help with my problem as well)
希望这可能有助于引导别人回答(也许也有助于解决我的问题)
Please state if you are running 64-bit - and have you tried the same code on a 32-bit OS?
请说明您是否正在运行64位 - 并且您是否在32位操作系统上尝试过相同的代码?
#4
The problem starts with how SetupDiGetClassDevs is called.
问题始于如何调用SetupDiGetClassDevs。
If you are looking to get a device path, use SetupDiGetClassDevs(&GUID_DEVINTERFACE_USB_DEVICE ,,,)
如果您要获取设备路径,请使用SetupDiGetClassDevs(&GUID_DEVINTERFACE_USB_DEVICE ,,,)
SetupDiEnumDeviceInterfaces fails with error 259 if SetupDiGetClassDevs is given the wrong GUID in ClassGuid which MS Help says is A pointer to the GUID for a device setup class or a device interface class.
如果在ClassGuid中为SetupDiGetClassDevs指定了错误的GUID,则SetupDiEnumDeviceInterfaces失败并显示错误259,MS帮助说这是指向设备设置类或设备接口类的GUID的指针。
Include file devguid.h contains a set of GUID_DEVCLASS values. These are NOT the same as GUID_DEVINTERFACE_* values which are the one you need.
包含文件devguid.h包含一组GUID_DEVCLASS值。这些与您需要的GUID_DEVINTERFACE_ *值不同。
Use #include which includes ksuuids.h where you'll find GUID_DEVINTERFACE_* values.
使用包含ksuuids.h的#include,您可以在其中找到GUID_DEVINTERFACE_ *值。
There's a more detailed explanation on my website, with some source code that should help in correctly enumerating USB devices.
在我的网站上有一个更详细的解释,有一些源代码可以帮助正确枚举USB设备。
#1
Are you sure you're using the right GUID?
你确定你使用的是正确的GUID吗?
Check out http://blogs.msdn.com/doronh/archive/2006/02/15/532679.aspx
查看http://blogs.msdn.com/doronh/archive/2006/02/15/532679.aspx
Edit: Everything else looks by-the-book and correct.
编辑:其他所有东西看起来都是正确的。
Edit2: Trying including DIGCF_DEVICEINTERFACE in call to SetupDiGetClassDevs, and see if that works for you. That is, both DIGCF_PRESENT and DIGCF_DEVICEINTERFACE.
Edit2:尝试在调用SetupDiGetClassDevs时包含DIGCF_DEVICEINTERFACE,看看它是否适合您。也就是说,DIGCF_PRESENT和DIGCF_DEVICEINTERFACE都是。
Edit3: For the 64bit issue (@Thies), check out http://social.msdn.microsoft.com/Forums/en-US/windowssdk/thread/ea816aea-f718-4a0e-b013-0aa273de037f
编辑3:对于64位问题(@Thies),请查看http://social.msdn.microsoft.com/Forums/en-US/windowssdk/thread/ea816aea-f718-4a0e-b013-0aa273de037f
#2
I'm not familiar with this particular interface but it doesn't appear you are doing anything wrong. It simply appears that you are trying to read data from a device which currently has no data to offer.
我不熟悉这个特殊的界面,但看起来你做错了什么。您似乎只是试图从当前没有数据提供的设备读取数据。
Is that the case? Do you know for sure that the device is currently trying to return data to you?
是这样的吗?您是否确定该设备当前正在尝试向您返回数据?
#3
I had simular problems which were due to running on 64-bit Windows. I never quite figured it out, and ended up hardcoding the device path in my code - which is not recommended.
我有类似的问题是由于在64位Windows上运行。我从来没有弄明白,并最终在我的代码中硬编码设备路径 - 这是不推荐的。
I think it has to do with the API structures not setup correct for 64-bit.
我认为这与64位未正确设置的API结构有关。
Hope this may help lead someone else to an answer (and maybe help with my problem as well)
希望这可能有助于引导别人回答(也许也有助于解决我的问题)
Please state if you are running 64-bit - and have you tried the same code on a 32-bit OS?
请说明您是否正在运行64位 - 并且您是否在32位操作系统上尝试过相同的代码?
#4
The problem starts with how SetupDiGetClassDevs is called.
问题始于如何调用SetupDiGetClassDevs。
If you are looking to get a device path, use SetupDiGetClassDevs(&GUID_DEVINTERFACE_USB_DEVICE ,,,)
如果您要获取设备路径,请使用SetupDiGetClassDevs(&GUID_DEVINTERFACE_USB_DEVICE ,,,)
SetupDiEnumDeviceInterfaces fails with error 259 if SetupDiGetClassDevs is given the wrong GUID in ClassGuid which MS Help says is A pointer to the GUID for a device setup class or a device interface class.
如果在ClassGuid中为SetupDiGetClassDevs指定了错误的GUID,则SetupDiEnumDeviceInterfaces失败并显示错误259,MS帮助说这是指向设备设置类或设备接口类的GUID的指针。
Include file devguid.h contains a set of GUID_DEVCLASS values. These are NOT the same as GUID_DEVINTERFACE_* values which are the one you need.
包含文件devguid.h包含一组GUID_DEVCLASS值。这些与您需要的GUID_DEVINTERFACE_ *值不同。
Use #include which includes ksuuids.h where you'll find GUID_DEVINTERFACE_* values.
使用包含ksuuids.h的#include,您可以在其中找到GUID_DEVINTERFACE_ *值。
There's a more detailed explanation on my website, with some source code that should help in correctly enumerating USB devices.
在我的网站上有一个更详细的解释,有一些源代码可以帮助正确枚举USB设备。