Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 239285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:34:23+00:00 2026-05-11T20:34:23+00:00

I have code to detect the connection of USB Flash Drives as volumes. The

  • 0

I have code to detect the connection of USB Flash Drives as volumes. The code has been working very well for awhile, but recently a fellow engineer’s machine started to fail and didn’t work right again until it was restarted.

The project uses Qt 4.5.0, but that shouldn’t be very relevant to this question.

I register for the notification as follows

// Register for device connect notification
DEV_BROADCAST_DEVICEINTERFACE devInt;
ZeroMemory( &devInt, sizeof(devInt) );
devInt.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE);
devInt.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
devInt.dbcc_classguid = GUID_DEVINTERFACE_VOLUME;

m_hDeviceNotify =
    RegisterDeviceNotification( winId(), &devInt, DEVICE_NOTIFY_WINDOW_HANDLE );   

The handler then filters for the WM_DEVICECHANGE messages.

if (message->message == WM_DEVICECHANGE)
{
    switch (message->wParam)
    {
    case DBT_DEVICEARRIVAL:
        HandleVolumeArrival( message );
        break;

    case DBT_DEVICEREMOVECOMPLETE:
        HandleVolumeRemoval( message );
        break;

    default:
        break;
    }

    *result = TRUE;
} // end if

The arrival message handler then handles the message as such:

void HandleVolumeArrival( MSG *message )
{
if(message->lParam == 0)
{
qDebug() << “lParam is 0 on Device Arrival”;
return;
} // end if

PDEV_BROADCAST_HDR pHdr = (PDEV_BROADCAST_HDR) message->lParam;
if(pHdr->dbch_devicetype == DBT_DEVTYP_VOLUME)
{
    PDEV_BROADCAST_VOLUME pVol = (PDEV_BROADCAST_VOLUME) pHdr;

    // Handling of the volume is performed here
} // end if

} // end HandleVolumeArrival

The problem came when checking the device type for a volume type:

pHdr->dbch_devicetype == DBT_DEVTYP_VOLUME

When it was failing, the device type was being reported as DBT_DEVTYP_DEVICEINTERFACE.

Multiple USB drives were tried and all had the same problem.

Has anyone seen anything like this before? Do you know what could cause it or why the problem would go away on a system restart?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T20:34:24+00:00Added an answer on May 11, 2026 at 8:34 pm

    My guess would be that you would see the DBT_DEVTYP_DEVICEINTERFACE normally anyway. USB devices are self-describing. A USB device can have any “interfaces” where each interface is a feature of the device. My guess is that when a USB is connected you get a “DBT_DEVTYP_DEVICEINTERFACE” per USB device interface so that a USB device driver can say that they can handle that USB interface. I would assume that the USB device driver for USB mass storage driver would would handle this messages by mounting the volume and then you would get the DBT_DEVTYP_VOLUME message.

    I would guess that the mass storage interface driver is not working correctly (or has crashed) and is not handling the DBT_DEVTYP_DEVICEINTERFACE. Unless you starting seeing it a lot I don’t think it is a situation that you should bother to handle.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some way to detect when the network connection has been lost. So
I have a code to detect if I have internet connection or not, and
I have code that generates a List<string[]> variable but can't quite figure out how
I have code which has a drop down list. And when a certain option
I have code that looks more or less like the code below but it
I have an app in which I'm trying to detect WHEN the Internet connection
How can I detect that a client has disconnected from my server? I have
What's the most appropriate way to detect if a socket has been dropped or
I have a very simple client server code written java(server listens on some port
I currently have the following code: events.detect do |event| #detect does the block until

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.