阅读:1334回复:2
为何不能枚举设备的接口类
各位大虾:
调用setupdigetclassdevs()函数可以正确得到设备信息集,但调用setupdienumdeviceinterfaces()时不能得到指定接口类的数据(guid是从注册表中读到的)?如果在调用setupdiclassdevs()中带参数DIGCF_ALLCLASSES,调试时发现设备信息集中包含我要的guid的接口信息,但一指定接口类就返回失败。 哪位大虾指点一下:源程序如下 #include \"stdafx.h\" #include \"windows.h\" #include \"winioctl.h\" #include \"stdio.h\" #include \"string.h\" #include \"guidusb.h\" extern \"C\" { #include \"setupapi.h\" } #include \"initguid.h\" DEFINE_GUID(GUID_USB, 0x4D36E97D, 0xE325, 0x11CE, 0xBF, 0xC1, 0x08, 0x0, 0x2B, 0xE1, 0x03, 0x18); int main(int argc, char* argv[]) { DWORD ReqLength; DWORD Flags=DIGCF_PRESENT|DIGCF_DEVICEINTERFACE; //DWORD Flags=DIGCF_ALLCLASSES; HDEVINFO HardwareDeviceInfo; int index = 0; PSP_DEVICE_INTERFACE_DETAIL_DATA DeviceDetailData; SP_DEVICE_INTERFACE_DATA DeviceInterfaceData; //SP_INTERFACE_DEVICE_DATA DeviceInterfaceData; SP_DEVINFO_DATA DeviceInfo; DeviceInfo.cbSize = sizeof(SP_DEVINFO_DATA); DeviceInterfaceData.cbSize = size(SP_DEVICE_INTERFACE_DATA); HardwareDeviceInfo = SetupDiGetClassDevs((LPGUID)&GUID_USB,NULL,NULL,Flags); if(HardwareDeviceInfo==INVALID_HANDLE_VALUE) { printf(\"Invalid Handle\"); return false; } while(Outer) { status = SetupDiEnumDeviceInfo(HardwareDeviceInfo,index,&DeviceInfo); status = SetupDiEnumDeviceInterfaces(HardwareDeviceInfo,0,(LPGUID)&GUID_USB,index,&DeviceInterfaceData); if(!status) { printf(\"Failed to enumerate the interface of the specified device\"); int error = GetLastError(); return false; } SetupDiGetDeviceInterfaceDetail(HardwareDeviceInfo,&DeviceInterfaceData,NULL,0,&ReqLength,NULL); DeviceDetailData = (PSP_INTERFACE_DEVICE_DETAIL_DATA)new char[ReqLength]; if(DeviceDetailData) { printf(\"Not enough memory\"); return false; } status = SetupDiGetDeviceInterfaceDetail(HardwareDeviceInfo,&DeviceInterfaceData,DeviceDetailData,ReqLength,&ReqLength,NULL); if(!status) { printf(\"Failed to get the detail data!\"); delete DeviceDetailData; DeviceDetailData = NULL; return false; } return 0; } |
|
沙发#
发布于:2003-09-19 23:37
设备句柄是0x00135bc8,返回成功。
现在接口已经枚举成功了,问题出在接口GUID上。从注册表中读的是设备GUID,而不是接口GUID,是不是这么回事啊?? 另,我有个疑问,GUID我是用ddk中的objdir读出来的,有没有api函数可以读出GUID的?如果可以的话,我程序就可以从0开始,不用事先知道GUID了。 [编辑 - 9/19/03 by hhddy] |
|
板凳#
发布于:2003-09-16 15:47
首先我想知道你的设备枚举成功了没有
你的枚举值发来上看看给我看看 |
|
|