Detecting media insertion into disk using window messages

I am currently using WM_DEVICECHANGE to receive notifications when new USB drives are connected to the computer. This is great for devices, such as thumb drives, where, as soon as the device arrives, it will be ready to read files. For devices, such as SD card readers, this is not because the message is sent once when the device is connected, but the message is not sent when the user actually inserts the card into the device.

Is it possible to detect the insertion of new media into an existing USB device without using a poll?

+5
source share
4 answers

I just did it a few weeks ago. Technically speaking, the RegisterDeviceNotification path is the right path, but it requires decent work. However, Windows Explorer is already doing all the hard work for you. Just use SHChangeNotifyRegister with SHCNE_DRIVEADD / SHCNE_DRIVEREMOVED / SHCNE_MEDIAINSERTED / SHCNE_MEDIAREMOVED. Note that this method depends on the Shell hardware discovery service (or on which it is called), but it is much easier than trying to re-implement the functionality yourself.

+8
source

There is a very good use case SHChangeNotifyRegisterin "Change the image of Watcher Watcher". Download it from this address:

http://msdn.microsoft.com/en-us/library/dd940348.aspx#downloading

SHChangeNotifyRegister Qt-.

!

+2

​​ SD-. WM_DEVICECHANGE - "DBT_DEVICEARRIVAL 0x8000 ."

, .

RegisterDeviceNotification? , .

0

, (, , , ), ... . , , , Microsoft (, ) , ( Windows 7 Microsoft Windows). SD- USB- WM_DEVICECHANGE.

SHChangeNotifyRegister . . SHGetPathFromIDList. SHCNE_MEDIAINSERTED SHCNE_MEDIAREMOVED.

Use the ONDeviceNotify device if you are looking for a hardware device rather than a multimedia device, or you can write your own device driver.

See this comment code CodeProject - Tracking Windows Messages

0
source

All Articles