注:我也遇到了这个问题,其实很简单,就是GUID与设备驱动的GUID不一致导致的。
CodeGuru Forums >
Visual C++ & C++ Programming >
Driver Development > SetupDiEnumDeviceInterfa
Click to See Complete Forum and Search --> : SetupDiEnumDeviceInterfa
scottweddle
March 9th, 2005, 04:38 PM
Hello,
I have a problem with SetupDiEnumDeviceInterfa I'm wondering if anyone knows why it never returns TRUE? Thanks. Here's the code: #include "stdafx.h" #include "windows.h" #include "Setupapi.h" #include "stdio.h" struct __declspec(uuid("36FC9E60-C465-11CF-8056-444553540000")) uuidUsbDevClass { }; int main(int argc, char* argv[]) { char szTraceBuf[256]; GUID guidUsbDevClass = __uuidof(uuidUsbDevClass); // Get device interface info set handle for all devices attached to system HDEVINFO hDevInfo = SetupDiGetClassDevs( &guidUsbDevClass, NULL, NULL, DIGCF_DEVICEINTERFACE | DIGCF_PRESENT ); if (hDevInfo == INVALID_HANDLE_VALUE) { sprintf(szTraceBuf, "SetupDiClassDevs() failed. GetLastError() " \ "returns: 0x%x\n", GetLastError()); OutputDebugString(szTraceBuf); printf("SetupDiClassDevs() failed. GetLastError() " \ "returns: 0x%x\n", GetLastError()); return 1; } sprintf(szTraceBuf, "Device info set handle for all devices attached to " \ "system: 0x%x\n", hDevInfo); OutputDebugString(szTraceBuf); printf("Device info set handle for all devices attached to " \ "system: 0x%x\n", hDevInfo); // Retrieve a context structure for a device interface of a device // information set. DWORD dwIndex = 0; SP_DEVICE_INTERFACE_DATA devInterfaceData; ZeroMemory(&devInterfaceData, sizeof(SP_DEVICE_INTERFACE_DATA)); devInterfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA); BOOL bRet = FALSE; while(TRUE) { bRet = SetupDiEnumDeviceInterfa hDevInfo, NULL, &guidUsbDevClass, dwIndex, &devInterfaceData ); if (!bRet) { sprintf(szTraceBuf, "SetupDiEnumDeviceInterfa "GetLastError() returns: 0x%x\n", GetLastError()); OutputDebugString(szTraceBuf); printf("SetupDiEnumDeviceInterfa "GetLastError() returns: 0x%x\n", GetLastError()); if (GetLastError() == ERROR_NO_MORE_ITEMS) { break; } } dwIndex++; } sprintf(szTraceBuf, "Number of device interface sets representing all " \ "devices attached to system: 0x%x\n", dwIndex); OutputDebugString(szTraceBuf); printf("Number of device interface sets representing all " \ "devices attached to system: 0x%x\n", dwIndex); SetupDiDestroyDeviceInfo return 0; }
scottweddle
March 10th, 2005, 11:29 AM
Here's more to add:
I'm doing this enumeration at the application level (user mode) not driver level (kernel mode). In order to be able to enumerate the devices does ther driver have to call IoRegisterDeviceInterfac Funny thing is when I call SetDiGetClassDevs() with whatever combonation for the 1st and 4th argument's I always get back the same handle. I'm passing the ClassGuid for the USB devices that come under the registry key: HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Enum\USB My theroy is that if you pass only DIGCF_DEVICEINTERFACE as the 4th arg along with the USB ClassGuid then SetupDiEnumDeviceInterfa If you pass the combonation of flags DIGCF_PRESENT | DIGCF_DEVICEINTERFACE and I have my device attached to the host SetupDiEnumDeviceInterfa That's all for now. Thanks, Scott
scottweddle
March 11th, 2005, 12:43 PM
Problem solved. I was using the wrong GUID. The correct GUID is:
A5DCBF10-6530-11D2-901F-00C04FB951ED. Here the code that works. Its basically the same except for how the GUID is declared and passed to functions SetupDiGetClassDevs() and SetupDiEnumDeviceInterfa #include "stdafx.h" #include "windows.h" #include "Setupapi.h" #include "stdio.h" static GUID GUID_DEVINTERFACE_USB_DEVICE = { 0xA5DCBF10L, 0x6530, 0x11D2, { 0x90, 0x1F, 0x00, 0xC0, 0x4F, 0xB9, 0x51, 0xED } }; int main(int argc, char* argv[]) { char szTraceBuf[256]; // Get device interface info set handle for all devices attached to system HDEVINFO hDevInfo = SetupDiGetClassDevs( &GUID_DEVINTERFACE_USB_DEVICE, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE ); if (hDevInfo == INVALID_HANDLE_VALUE) { sprintf(szTraceBuf, "SetupDiClassDevs() failed. GetLastError() " \ "returns: 0x%x\n", GetLastError()); OutputDebugString(szTraceBuf); printf("SetupDiClassDevs() failed. GetLastError() " \ "returns: 0x%x\n", GetLastError()); return 1; } sprintf(szTraceBuf, "Device info set handle for all devices attached to " \ "system: 0x%x\n", hDevInfo); OutputDebugString(szTraceBuf); printf("Device info set handle for all devices attached to " \ "system: 0x%x\n", hDevInfo); // Retrieve a context structure for a device interface of a device // information set. DWORD dwIndex = 0; SP_DEVICE_INTERFACE_DATA devInterfaceData; ZeroMemory(&devInterfaceData, sizeof(SP_DEVICE_INTERFACE_DATA)); devInterfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA); BOOL bRet = FALSE; while(TRUE) { bRet = SetupDiEnumDeviceInterfa hDevInfo, NULL, &GUID_DEVINTERFACE_USB_DEVICE, dwIndex, &devInterfaceData ); if (!bRet) { sprintf(szTraceBuf, "SetupDiEnumDeviceInterfa "GetLastError() returns: 0x%x\n", GetLastError()); OutputDebugString(szTraceBuf); printf("SetupDiEnumDeviceInterfa "GetLastError() returns: 0x%x\n", GetLastError()); if (GetLastError() == ERROR_NO_MORE_ITEMS) { break; } } dwIndex++; } sprintf(szTraceBuf, "Number of device interface sets representing all " \ "devices attached to system: 0x%x\n", dwIndex); OutputDebugString(szTraceBuf); printf("Number of device interface sets representing all " \ "devices attached to system: 0x%x\n", dwIndex); SetupDiDestroyDeviceInfo return 0; }
Neor
March 13th, 2005, 09:18 AM
Congratulation!
howcani
June 29th, 2005, 09:34 PM
I really need to know where you found the device interface GUID as distinct from the device setup GUID.....
optionalreaction
September 3rd, 2005, 12:51 PM
I really need to know where you found the device interface GUID as distinct from the device setup GUID.....
Yes, so do I. Has anyone got the (current) 'interface GUID' header file that they could post here? Keith
guitarmy
September 10th, 2005, 12:04 PM
Look in the winioctl.h header in the sdk include directory. make sure to include initguid.h as well if you plan to use the predefined guids.
eric
optionalreaction
September 11th, 2005, 01:58 PM
Look in the winioctl.h header in the sdk include directory. make sure to include initguid.h as well if you plan to use the predefined guids.
eric Thanks guitarmy... unfortunately winioctl.h contains GUIDs for IO only (disk, comport etc). I think the only way to get them is with the MS DDK, and that's not available for free download. Keith
cehupper
April 13th, 2006, 02:26 PM
DEFINE_GUID(GUID_DEVINTERFACE_USB_HUB, 0xf18a0e88, 0xc30c, 0x11d0, 0x88, 0x15, 0x00, \ 0xa0, 0xc9, 0x06, 0xbe, 0xd8); DEFINE_GUID(GUID_DEVINTERFACE_USB_DEVICE, 0xA5DCBF10L, 0x6530, 0x11D2, 0x90, 0x1F, 0x00, \ 0xC0, 0x4F, 0xB9, 0x51, 0xED); DEFINE_GUID(GUID_DEVINTERFACE_USB_HOST_CONTROLLER, 0x3abf6f2d, 0x71c4, 0x462a, 0x8a, 0x92, 0x1e, \ 0x68, 0x61, 0xe6, 0xaf, 0x27); DEFINE_GUID(GUID_USB_WMI_STD_DATA, 0x4E623B20L, 0xCB14, 0x11D1, 0xB3, 0x31, 0x00,\ 0xA0, 0xC9, 0x59, 0xBB, 0xD2); DEFINE_GUID(GUID_USB_WMI_STD_NOTIFICATION, 0x4E623B20L, 0xCB14, 0x11D1, 0xB3, 0x31, 0x00,\ 0xA0, 0xC9, 0x59, 0xBB, 0xD2); #define GUID_CLASS_USBHUB GUID_DEVINTERFACE_USB_HUB #define GUID_CLASS_USB_DEVICE GUID_DEVINTERFACE_USB_DEVICE #define GUID_CLASS_USB_HOST_CONTROLLER GUID_DEVINTERFACE_USB_HOST_CONTROLLER #define FILE_DEVICE_USB FILE_DEVICE_UNKNOWN
codeguru.com
Copyright 2007 Jupitermedia Corporation All Rights Reserved. | 被过滤广告![]() |
国外网站上解决SetupDiEnumDeviceInterfaces返回false的方法 (转)
最新推荐文章于 2023-04-05 17:20:49 发布