3

Regarding the Windows platform, is their an event I can look for to tell when a USB drive or any type of portable media us plugged in?

derobert
  • 49,731
  • 15
  • 94
  • 124
  • Even though [this article is about Qt](https://stackoverflow.com/questions/852752/how-to-know-when-a-new-usb-storage-device-is-connected-in-qt), the code in the answer is relevant here. – sean e May 31 '09 at 15:45

1 Answers1

4

You won't get such notifications without first registering for them. Use RegisterDeviceNotification() to do that.

After you have registered your window to receive such notifications, handle the WM_DEVICECHANGE message.

Stefan
  • 43,293
  • 10
  • 75
  • 117
  • -1, doesn't work because it's not needed. QUoting the linked MSDN article: "Volume notifications are broadcast to top-level windows, so the function fails if dbch_devicetype is DBT_DEVTYP_VOLUME". USB drives (implementing Mass Storage profile) are volumes. – MSalters Jul 02 '09 at 15:54