Question: sumoyu () reputation: Level 100: user1 Date: 10:12:51
USB insertion or removal is monitored to obtain the drive letter. The event wm_devicechange can monitor insertion and removal, how to determine whether to insert or remove the drive letter, and how to obtain the drive letter.
Reply:
Respondent: ffsb (for petty assets) Credit: 100 level: user2 Date: 11:07:49 ID: 37208771
Form1::OnCreate //================Dev Notfi============================ DEV_BROADCAST_DEVICEINTERFACE NotificationFilter; ZeroMemory( &NotificationFilter, sizeof(NotificationFilter) ); NotificationFilter.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE); NotificationFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE; NotificationFilter.dbcc_classguid = g_UsbioID; DevNotify = RegisterDeviceNotification( Handle, &NotificationFilter, DEVICE_NOTIFY_WINDOW_HANDLE );==========================//---------------------------------------------------------------------------void __fastcall TDCForm::WMDeviceChange(TMessage & Msg){ if(Msg.WParam == DBT_DEVICEARRIVAL) { PDEV_BROADCAST_HDR hDev = (PDEV_BROADCAST_HDR)Msg.LParam; if(hDev->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE) {// Do nothing! } } else if(Msg.WParam == DBT_DEVICEREMOVECOMPLETE) { PDEV_BROADCAST_HDR hDev = (PDEV_BROADCAST_HDR)Msg.LParam; if(hDev->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE) {if(DisconnBtn->Enabled) {DisconnBtn->Click(); } } }}
Respondent: ffsb (for petty assets) Credit: 100 level: user2 Date: 11:09:09 ID: 37208826
This is a bit messy.
Respondent: sumoyu () reputation: 100 level: user1 Date: 11:12:45 ID: 37208961
Thank you! Try me
Respondent: sumoyu () reputation: 100 level: user1 Date: 11:21:04 ID: 37209265
What is g_usbioid?
Respondent: ffsb (for petty assets) Credit: 100 level: user2 Date: 11:51:19 ID: 37210214
USB hardware ID,
Respondent: sumoyu () reputation: 100 level: user1 Date: 12:42:52 ID: 37211248
How to obtain the hardware ID? During debugging, I tracked and found that MSG. wparam = dbt_devnodes_changed
Respondent: ffsb (for petty assets) Credit: 100 level: user2 Date: 14:00:41 ID: 37213378
Device_policy_window_handle ==> device_policy_window_handle | device_policy_all_interface_classes to track all USB devices.
Respondent: cczlp (not confused) reputation: 117 level: star2 Date: 14:01:41 ID: 37213414
When msg. wparam = dbt_devnodes_changed, take the number of specified devices, increase is insert, decrease is remove.
Respondent: sumoyu () reputation: 100 level: user1 Date: 15:05:05 ID: 37215482
After USB is removed, an event msg. wparam = dbt_deviceremovecomplete is generated, and an event msg. wparam = dbt_devnodes_changed is generated. After the USB is removed, the code in both events is executed (as if msg. wparam = dbt_devnodes_changed was executed first .) Also, you can use a function to obtain all USB guids.
Respondent: ffsb (for petty assets) Credit: 100 level: user2 Date: 15:31:02 ID: 37216498
Setupdixxxxx: I forgot the title. Check it.
Well, the above are all nonsense. Let's look at the masterworks:
Http://www.codeproject.com/Articles/14500/Detecting-Hardware-Insertion-and-or-Removal
Http://www.codeproject.com/Articles/119168/Hardware-Change-Detection
Generally, the imported registerdevicenotification-> GUID is not as elegant as you think. Read this blog:
Http://blogs.msdn.com/ B /doronh/archive/2006/02/15/532679.aspx