eyeszhu
驱动牛犊
驱动牛犊
  • 注册日期2003-05-14
  • 最后登录2003-08-22
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:2251回复:5

SetupDiEnumDeviceInterfaces枚举返回no_more_items,在线散分

楼主#
更多 发布于:2003-06-23 12:29
用vc编程
之前我用SetupDiEnumDeviceInfo枚举正常,但是换成SetupDiEnumDeviceInterfaces
就返回no_more_items,
另外,
我注意到SetupDiGetClassDevs(pGuid,
0, // Enumerator
0,
DIGCF_PRESENT); 中最后一个参数加上|DIGCF_DEVICEINTERFACE后,即使是SetupDiEnumDeviceInfo也什么都无法枚举,不明白为什么
我的guid用的系统自定义的GUID_DEVCLASS_USB
是不是这种类没有接口函数?
在线等待散分,谢谢
jinghuiren
驱动巨牛
驱动巨牛
  • 注册日期2002-06-01
  • 最后登录2008-10-27
  • 粉丝0
  • 关注0
  • 积分291分
  • 威望460点
  • 贡献值0点
  • 好评度428点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2003-06-23 13:08
不应该呀,下面这段代码是打开我的设备用的,最后那两个释放资源是我最近改的,没有经过测试,但是前面那一段是我测试过的,确实没问题,你参考一下吧。
HANDLE
open_dev()
{
PSP_INTERFACE_DEVICE_DETAIL_DATA     functionClassDeviceData = NULL;
    SP_INTERFACE_DEVICE_DATA     deviceInfoData;
    ULONG                                predictedLength = 0;
    ULONG                                requiredLength = 0;
HANDLE hOut = INVALID_HANDLE_VALUE;
    HDEVINFO                 hardwareDeviceInfo = NULL;
    PUSB_DEVICE_DESCRIPTOR   usbDeviceInst;
    PUSB_DEVICE_DESCRIPTOR *UsbDevices = &usbDeviceInst;
    deviceInfoData.cbSize = sizeof (SP_INTERFACE_DEVICE_DATA);
   *UsbDevices = (PUSB_DEVICE_DESCRIPTOR)calloc (1, sizeof (USB_DEVICE_DESCRIPTOR));
    if (NULL == *UsbDevices)
{
    SetupDiDestroyDeviceInfoList (hardwareDeviceInfo);
return hOut;
      }

hardwareDeviceInfo = SetupDiGetClassDevs(
                           (LPGUID)&GUID_CLASS_D12_BULK,
                           NULL, // Define no enumerator (global)
                           NULL, // Define no
                           (DIGCF_PRESENT | // Only Devices present
                            DIGCF_INTERFACEDEVICE));

SetupDiEnumDeviceInterfaces (hardwareDeviceInfo,
                                 0, // We don\'t care about specific PDOs
(LPGUID) &GUID_CLASS_D12_BULK,
                                 0,
                                 &deviceInfoData);

    SetupDiGetDeviceInterfaceDetail(
            hardwareDeviceInfo,
            &deviceInfoData,
            NULL, // probing so no output buffer yet
            0, // probing so output buffer length of zero
            &requiredLength,
            NULL); // not interested in the specific dev-node


    predictedLength = requiredLength;

    functionClassDeviceData = (PSP_INTERFACE_DEVICE_DETAIL_DATA)malloc (predictedLength);
    functionClassDeviceData->cbSize = sizeof (SP_INTERFACE_DEVICE_DETAIL_DATA);
    //
    // Retrieve the information from Plug and Play.
    //
    if (!SetupDiGetDeviceInterfaceDetail (
               hardwareDeviceInfo,
               &deviceInfoData,
               functionClassDeviceData,
               predictedLength,
               &requiredLength,
               NULL))
{
   SetupDiDestroyDeviceInfoList (hardwareDeviceInfo);
free(functionClassDeviceData);
if(*UsbDevices)
free(*UsbDevices);
return hOut;
    }

    hOut = CreateFile (
                  functionClassDeviceData->DevicePath,
                  GENERIC_READ | GENERIC_WRITE,
                  FILE_SHARE_READ | FILE_SHARE_WRITE,
                  NULL, // no SECURITY_ATTRIBUTES structure
                  OPEN_EXISTING, // No special create flags
                  0, // No special attributes
                  NULL); // No template file
    SetupDiDestroyDeviceInfoList (hardwareDeviceInfo);
    free(functionClassDeviceData);
if(usbDeviceInst)
free(usbDeviceInst);
if(*UsbDevices)
UsbDevices = NULL;
return hOut;

}
eyeszhu
驱动牛犊
驱动牛犊
  • 注册日期2003-05-14
  • 最后登录2003-08-22
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2003-06-23 13:34
会不会是我使用GUID_DEVCLASS_USB的原因
我的源代码和你的差不多呀,参考ddk的

是不是和运行环境也有关?
我直接在vc下运行,加入了
.lib和.h文件而已
jinghuiren
驱动巨牛
驱动巨牛
  • 注册日期2002-06-01
  • 最后登录2008-10-27
  • 粉丝0
  • 关注0
  • 积分291分
  • 威望460点
  • 贡献值0点
  • 好评度428点
  • 原创分0分
  • 专家分0分
地板#
发布于:2003-06-23 13:48
有可能,你不能用class usb的guid
你必须为你自己的设备产生一个guid
Microsoft Visual Studio\\Common\\Tools里有个叫GUIDGEN.EXE的应用程序,你可以用它产生一个GUID,再试试。
eyeszhu
驱动牛犊
驱动牛犊
  • 注册日期2003-05-14
  • 最后登录2003-08-22
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
地下室#
发布于:2003-06-23 14:22
我现在是先访问已存在驱动的闪盘,他的驱动信息中显示是
usb类,Guid已经定了,能改吗?

而且,在硬件里看到,闪盘对应这usb/mass storage和磁盘驱动器/usb设备两个驱动,对应在winobj的??目录中的
usbstor#disk#...
usb#vid_...#pid_...
上面说得驱动对应guid指其中mass storage的驱动

分不清了

 
eyeszhu
驱动牛犊
驱动牛犊
  • 注册日期2003-05-14
  • 最后登录2003-08-22
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
5楼#
发布于:2003-06-23 16:33

我知道为什么有两个驱动了,看:
Note that at least two drivers are used for USB keyboard and mouse devices. One belongs to the USB HID class and the other one belongs to the keyboard or mouse class. The keyboard
or mouse driver runs on top of the USB HID driver. In the Device Manager the HID driver is shown in a section labeled
\"Human Interface Devices\".
游客

返回顶部