Received Error code 6 when calling ::DeviceIoControl with command CTL_CODE(FILE_DEVICE_UNKNOWN, IOCTL_USB_INDEX(0x0000) + 4, METHOD_BUFFERED, FILE_ANY_ACCESS) on windows 10. Getting error on windows 10 version 1809 but same code was/is working on windows 10 version 1803. Is there any change in windows 10 patches? I am communicating with hardware on USB port.
Asked
Active
Viewed 325 times
0
-
6 is "the handle is invalid". Where did you get the handle? Did you check the return code to make sure that step was successful? – Ben Mar 05 '19 at 15:06
-
What is the hex value of the handle in the debugger? All zeros and all Fs are invalid values for USB objects. – Ben Mar 05 '19 at 15:12
-
I got the handle from call to ::CreateFile(). The thing is, command failure is 'Random'. Its do get success for few time and then fails for few times. In one button click, i call ::CreateFile() and ::DeviceIoControl(IOCTL_UAUSB_REGISTER_DATA_RX_NOTIFY_EVENT) 4 times. Out of 4, it fails at any time, but other calls with same CTL code gets success – Imrankhan Pathan Mar 06 '19 at 07:53
-
Do you check the return from CreateFile to make sure it is successful? What is the hex value of the handle in the debugger? – Ben Mar 06 '19 at 09:49
-
Do you close the handle each time? Why do you call createfile every time? Why not call it once and save the handle? – Ben Mar 06 '19 at 09:49
-
CreateFile returns is successful every time, its value is within 1 to 1000 hex (its random, can't mention specific value). Yes I am closing handle every time. Can't save handle as its within another library and i am calling loadlibrary() 4 times. – Imrankhan Pathan Mar 07 '19 at 05:25
-
OK 6 = ERROR_INVALID_HANDLE can mean "this is not a handle" but can also mean "this handle is not valid for this operation". This might be because it isn't opened with the correct permissions, or because the object doesn't support the operation, or because the object is not in the correct state for the operation. State might mean: You can only do this when not connected/or only when connected, or you can only do this once and it has already been done. To get more help, you have to tell more about what the device is and what you are trying to do. – Ben Mar 07 '19 at 10:02
-
Hi Ben, I got to work with driver code of device that i am using, and found that Windows Kernel function ObReferenceObjectByHandle() (in wdm.h) fails randomly with return value STATUS_INVALID_HANDLE. This fails only in Win10 ver 1809 and not in prior versions. I tried to find solutions on Google but could not understand it as DeviceDriver programming is foreign to me. – Imrankhan Pathan May 21 '19 at 13:08
-
What is the numeric value of the handle in the debugger? – Ben May 22 '19 at 15:49