Test wince http://blog.csdn.net/achellies/article/details/4533881 http://blog.csdn.net/CoolSlob/article/details/3348147 1、可根据dbch_devicetype(DBT_DEVTYP_DEVICEINTERFACE和DBT_DEVTYP_VOLUME),分别得到PID/VID/SN和盘符号。 2、当USB设备不是存储设备时,只出发一次WM_DEVICECHANGE,devicetype是DBT_DEVTYP_DEVICEINTERFACE 3、当USB设备是存储设备时,会触发两次WM_DEVICECHANGE,一次是DBT_DEVTYP_DEVICEINTERFACE、一次是DBT_DEVTYP_VOLUME 4、插入时,先DBT_DEVTYP_DEVICEINTERFACE后DBT_DEVTYP_VOLUME 5、拔出时,先DBT_DEVTYP_VOLUME后DBT_DEVTYP_DEVICEINTERFACE 6、即使是存储设备,有时也不会触发DBT_DEVTYP_VOLUME,这个问题还没搞清楚。 case WM_DEVICECHANGE: { DbgPrint(_T("WM_DEVICECHANGE/n")); switch (wParam) { case DBT_DEVICEARRIVAL: { PDEV_BROADCAST_HDR pDBHdr = (PDEV_BROADCAST_HDR)lParam; switch(pDBHdr->dbch_devicetype) { case DBT_DEVTYP_DEVICEINTERFACE: { PDEV_BROADCAST_DEVICEINTERFACE pDBInteface = (PDEV_BROADCAST_DEVICEINTERFACE)pDBHdr; LPOLESTR pGuid = NULL; StringFromCLSID(pDBInteface->dbcc_classguid,&pGuid); DbgPrint(_T("DBT_DEVTYP_DEVICEINTERFACE,Device CLSID = %s,Device Name = %s/n"),pGuid,pDBInteface->dbcc_name); CoTaskMemFree(pGuid); break; } case DBT_DEVTYP_HANDLE: { PDEV_BROADCAST_HANDLE pDBHandler = (PDEV_BROADCAST_HANDLE)pDBHdr; LPOLESTR pGuid = NULL; StringFromCLSID(pDBHandler->dbch_eventguid,&pGuid); DbgPrint(_T("DBT_DEVTYP_HANDLE,Device CLSID = %s/n"),pGuid); CoTaskMemFree(pGuid); break; } case DBT_DEVTYP_OEM: DbgPrint( _T("DBT_DEVTYP_OEM!/n")); break; case DBT_DEVTYP_PORT: { PDEV_BROADCAST_PORT pDBPort = (PDEV_BROADCAST_PORT)pDBHdr; DbgPrint(_T("DBT_DEVTYP_PORT = %s/n"),pDBPort->dbcp_name); break; } case DBT_DEVTYP_VOLUME: DbgPrint( _T("DBT_DEVTYP_VOLUME!/n")); break; } break; } case DBT_DEVICEREMOVECOMPLETE: { PDEV_BROADCAST_HDR pDBHdr = (PDEV_BROADCAST_HDR)lParam; switch(pDBHdr->dbch_devicetype) { case DBT_DEVTYP_DEVICEINTERFACE: { PDEV_BROADCAST_DEVICEINTERFACE pDBInteface = (PDEV_BROADCAST_DEVICEINTERFACE)pDBHdr; LPOLESTR pGuid = NULL; StringFromCLSID(pDBInteface->dbcc_classguid,&pGuid); DbgPrint(_T("DBT_DEVICEREMOVECOMPLETE,Device CLSID = %s,Device Name = %s/n"),pGuid,pDBInteface->dbcc_name); CoTaskMemFree(pGuid); break; } case DBT_DEVTYP_HANDLE: { PDEV_BROADCAST_HANDLE pDBHandler = (PDEV_BROADCAST_HANDLE)pDBHdr; LPOLESTR pGuid = NULL; StringFromCLSID(pDBHandler->dbch_eventguid,&pGuid); DbgPrint(_T("DBT_DEVTYP_HANDLE,Device CLSID = %s/n"),pGuid); CoTaskMemFree(pGuid); break; } case DBT_DEVTYP_OEM: DbgPrint( _T("DBT_DEVTYP_OEM!/n")); break; case DBT_DEVTYP_PORT: { PDEV_BROADCAST_PORT pDBPort = (PDEV_BROADCAST_PORT)pDBHdr; DbgPrint(_T("DBT_DEVTYP_PORT = %s/n"),pDBPort->dbcp_name); break; } case DBT_DEVTYP_VOLUME: DbgPrint( _T("DBT_DEVTYP_VOLUME!/n")); break; } break; } } return LRESULT(TRUE); } rpath.pri OTHER PLATFORM Use QAbstractEventDispatcher. See QxtGlobalShortcut other device windows and other platforms. See QDrive watch /etc/mtab for linux 2.4 GUI example from armv6: tid=0x4001fe20 HotplugWatcher::HotplugWatcher(QObject*) Hotplug watcher started parseDeviceInfo: "read fro socket 239 bytes" parseLine: "add@/devices/platform/tcc-ohci/usb1/1-1/1-1.2" parseLine: "ACTION=add" parseLine: "DEVPATH=/devices/platform/tcc-ohci/usb1/1-1/1-1.2" parseLine: "SUBSYSTEM=usb" parseLine: "MAJOR=189" parseLine: "MINOR=4" parseLine: "DEVTYPE=usb_device" parseLine: "PHYSDEVBUS=usb" parseLine: "PRODUCT=125f/312a/a00" parseLine: "TYPE=0/0/0" parseLine: "BUSNUM=001" parseLine: "DEVNUM=005" parseLine: "SEQNUM=755" parseDeviceInfo: "read fro socket 294 bytes" parseLine: "add@/devices/platform/tcc-ohci/usb1/1-1/1-1.2/1-1.2:1.0" parseLine: "ACTION=add" parseLine: "DEVPATH=/devices/platform/tcc-ohci/usb1/1-1/1-1.2/1-1.2:1.0" parseLine: "SUBSYSTEM=usb" parseLine: "DEVTYPE=usb_interface" parseLine: "PHYSDEVBUS=usb" parseLine: "PRODUCT=125f/312a/a00" parseLine: "TYPE=0/0/0" parseLine: "INTERFACE=8/6/80" parseLine: "MODALIAS=usb:v125Fp312Ad0A00dc00dsc00dp00ic08isc06ip50" parseLine: "SEQNUM=756" parseDeviceInfo: "read fro socket 205 bytes" parseLine: "add@/class/scsi_host/host5" parseLine: "ACTION=add" parseLine: "DEVPATH=/class/scsi_host/host5" parseLine: "SUBSYSTEM=scsi_host" parseLine: "PHYSDEVPATH=/devices/platform/tcc-ohci/usb1/1-1/1-1.2/1-1.2:1.0" parseLine: "PHYSDEVBUS=usb" parseLine: "PHYSDEVDRIVER=usb-storage" parseLine: "SEQNUM=757" parseDeviceInfo: "read fro socket 251 bytes" parseLine: "add@/class/usb_endpoint/usbdev1.5_ep02" parseLine: "ACTION=add" parseLine: "DEVPATH=/class/usb_endpoint/usbdev1.5_ep02" parseLine: "SUBSYSTEM=usb_endpoint" parseLine: "MAJOR=253" parseLine: "MINOR=20" parseLine: "PHYSDEVPATH=/devices/platform/tcc-ohci/usb1/1-1/1-1.2/1-1.2:1.0" parseLine: "PHYSDEVBUS=usb" parseLine: "PHYSDEVDRIVER=usb-storage" parseLine: "SEQNUM=758" parseDeviceInfo: "read fro socket 251 bytes" parseLine: "add@/class/usb_endpoint/usbdev1.5_ep81" parseLine: "ACTION=add" parseLine: "DEVPATH=/class/usb_endpoint/usbdev1.5_ep81" parseLine: "SUBSYSTEM=usb_endpoint" parseLine: "MAJOR=253" parseLine: "MINOR=21" parseLine: "PHYSDEVPATH=/devices/platform/tcc-ohci/usb1/1-1/1-1.2/1-1.2:1.0" parseLine: "PHYSDEVBUS=usb" parseLine: "PHYSDEVDRIVER=usb-storage" parseLine: "SEQNUM=759" parseDeviceInfo: "read fro socket 233 bytes" parseLine: "add@/class/usb_endpoint/usbdev1.5_ep00" parseLine: "ACTION=add" parseLine: "DEVPATH=/class/usb_endpoint/usbdev1.5_ep00" parseLine: "SUBSYSTEM=usb_endpoint" parseLine: "MAJOR=253" parseLine: "MINOR=22" parseLine: "PHYSDEVPATH=/devices/platform/tcc-ohci/usb1/1-1/1-1.2" parseLine: "PHYSDEVBUS=usb" parseLine: "PHYSDEVDRIVER=usb" parseLine: "SEQNUM=760" parseDeviceInfo: "read fro socket 262 bytes" parseLine: "add@/devices/platform/tcc-ohci/usb1/1-1/1-1.2/1-1.2:1.0/host5/target5:0:0/5:0:0:0" parseLine: "ACTION=add" parseLine: "DEVPATH=/devices/platform/tcc-ohci/usb1/1-1/1-1.2/1-1.2:1.0/host5/target5:0:0/5:0:0:0" parseLine: "SUBSYSTEM=scsi" parseLine: "DEVTYPE=scsi_device" parseLine: "PHYSDEVBUS=scsi" parseLine: "MODALIAS=scsi:t-0x00" parseLine: "SEQNUM=761" parseDeviceInfo: "read fro socket 227 bytes" parseLine: "add@/class/scsi_disk/5:0:0:0" parseLine: "ACTION=add" parseLine: "DEVPATH=/class/scsi_disk/5:0:0:0" parseLine: "SUBSYSTEM=scsi_disk" parseLine: "PHYSDEVPATH=/devices/platform/tcc-ohci/usb1/1-1/1-1.2/1-1.2:1.0/host5/target5:0:0/5:0:0:0" parseLine: "PHYSDEVBUS=scsi" parseLine: "PHYSDEVDRIVER=sd" parseLine: "SEQNUM=762" parseDeviceInfo: "read fro socket 315 bytes" parseLine: "change@/devices/platform/tcc-ohci/usb1/1-1/1-1.2/1-1.2:1.0/host5/target5:0:0/5:0:0:0" parseLine: "ACTION=change" parseLine: "DEVPATH=/devices/platform/tcc-ohci/usb1/1-1/1-1.2/1-1.2:1.0/host5/target5:0:0/5:0:0:0" parseLine: "SUBSYSTEM=scsi" parseLine: "SDEV_MEDIA_CHANGE=1" parseLine: "DEVTYPE=scsi_device" parseLine: "DRIVER=sd" parseLine: "PHYSDEVBUS=scsi" parseLine: "PHYSDEVDRIVER=sd" parseLine: "MODALIAS=scsi:t-0x00" parseLine: "SEQNUM=763" parseDeviceInfo: "read fro socket 225 bytes" parseLine: "add@/block/sdc" parseLine: "ACTION=add" parseLine: "DEVPATH=/block/sdc" parseLine: "SUBSYSTEM=block" parseLine: "MAJOR=8" parseLine: "MINOR=32" parseLine: "DEVTYPE=disk" parseLine: "PHYSDEVPATH=/devices/platform/tcc-ohci/usb1/1-1/1-1.2/1-1.2:1.0/host5/target5:0:0/5:0:0:0" parseLine: "PHYSDEVBUS=scsi" parseLine: "PHYSDEVDRIVER=sd" parseLine: "SEQNUM=764" parseDeviceInfo: "read fro socket 240 bytes" parseLine: "add@/block/sdc/sdc1" parseLine: "ACTION=add" parseLine: "DEVPATH=/block/sdc/sdc1" parseLine: "SUBSYSTEM=block" parseLine: "MAJOR=8" parseLine: "MINOR=33" parseLine: "DEVTYPE=partition" parseLine: "PHYSDEVPATH=/devices/platform/tcc-ohci/usb1/1-1/1-1.2/1-1.2:1.0/host5/target5:0:0/5:0:0:0" parseLine: "PHYSDEVBUS=scsi" parseLine: "PHYSDEVDRIVER=sd" parseLine: "SEQNUM=765" parseDeviceInfo: "read fro socket 80 bytes" parseLine: "add@/class/bdi/8:32" parseLine: "ACTION=add" parseLine: "DEVPATH=/class/bdi/8:32" parseLine: "SUBSYSTEM=bdi" parseLine: "SEQNUM=766" parseDeviceInfo: "read fro socket 233 bytes" parseLine: "add@/class/scsi_device/5:0:0:0" parseLine: "ACTION=add" parseLine: "DEVPATH=/class/scsi_device/5:0:0:0" parseLine: "SUBSYSTEM=scsi_device" parseLine: "PHYSDEVPATH=/devices/platform/tcc-ohci/usb1/1-1/1-1.2/1-1.2:1.0/host5/target5:0:0/5:0:0:0" parseLine: "PHYSDEVBUS=scsi" parseLine: "PHYSDEVDRIVER=sd" parseLine: "SEQNUM=767" parseDeviceInfo: "read fro socket 245 bytes" parseLine: "add@/class/scsi_generic/sg2" parseLine: "ACTION=add" parseLine: "DEVPATH=/class/scsi_generic/sg2" parseLine: "SUBSYSTEM=scsi_generic" parseLine: "MAJOR=21" parseLine: "MINOR=2" parseLine: "PHYSDEVPATH=/devices/platform/tcc-ohci/usb1/1-1/1-1.2/1-1.2:1.0/host5/target5:0:0/5:0:0:0" parseLine: "PHYSDEVBUS=scsi" parseLine: "PHYSDEVDRIVER=sd" parseLine: "SEQNUM=768" parseDeviceInfo: "read fro socket 257 bytes" parseLine: "remove@/class/usb_endpoint/usbdev1.5_ep02" parseLine: "ACTION=remove" parseLine: "DEVPATH=/class/usb_endpoint/usbdev1.5_ep02" parseLine: "SUBSYSTEM=usb_endpoint" parseLine: "MAJOR=253" parseLine: "MINOR=20" parseLine: "PHYSDEVPATH=/devices/platform/tcc-ohci/usb1/1-1/1-1.2/1-1.2:1.0" parseLine: "PHYSDEVBUS=usb" parseLine: "PHYSDEVDRIVER=usb-storage" parseLine: "SEQNUM=769" parseDeviceInfo: "read fro socket 257 bytes" parseLine: "remove@/class/usb_endpoint/usbdev1.5_ep81" parseLine: "ACTION=remove" parseLine: "DEVPATH=/class/usb_endpoint/usbdev1.5_ep81" parseLine: "SUBSYSTEM=usb_endpoint" parseLine: "MAJOR=253" parseLine: "MINOR=21" parseLine: "PHYSDEVPATH=/devices/platform/tcc-ohci/usb1/1-1/1-1.2/1-1.2:1.0" parseLine: "PHYSDEVBUS=usb" parseLine: "PHYSDEVDRIVER=usb-storage" parseLine: "SEQNUM=770" parseDeviceInfo: "read fro socket 251 bytes" parseLine: "remove@/class/scsi_generic/sg2" parseLine: "ACTION=remove" parseLine: "DEVPATH=/class/scsi_generic/sg2" parseLine: "SUBSYSTEM=scsi_generic" parseLine: "MAJOR=21" parseLine: "MINOR=2" parseLine: "PHYSDEVPATH=/devices/platform/tcc-ohci/usb1/1-1/1-1.2/1-1.2:1.0/host5/target5:0:0/5:0:0:0" parseLine: "PHYSDEVBUS=scsi" parseLine: "PHYSDEVDRIVER=sd" parseLine: "SEQNUM=771" parseDeviceInfo: "read fro socket 239 bytes" parseLine: "remove@/class/scsi_device/5:0:0:0" parseLine: "ACTION=remove" parseLine: "DEVPATH=/class/scsi_device/5:0:0:0" parseLine: "SUBSYSTEM=scsi_device" parseLine: "PHYSDEVPATH=/devices/platform/tcc-ohci/usb1/1-1/1-1.2/1-1.2:1.0/host5/target5:0:0/5:0:0:0" parseLine: "PHYSDEVBUS=scsi" parseLine: "PHYSDEVDRIVER=sd" parseLine: "SEQNUM=772" parseDeviceInfo: "read fro socket 233 bytes" parseLine: "remove@/class/scsi_disk/5:0:0:0" parseLine: "ACTION=remove" parseLine: "DEVPATH=/class/scsi_disk/5:0:0:0" parseLine: "SUBSYSTEM=scsi_disk" parseLine: "PHYSDEVPATH=/devices/platform/tcc-ohci/usb1/1-1/1-1.2/1-1.2:1.0/host5/target5:0:0/5:0:0:0" parseLine: "PHYSDEVBUS=scsi" parseLine: "PHYSDEVDRIVER=sd" parseLine: "SEQNUM=773" parseDeviceInfo: "read fro socket 246 bytes" parseLine: "remove@/block/sdc/sdc1" parseLine: "ACTION=remove" parseLine: "DEVPATH=/block/sdc/sdc1" parseLine: "SUBSYSTEM=block" parseLine: "MAJOR=8" parseLine: "MINOR=33" parseLine: "DEVTYPE=partition" parseLine: "PHYSDEVPATH=/devices/platform/tcc-ohci/usb1/1-1/1-1.2/1-1.2:1.0/host5/target5:0:0/5:0:0:0" parseLine: "PHYSDEVBUS=scsi" parseLine: "PHYSDEVDRIVER=sd" parseLine: "SEQNUM=774" parseDeviceInfo: "read fro socket 86 bytes" parseLine: "remove@/class/bdi/8:32" parseLine: "ACTION=remove" parseLine: "DEVPATH=/class/bdi/8:32" parseLine: "SUBSYSTEM=bdi" parseLine: "SEQNUM=775" parseDeviceInfo: "read fro socket 231 bytes" parseLine: "remove@/block/sdc" parseLine: "ACTION=remove" parseLine: "DEVPATH=/block/sdc" parseLine: "SUBSYSTEM=block" parseLine: "MAJOR=8" parseLine: "MINOR=32" parseLine: "DEVTYPE=disk" parseLine: "PHYSDEVPATH=/devices/platform/tcc-ohci/usb1/1-1/1-1.2/1-1.2:1.0/host5/target5:0:0/5:0:0:0" parseLine: "PHYSDEVBUS=scsi" parseLine: "PHYSDEVDRIVER=sd" parseLine: "SEQNUM=776" parseDeviceInfo: "read fro socket 268 bytes" parseLine: "remove@/devices/platform/tcc-ohci/usb1/1-1/1-1.2/1-1.2:1.0/host5/target5:0:0/5:0:0:0" parseLine: "ACTION=remove" parseLine: "DEVPATH=/devices/platform/tcc-ohci/usb1/1-1/1-1.2/1-1.2:1.0/host5/target5:0:0/5:0:0:0" parseLine: "SUBSYSTEM=scsi" parseLine: "DEVTYPE=scsi_device" parseLine: "PHYSDEVBUS=scsi" parseLine: "MODALIAS=scsi:t-0x00" parseLine: "SEQNUM=777" parseDeviceInfo: "read fro socket 211 bytes" parseLine: "remove@/class/scsi_host/host5" parseLine: "ACTION=remove" parseLine: "DEVPATH=/class/scsi_host/host5" parseLine: "SUBSYSTEM=scsi_host" parseLine: "PHYSDEVPATH=/devices/platform/tcc-ohci/usb1/1-1/1-1.2/1-1.2:1.0" parseLine: "PHYSDEVBUS=usb" parseLine: "PHYSDEVDRIVER=usb-storage" parseLine: "SEQNUM=778" parseDeviceInfo: "read fro socket 300 bytes" parseLine: "remove@/devices/platform/tcc-ohci/usb1/1-1/1-1.2/1-1.2:1.0" parseLine: "ACTION=remove" parseLine: "DEVPATH=/devices/platform/tcc-ohci/usb1/1-1/1-1.2/1-1.2:1.0" parseLine: "SUBSYSTEM=usb" parseLine: "DEVTYPE=usb_interface" parseLine: "PHYSDEVBUS=usb" parseLine: "PRODUCT=125f/312a/a00" parseLine: "TYPE=0/0/0" parseLine: "INTERFACE=8/6/80" parseLine: "MODALIAS=usb:v125Fp312Ad0A00dc00dsc00dp00ic08isc06ip50" parseLine: "SEQNUM=779" parseDeviceInfo: "read fro socket 239 bytes" parseLine: "remove@/class/usb_endpoint/usbdev1.5_ep00" parseLine: "ACTION=remove" parseLine: "DEVPATH=/class/usb_endpoint/usbdev1.5_ep00" parseLine: "SUBSYSTEM=usb_endpoint" parseLine: "MAJOR=253" parseLine: "MINOR=22" parseLine: "PHYSDEVPATH=/devices/platform/tcc-ohci/usb1/1-1/1-1.2" parseLine: "PHYSDEVBUS=usb" parseLine: "PHYSDEVDRIVER=usb" parseLine: "SEQNUM=780" parseDeviceInfo: "read fro socket 245 bytes" parseLine: "remove@/devices/platform/tcc-ohci/usb1/1-1/1-1.2" parseLine: "ACTION=remove" parseLine: "DEVPATH=/devices/platform/tcc-ohci/usb1/1-1/1-1.2" parseLine: "SUBSYSTEM=usb" parseLine: "MAJOR=189" parseLine: "MINOR=4" parseLine: "DEVTYPE=usb_device" parseLine: "PHYSDEVBUS=usb" parseLine: "PRODUCT=125f/312a/a00" parseLine: "TYPE=0/0/0" parseLine: "BUSNUM=001" parseLine: "DEVNUM=005" parseLine: "SEQNUM=781"