请问下mfc检测usb 插拔情况?
我设备管理中器中获取到,{b322bfc4-e924-11d2-826e-0080c8ef9f08}
static const GUID hid_guid = {0xb322bfc4, 0xe924, 0x11d2, 0x82, 0x6e, 0x00, 0x80, 0xc8, 0xef, 0x9f, 0x08};
DEV_BROADCAST_DEVICEINTERFACE dbi;
ZeroMemory(&dbi,sizeof(dbi));
dbi.dbcc_size=sizeof(dbi);
dbi.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
dbi.dbcc_reserved = 0;
dbi.dbcc_classguid = hid_guid;
HDEVNOTIFY hDevNotify;
hDevNotify = RegisterDeviceNotification(m_hWnd, &dbi, DEVICE_NOTIFY_WINDOW_HANDLE);
if(!hDevNotify)
{
int Err = GetLastError();
MessageBox("RegisterDeviceNotification failed");
}我注册消息后;
我用下面消息,检测USB插拔情况;
OnDeviceChange(
UINT nEventType,
DWORD_PTR dwData
)
怎么获取到的数据:nEventType, 一直为7,且dwData为0,这个什么回事呀?有人可以解释一下吗?
[解决办法]
#define DBT_DEVNODES_CHANGED 0x0007
DBT_DEVNODES_CHANGED Device node has changed.
这个就是说设备节点发生改变,没有什么问题
[解决办法]
我注册的GUID_DEVINTERFACE_CDROM类型
wParam 是DBT_DEVICEREMOVECOMPLETE 或DBT_DEVICEARRIVAL
lParam 可以转化成PDEV_BROADCAST_HDR,判断是否相应类型的usb设备
[解决办法]
通过RegisterDeviceNotification使窗口监控 WM_DEVICECHANGE消息。
查查7对应是下面哪个Type
DBT_DEVICEARRIVAL A device has been inserted and is now available.
DBT_DEVICEQUERYREMOVE Permission to remove a device is requested. Any application can deny this request and cancel the removal.
DBT_DEVICEQUERYREMOVEFAILED Request to remove a device has been canceled.
DBT_DEVICEREMOVEPENDING Device is about to be removed. Cannot be denied.
DBT_DEVICEREMOVECOMPLETE Device has been removed.
DBT_DEVICETYPESPECIFIC Device-specific event.
DBT_CONFIGCHANGED Current configuration has changed.
DBT_DEVNODES_CHANGED Device node has changed.