【问题标题】:Which code fragment to use to handle USB device insertion?使用哪个代码片段来处理 USB 设备插入?
【发布时间】:2015-08-11 10:41:18
【问题描述】:

应用程序可以使用RegisterDeviceNotification 函数注册以接收来自系统的通知消息。 This example 展示了如何注册设备接口的事件通知,这些设备接口是其 GUID 传递给函数的接口类的成员。

在这个例子中,我应该使用哪个代码片段来处理 USB 设备插入消息?

【问题讨论】:

    标签: c++ windows winapi usb


    【解决方案1】:

    搜索 DBT_DEVICEARRIVAL: 这是处理 USB 设备插入消息的地方。

     case WM_DEVICECHANGE:
    {
        //
        // This is the actual message from the interface via Windows messaging.
        // This code includes some additional decoding for this particular device type
        // and some common validation checks.
        //
        // Note that not all devices utilize these optional parameters in the same
        // way. Refer to the extended information for your particular device type 
        // specified by your GUID.
        //
        PDEV_BROADCAST_DEVICEINTERFACE b = (PDEV_BROADCAST_DEVICEINTERFACE) lParam;
        TCHAR strBuff[256];
    
        // Output some messages to the window.
        switch (wParam)
        {
        case DBT_DEVICEARRIVAL:
            msgCount++;
            StringCchPrintf(
                strBuff, 256, 
                TEXT("Message %d: DBT_DEVICEARRIVAL\n"), msgCount);
            break;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-05-31
      • 2017-03-16
      • 2022-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-06
      相关资源
      最近更新 更多