hi,my dear friends:
I have a problem on usb camera device enumerate,my usb device usually run well.but when my usb device is running,and
then i disconnect the usb line, then i plug into usb line again,at this time ,the camera also can run.but when I turn off
the camera application pragram,and then I run the application pragram again,at this time I can not enumerate the camera
device,but I check in the device manager,find the device correctly.
and this also happened when the application suddenly have a mistake,in this time ,i turn off the application program,and
then i run the application program again, and i can not enumerate the camera device,but in device manager,I can see the
camera device.
the method for my camera enumeration as follows, firstly ,I use SetupDiGetClassDevs to get the device information,and
then use SetupDiEnumDeviceInterfaces to get the device path, at last time ,i use it to compare with my device PID and VID,
if it is equal, it shows the device is our enumerate device.
but when it can not enumerate,I find the function SetupDiEnumDeviceInterfaces return flase,but I the device correctly in
the windows device manager.I don’t know what causes this. is it the method of my enumeration have some bug? is there any
other mothod to enumerate device? thank you.
my code of enumeration as follows:
Device_ERROR CDevice::GetDevice(DWORD instance,
PTCHAR pVID_PID,
PTCHAR pPath,
DWORD dwLen,
PDWORD pLength)
{
if(pLength != NULL)*pLength = 0; // Initialization
HDEVINFO info = SetupDiGetClassDevs((LPGUID)&ClassGuid,
NULL,
NULL,
DIGCF_PRESENT|DIGCF_DEVICEINTERFACE);
if(info==INVALID_HANDLE_VALUE)
{
SetupDiDestroyDeviceInfoList(info);
return E_DEV_NO_INFO;
}
// Get interface data for the requested instance
SP_DEVICE_INTERFACE_DATA intf_data;
intf_data.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
if(!SetupDiEnumDeviceInterfaces(info,
NULL,
(LPGUID)&ClassGuid,
instance,
&intf_data))
{
SetupDiDestroyDeviceInfoList(info);
return E_DEV_INVALID_INST;
}
// Get size of symbolic link
DWORD ReqLen;
SetupDiGetDeviceInterfaceDetail(info, &intf_data, NULL, 0, &ReqLen, NULL);
PSP_DEVICE_INTERFACE_DETAIL_DATA intf_detail = \
(PSP_DEVICE_INTERFACE_DETAIL_DATA)(new char[ReqLen]);
if( intf_detail == NULL)
{
SetupDiDestroyDeviceInfoList(info);
delete intf_detail;
return E_DEV_NO_INFO;
}
// Get symbolic link name
intf_detail->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
if(!SetupDiGetDeviceInterfaceDetail(info,
&intf_data,
intf_detail,
ReqLen,
NULL,
NULL))
{
SetupDiDestroyDeviceInfoList(info);
delete intf_detail;
return E_DEV_NO_INFO;
}
// Check for a valid VID&PID - if argument is not null)
if(pVID_PID != NULL)
{
if(IsVidPidEqual(intf_detail->DevicePath,pVID_PID) == E_FALSE)
{
SetupDiDestroyDeviceInfoList(info);
delete intf_detail;
return E_DEV_VIDPID_NOT_FOUND;
}
}
// Set the length of the path string
if(pLength != NULL)
*pLength = (DWORD)strlen(intf_detail->DevicePath);
// Copy output string path to buffer pointed to by pPath
if(pPath != NULL)
{
// Check that input buffer has enough room…
// Use > not >= because strlen does not include null
if(dwLen > strlen(intf_detail->DevicePath))
strcpy(pPath, intf_detail->DevicePath);
else
{
SetupDiDestroyDeviceInfoList(info);
delete intf_detail;
return E_FALSE;
}
}
// Clean up
SetupDiDestroyDeviceInfoList(info);
delete intf_detail;
return E_OK;
}
thank you very much indeed.