I'm writing an application that detects when a certain USB Mass Storage Device is plugged-in, and when it is unplugged - by listening for WM_DEVICECHANGE messages.
I've also registered my application to listen for WM_DEVICECHANGE
messages for DBT_DEVTYP_DEVICEINTERFACE
(using the RegisterDeviceNotification API call) and I get both the DBT_DEVICEARRIVAL
and DBT_DEVICEREMOVECOMPLETE
messages when a USB Mass Storage Device is plugged-in or unplugged.
Now, the problem occurs when a USB device that has multiple volumes is plugged-in, and then unplugged.
I get the following messages when the device is plugged in:
WM_DEVICECHANGE
(DBT_DEVICEARRIVAL
of typeDBT_DEVTYP_DEVICEINTERFACE
)WM_DEVICECHANGE
(DBT_DEVICEARRIVAL
of typeDBT_DEVTYP_VOLUME
)WM_DEVICECHANGE
(DBT_DEVICEARRIVAL
of typeDBT_DEVTYP_VOLUME
)
And the following messages when it is plugged out:
WM_DEVICECHANGE
(DBT_DEVICEREMOVECOMPLETE
of typeDBT_DEVTYP_VOLUME
)WM_DEVICECHANGE
(DBT_DEVICEREMOVECOMPLETE
of typeDBT_DEVTYP_DEVICEINTERFACE
)
So, only one remove message even though there are two volumes. Why??
I have two questions:
- How can I correlate
DBT_DEVTYP_DEVICEINTERFACE
messages withDBT_DEVTYP_VOLUME
messages (essentially, how do I know which VOLUME message corresponds to which DEVICEINTERFACE message - since I get them both for the device)? - Is there a way to make Windows notify me of both volume removals?