• <i id='Xns2F'><tr id='Xns2F'><dt id='Xns2F'><q id='Xns2F'><span id='Xns2F'><b id='Xns2F'><form id='Xns2F'><ins id='Xns2F'></ins><ul id='Xns2F'></ul><sub id='Xns2F'></sub></form><legend id='Xns2F'></legend><bdo id='Xns2F'><pre id='Xns2F'><center id='Xns2F'></center></pre></bdo></b><th id='Xns2F'></th></span></q></dt></tr></i><div id='Xns2F'><tfoot id='Xns2F'></tfoot><dl id='Xns2F'><fieldset id='Xns2F'></fieldset></dl></div>
      <bdo id='Xns2F'></bdo><ul id='Xns2F'></ul>
    1. <tfoot id='Xns2F'></tfoot>

      <small id='Xns2F'></small><noframes id='Xns2F'>

      <legend id='Xns2F'><style id='Xns2F'><dir id='Xns2F'><q id='Xns2F'></q></dir></style></legend>

        对所有 USB 设备使用 RegisterDeviceNotification()

        时间:2023-12-02

          <bdo id='ZcBM7'></bdo><ul id='ZcBM7'></ul>
            <legend id='ZcBM7'><style id='ZcBM7'><dir id='ZcBM7'><q id='ZcBM7'></q></dir></style></legend>
              <tbody id='ZcBM7'></tbody>
            <tfoot id='ZcBM7'></tfoot>

                  <i id='ZcBM7'><tr id='ZcBM7'><dt id='ZcBM7'><q id='ZcBM7'><span id='ZcBM7'><b id='ZcBM7'><form id='ZcBM7'><ins id='ZcBM7'></ins><ul id='ZcBM7'></ul><sub id='ZcBM7'></sub></form><legend id='ZcBM7'></legend><bdo id='ZcBM7'><pre id='ZcBM7'><center id='ZcBM7'></center></pre></bdo></b><th id='ZcBM7'></th></span></q></dt></tr></i><div id='ZcBM7'><tfoot id='ZcBM7'></tfoot><dl id='ZcBM7'><fieldset id='ZcBM7'></fieldset></dl></div>
                1. <small id='ZcBM7'></small><noframes id='ZcBM7'>

                  本文介绍了对所有 USB 设备使用 RegisterDeviceNotification()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我目前有一些代码可以在 Windows 服务(用 C++ 编写)中设置连接的 USB HID 设备的通知.代码如下:

                  I currently have some code that sets up notifications of connected USB HID devices within a Windows Service (written in C++). The code is as follows:

                     GUID hidGuid;
                     HidD_GetHidGuid(&hidGuid);
                  
                     DEV_BROADCAST_DEVICEINTERFACE NotificationFilter;
                     ZeroMemory(&NotificationFilter, sizeof(NotificationFilter));
                     NotificationFilter.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE);
                     NotificationFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
                     NotificationFilter.dbcc_classguid = hidGuid;
                     HDEVNOTIFY deviceNotify = RegisterDeviceNotification(StatusHandle, &NotificationFilter, DEVICE_NOTIFY_SERVICE_HANDLE);
                  

                  然后通过 SERVICE_CONTROL_DEVICEEVENT 事件接收通知.(请记住,这是一项服务,因此没有 WM_DEVICECHANGE).

                  A notification is then received via the SERVICE_CONTROL_DEVICEEVENT event. (Remember, this is a Service so no WM_DEVICECHANGE).

                  我以为我可以在 RegisterDeviceNotification() 调用中指定 DEV_BROADCAST_DEVICEINTERFACE 标志,这样它就会覆盖 dbcc_classguid 并获取所有设备,但结果证明该标志在 Windows 2000 上不受支持,这对我来说是一个交易破坏者.此外,我猜这将返回的不仅仅是 USB 设备.

                  I thought I could just specify the DEV_BROADCAST_DEVICEINTERFACE flag in the RegisterDeviceNotification() call so it would override dbcc_classguid and get all devices, but it turns out that that flag is not supported on Windows 2000, which is a dealbreaker for me. Also, I'm guessing that that would return more than just USB devices.

                  我应该如何修改它以获取所有 USB 设备,而不仅仅是 USB HID?它应该像只提供不同的 GUID 一样简单吗?甚至所有 USB 都有一个 GUID 吗?

                  How should I modify this to get all USB devices, not just USB HID? Should it be as simple as just giving a different GUID? Is there even a GUID for all USB?

                  推荐答案

                  使用 GUID_DEVINTERFACE_USB_DEVICE(在usbiodef.h"中)来监视所有 USB 设备.

                  Used GUID_DEVINTERFACE_USB_DEVICE (in "usbiodef.h") to watch for all USB devices.

                    DEV_BROADCAST_DEVICEINTERFACE NotificationFilter;
                    ZeroMemory(&NotificationFilter, sizeof(NotificationFilter));
                  
                    NotificationFilter.dbcc_size = sizeof(NotificationFilter);
                    NotificationFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
                    NotificationFilter.dbcc_reserved = 0;
                  
                    NotificationFilter.dbcc_classguid = GUID_DEVINTERFACE_USB_DEVICE;
                  
                    HDEVNOTIFY hDevNotify = RegisterDeviceNotification(hwnd, &NotificationFilter, DEVICE_NOTIFY_SERVICE_HANDLE);
                  

                  这篇关于对所有 USB 设备使用 RegisterDeviceNotification()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:默认情况下启用或禁用菜单项.为什么? 下一篇:Windows 10 Toast 通知桌面应用程序

                  相关文章

                  <small id='Cg4Gv'></small><noframes id='Cg4Gv'>

                    <i id='Cg4Gv'><tr id='Cg4Gv'><dt id='Cg4Gv'><q id='Cg4Gv'><span id='Cg4Gv'><b id='Cg4Gv'><form id='Cg4Gv'><ins id='Cg4Gv'></ins><ul id='Cg4Gv'></ul><sub id='Cg4Gv'></sub></form><legend id='Cg4Gv'></legend><bdo id='Cg4Gv'><pre id='Cg4Gv'><center id='Cg4Gv'></center></pre></bdo></b><th id='Cg4Gv'></th></span></q></dt></tr></i><div id='Cg4Gv'><tfoot id='Cg4Gv'></tfoot><dl id='Cg4Gv'><fieldset id='Cg4Gv'></fieldset></dl></div>
                    • <bdo id='Cg4Gv'></bdo><ul id='Cg4Gv'></ul>
                    <legend id='Cg4Gv'><style id='Cg4Gv'><dir id='Cg4Gv'><q id='Cg4Gv'></q></dir></style></legend>
                    1. <tfoot id='Cg4Gv'></tfoot>