Hi Debasisdas
The following is the way i have tried
DEFINE_GUID(USBIODS_GUID,0x1f537664, 0x37a9, 0x48c1, 0x96, 0xe7, 0x1a, 0x8a, 0x18, 0x48, 0x41, 0xfd);
// {1F537664-37A9-48c1-96E7-1A8A184841FD}
HDEVINFO hInfo = SetupDiGetClassDevs((struct _GUID *)&USBIODS_GUID, NULL, NULL, DIGCF_PRESENT | DIGCF_INTERFACEDEVICE);
int i;
char *Devices[10]; // an array of cstrings
char name[150];
for ( i=0; ; ++i)
{
SP_INTERFACE_DEVICE_DATA Interface_Info;
Interface_Info.cbSize = sizeof(Interface_Info);
// Enumerate device
if (!SetupDiEnumInterfaceDevice(hInfo, NULL, (LPGUID)
&USBIODS_GUID,i, &Interface_Info))
{
SetupDiDestroyDeviceInfoList(hInfo);
return(i);
}
DWORD needed; // get the required lenght
SetupDiGetInterfaceDeviceDetail(hInfo, &Interface_Info,
NULL, 0, &needed, NULL);
PSP_INTERFACE_DEVICE_DETAIL_DATA detail = (PSP_INTERFACE_DEVICE_DETAIL_DATA) malloc(needed);
if (!detail)
{
SetupDiDestroyDeviceInfoList(hInfo);
return(i);
}
detail->cbSize =
sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA);
if (!SetupDiGetInterfaceDeviceDetail(hInfo,&Interface _Info,detail, needed,NULL, NULL))
{
free((PVOID) detail);
SetupDiDestroyDeviceInfoList(hInfo);
return(i);
}
strncpy(name, detail->DevicePath, sizeof(name));
free((PVOID) detail);
strcpy(Devices[i],name); // keep a copy of each device name
printf("%s", name);
}
HANDLE hUsbDevice = CreateFile(name, GENERIC_READ |GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
}
This is the way i have used, kindly suggest any changes to be done for the same as the
if (!SetupDiEnumInterfaceDevice(hInfo, NULL, (LPGUID)
&USBIODS_GUID,i, &Interface_Info))
is failing and entering the if condition in the code