3

Is there a mechanism in Windows that allows applications to detect when new hardware is connected to the system? In particular I would like to detect:

  • any serial ports being connected/disconnected
  • my custom USB-to-I2C board which uses WinUSB
mikijov
  • 1,552
  • 24
  • 37
  • tinman: Not or. WM_DEVICECHANGE messages aren't broadcast for all devices, only for disks and serial/parallel ports (including USB-based virtual COM ports). For other devices, the notification is sent only to windows for which it's been requested. – Ben Voigt Jul 20 '12 at 21:11
  • 1
    See this [related question](http://stackoverflow.com/q/11223562/588306) – Deanna Jul 23 '12 at 09:32

1 Answers1

4

You want RegisterDeviceNotification and WM_DEVICECHANGE.

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
  • This is a great starting point (RegisterDeviceNotification). Can you give me a clue in which direction to search for custom devices? – mikijov Jul 20 '12 at 21:08
  • @tinman: oops, maybe serial ports are sent automatically also. *Most* device types aren't. – Ben Voigt Jul 20 '12 at 21:10
  • I found an explanation, and saw your updated comment, in the MSDN page you linked to the last paragraph in remarks has "The DBT_DEVICEARRIVAL and DBT_DEVICEREMOVECOMPLETE events are automatically broadcast to all top-level windows for port devices." So that explains the serial ports. I'll remove my previous comment. – tinman Jul 20 '12 at 21:40
  • http://www.codeproject.com/Articles/14500/Detecting-Hardware-Insertion-and-or-Removal , this might help you.. – 2vision2 Jul 31 '12 at 04:45