I'm making application that listens for device notifications(through WndProc, DBT_DEVICEREMOVECOMPLETE and DBT_DEVICEARRIVAL). When I process DBT_DEVICEARRIVAL in WndProc, I get device path from PDEV_BROADCAST_DEVICEINTERFACE structure. When I try to create device handle with that path, it succeeds.
HANDLE device_handle = CreateFile(device_path.c_str(),
GENERIC_WRITE | GENERIC_READ,
FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE,
NULL,
OPEN_EXISTING,
0,
NULL);
if (device_handle == INVALID_HANDLE_VALUE)
return false;
But when I handle DBT_DEVICEREMOVECOMPLETE, I do the same thing with PDEV_BROADCAST_DEVICEINTERFACE structure, and the path is same as in DBT_DEVICEARRIVAL, but CreateFile always returns INVALID_HANDLE_VALUE
The funniest thing is, when I try to execute in debug mode, creating device handle works normally, both from DBT_DEVICEARRIVAL and DBT_DEVICEREMOVECOMPLETE.
I would appreciate any help.
DBT_DEVICEREMOVECOMPLETEevent imply that the device has been removed? If so I would expect an attempt to open the device that is no more to fail. - IInspectableDBT_DEVICEREMOVECOMPLETEcome - device already removed and name not valid. so must be error file not found - RbMmDBT_DEVICEQUERYREMOVEorDBT_DEVICEREMOVEPENDING? Why do you need to wait until the device has been completely removed from the system before getting its info? - Remy Lebeau