Can I use the win32 Setup API to detect when USB devices have been plugged-in or unplugged?

StackOverflow https://stackoverflow.com/questions/23525892

  •  17-07-2023
  •  | 
  •  

Question

I'm looking through the references at http://msdn.microsoft.com/en-us/library/aa376947(v=vs.85).aspx (Setup API reference) and http://msdn.microsoft.com/en-us/library/windows/hardware/ff549791(v=vs.85).aspx (driver Setup API reference) and I don't see a function that would let me register a function that would get called when a particular device/hardwareID/driver key/ or whatever appears.

Anyone know how I would go about this? Ideally I'd like to do this detection in user-space, but if necessary I could work things around detecting this in kernel-space.

Was it helpful?

Solution

For notifications that are commonly of interest (e.g. a new disk volume has been plugged-in) Windows automatically broadcasts the WM_DEVICECHANGE message to all top-level Windows. You do not need to register for it.

For notifications that are not delivered automatically you can use RegisterDeviceNotification to request them.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top