views:

408

answers:

2

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?

+5  A: 

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
Is this the only way?
the only way I know of.
Stefan
-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
+1  A: 

Even though this article is about Qt, the code in the answer is relevant here.

sean e