If the USB device has been unplugged, your handle will be invalid, there is nothing to do!
I would put the CloseHandle in try/catch block and set the handle to INVALID_HANDLE if it fails.
Try something like this:
HANDLE hDevice = CreateFile("\\\\.\\dev_name",
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
try
{
if (hDevice != INVALID_HANDLE_VALUE)
CloseHandle(hDevice);
}
catch(...)
{
hDevice = INVALID_HANDLE_VALUE;
}