Catch USB-Events
-
Hello! I want to catch events on the usb, like "the user plugged in a hid" :) I tried the WM_DEVICECHANGE, but this one helps only with USB-Sticks. Is there a way to get this information? Thank You
-
Hello! I want to catch events on the usb, like "the user plugged in a hid" :) I tried the WM_DEVICECHANGE, but this one helps only with USB-Sticks. Is there a way to get this information? Thank You
Set the GUID ( DEV_BROADCAST_DEVICEINTERFACE.dbcc_classguid ) to the class of devices that you want to monitor. That will take some digging on your part to discover the proper GUIDs DEV_BROADCAST_DEVICEINTERFACE devBroadcastDeviceInterface; ZeroMemory( &devBroadcastDeviceInterface, sizeof( devBroadcastDeviceInterface )); devBroadcastDeviceInterface.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE); devBroadcastDeviceInterface.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE; devBroadcastDeviceInterface.dbcc_classguid = GUID_DEVINTERFACE_USB_DEVICE;//GUID_DEVINTERFACE_HID m_hDevNotify = RegisterDeviceNotification ( g_hWnd, &devBroadcastDeviceInterface, DEVICE_NOTIFY_WINDOW_HANDLE );
-
Set the GUID ( DEV_BROADCAST_DEVICEINTERFACE.dbcc_classguid ) to the class of devices that you want to monitor. That will take some digging on your part to discover the proper GUIDs DEV_BROADCAST_DEVICEINTERFACE devBroadcastDeviceInterface; ZeroMemory( &devBroadcastDeviceInterface, sizeof( devBroadcastDeviceInterface )); devBroadcastDeviceInterface.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE); devBroadcastDeviceInterface.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE; devBroadcastDeviceInterface.dbcc_classguid = GUID_DEVINTERFACE_USB_DEVICE;//GUID_DEVINTERFACE_HID m_hDevNotify = RegisterDeviceNotification ( g_hWnd, &devBroadcastDeviceInterface, DEVICE_NOTIFY_WINDOW_HANDLE );
Good answer for the use case. I used static /*const*/ GUID GUID_DEVINTERFACE_USB_DEVICE = { 0xA5DCBF10L, 0x6530, 0x11D2, { 0x90, 0x1F, 0x00, 0xC0, 0x4F, 0xB9, 0x51, 0xED } }; However if I wanted to detect a user inserting/removing a card from a usb card reader... any one? Currently i only know if the carder reader is plugged/unplugged... not if the card is inserted / removed