Windows volume device detection failed to reboot. Never failed before
I have a code for detecting the connection of USB flash drives as volumes. The code worked very well for a while, but recently a mechanical engineer started crashing and didn't work again until it was restarted.
The project uses Qt 4.5.0, but that shouldn't be very relevant to this question.
I am registering for 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 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 processes the message as such:
void HandleVolumeArrival (MSG message *) {if (message-> lParam == 0) {qDebug () <"lParam - 0 when device arrives"; 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
Problem when checking device type for volume type:
pHdr->dbch_devicetype == DBT_DEVTYP_VOLUME
When it crashed, the device type was reported as DBT_DEVTYP_DEVICEINTERFACE
.
Several USB sticks were tested and they all had the same problem.
Has anyone seen anything like this before? Do you know what can cause this or why the problem will go away when you reboot the system?
a source to share
I guess you will see anyway DBT_DEVTYP_DEVICEINTERFACE
. USB devices are self-described. A USB device can have any "interfaces", where each interface is a feature of the device. I am assuming that when USB is plugged in, you get an " DBT_DEVTYP_DEVICEINTERFAC
E" on the USB device interface so the USB device driver can tell it can handle that USB interface. I would guess that the USB Mass Storage USB device driver will handle these messages by setting the volume and then you get the message DBT_DEVTYP_VOLUME
.
I would guess that the mass storage interface driver is malfunctioning (or crashed) and is not handling DBT_DEVTYP_DEVICEINTERFACE
. If you don't see it a lot, I don't think this is a situation you should be worried about.
a source to share