I am able to get the device interface and print out the device path but when I put in the device path as a parameter for create file, the program crashes at the point where it should create the file with the error 0xC0000005.
I have a Windows 7 64 bit computer, I am trying to connect to read data from this USB webcam specifically
Docooler USB 2.0 12 Megapixel HD Camera Web Cam with MIC Clip-on[
^]
Here is the code that I am using.
I am automatically setting the required Interface detail size to 90 because the highest is 82
I also have if(i == 2) because that is when the devicepath for the camera prints out.
i= 0;
if((webdevices = SetupDiGetClassDevs(&GUID_DEVINTERFACE_USB_DEVICE,NULL,NULL,(DIGCF_PRESENT|DIGCF_DEVICEINTERFACE))) != NULL){
printf("SetupDiGetClassDevs Worked!!\n");
}else{
printf("SetupDiGetClassDevs didn't work error %d\n",GetLastError());
}
webDevInfoDat->cbSize = sizeof(SP_DEVINFO_DATA);
webInterDat->cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
SetupDiEnumDeviceInfo(webdevices,i,webDevInfoDat);
while(sdei = SetupDiEnumDeviceInterfaces(webdevices,NULL,&GUID_DEVINTERFACE_USB_DEVICE,i,webInterDat)){ if(SetupDiGetDeviceInterfaceDetail(webdevices,webInterDat,webInterDetDat,interDetSiz,&reqInterDetSiz,webDevInfoDat)){
printf("Interface Detail Data\nDevicePath: %s\nRequired Size: %d\n",webInterDetDat->DevicePath,reqInterDetSiz);
}else{
printf("Getting SetupDiGetDeviceDetail error %d RequiredSize %d\n",GetLastError(),reqInterDetSiz);
}
if(i == 2){
webcam = CreateFile(webInterDetDat->DevicePath,(GENERIC_READ|GENERIC_WRITE),(FILE_SHARE_READ|FILE_SHARE_WRITE),NULL,OPEN_EXISTING,0,NULL);
if(webcam == INVALID_HANDLE_VALUE){
printf("Creating File didn't work %d\n",GetLastError());
}else{
printf("Creating File did work %s\n",webcam);
close(webcam);
}
}
printf("\n");
i++;
webInterDat->cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
}
if(sdei){
}else{
printf("Getting SetupDiEnumDeviceInterfaces error %d I is %d\n",GetLastError(), i);
}
What I have tried:
I have tried keeping it to the A-methods then tried changing it to the wide methods.
I have tried changing the '?' to a '.'. Then I tried adding in "\\\\.\\" and "\\\\?\\" and that still didn't work.
When I comment out the create file method it works perfectly and reaches to the end of the program with no errors.