Home > Software engineering >  Monitoring plug USB devices
Monitoring plug USB devices

Time:09-26

MFC, GUID in the registry to find the equipment ({eb781aaf - 9 c70-4523 - a87eca567 a5df - 642}), code changes become
Static const GUID GUID_DEVINTERFACE_LIST []={0 xeb781aaf, 0 x9c70, 0 x4523, {x64 xa5 0, 0 XDF, 0, 0 x2a, 0 x87, 0 xec, 0 xa5, 0 x67}};
Registered under the Mainframe OnCreate
 HDEVNOTIFY HDEVNOTIFY; 
DEV_BROADCAST_DEVICEINTERFACE NotificationFilter;
ZeroMemory (& amp; NotificationFilter, sizeof (NotificationFilter));
NotificationFilter. Dbcc_size=sizeof (DEV_BROADCAST_DEVICEINTERFACE);
NotificationFilter. Dbcc_devicetype=DBT_DEVTYP_DEVICEINTERFACE;
for(int i=0; i{
NotificationFilter. Dbcc_classguid=GUID_DEVINTERFACE_LIST [I];
HDevNotify=RegisterDeviceNotification (this - & gt; GetSafeHwnd (), & amp; NotificationFilter DEVICE_NOTIFY_WINDOW_HANDLE);
if( ! HDevNotify)
{
AfxMessageBox (cstrings (" Can 't register device notification: ")
+ _com_error (GetLastError ()). ErrorMessage (), MB_ICONEXCLAMATION);
Return FALSE;
}
}

Add the WM_DEVICECHANGE response function
 LRESULT CMainFrame: : OnMyDeviceChange (WPARAM WPARAM, LPARAM LPARAM) 
{
If (DBT_DEVICEARRIVAL==wParam | | DBT_DEVICEREMOVECOMPLETE==wParam) {
PDEV_BROADCAST_HDR pHdr=(lParam PDEV_BROADCAST_HDR);
PDEV_BROADCAST_DEVICEINTERFACE pDevInf;
PDEV_BROADCAST_HANDLE pDevHnd;
PDEV_BROADCAST_OEM pDevOem;
PDEV_BROADCAST_PORT pDevPort;
PDEV_BROADCAST_VOLUME pDevVolume;
The switch (pHdr - & gt; Dbch_devicetype) {
Case DBT_DEVTYP_DEVICEINTERFACE:
{
//need operation

}
break;

Case DBT_DEVTYP_HANDLE:
PDevHnd=(PDEV_BROADCAST_HANDLE pHdr);
break;

Case DBT_DEVTYP_OEM:
PDevOem=(PDEV_BROADCAST_OEM pHdr);
break;

Case DBT_DEVTYP_PORT:
PDevPort=(PDEV_BROADCAST_PORT pHdr);
break;

Case DBT_DEVTYP_VOLUME:
PDevVolume=(PDEV_BROADCAST_VOLUME pHdr);
break;
}
}
return 0;
}

equipment are plug, wParam is 7, could you tell me this is not registered under the USB message

CodePudding user response:

Sorry didn't have written such hardware detection code, but since when equipment plug, you can see whether wParam is 7 is a response to the news.
Only DBT_DEVICEARRIVAL device driver is already installed and available DBT_DEVICEREMOVECOMPLETE removal equipment for processing events, I can't find these macros F12 positioning here... I do not know how much value...

CodePudding user response:

reference 1st floor u014494506 response:
sorry didn't have written such hardware detection code, but since when equipment plug, you can see whether wParam is 7 is a response to the news.
Only DBT_DEVICEARRIVAL device driver is already installed and available DBT_DEVICEREMOVECOMPLETE removal equipment for processing events, I can't find these macros F12 positioning here... I do not know how much value...


Ok, thank you,,,
I see other document said wParam is 7, is RegisterDeviceNotification didn't get to, I think so, because I block out the code inside OnCreate and wParam is 7

CodePudding user response:

DBT_DEVNODES_CHANGED 0 x0007

I used before HID all seem to is the news, the news is to scan all the equipment, compare the equipment information change

CodePudding user response:

The
reference 3 floor zgl7903 response:
DBT_DEVNODES_CHANGED 0 x0007

I used before HID all seem to is the news, the news is to scan all the equipment, compare the equipment information change


Under the detailed said? thank you

CodePudding user response:

Baidu search "DBT_DEVNODES_CHANGED"
  • Related