Hi Tim,
Thanks for you answer.
Yes, i am creating symbolic link. Also i am generating a different name for each instance.
Please find below code of my function:
SLS_STATUS SLSUSBDev::EnumerateAllDevices()
{
HDEVINFO hDevInfo;
SP_DEVICE_INTERFACE_DATA DeviceInterfaceData;
LPGUID pGuid =(LPGUID) &GUID_CLASS_SLSUSB_BULK;
SP_DEVINFO_DATA DevInfoData;
int iIndex;
SLS_STATUS status;
hDevInfo = SetupDiGetClassDevs (
pGuid,
NULL, // Define no enumerator (global)
NULL, // Define no
(DIGCF_PRESENT | // Only Devices present
DIGCF_DEVICEINTERFACE)); // Function class devices.
if(hDevInfo == INVALID_HANDLE_VALUE)
{
CString str;
str.FormatMessage(“SetupDiGetClassDevs: Invalid Handle Getlasterror %d\n”,GetLastError());
DbgMsg(str.GetBuffer(str.GetLength()));
return SLS_DEVICE_NOT_FOUND;
}
for(iIndex=0;;iIndex++)
{
DevInfoData.cbSize = sizeof (SP_DEVINFO_DATA);
if(!SetupDiEnumDeviceInfo(hDevInfo,iIndex,&DevInfoData))
{
if(GetLastError()==ERROR_NO_MORE_ITEMS)
break;
/*CString str;
str.FormatMessage(“SetupDiEnumDeviceInfo: function fail Getlasterror %d\n”,GetLastError());
DbgMsg(str.GetBuffer(str.GetLength())); */
}
DeviceInterfaceData.cbSize = sizeof (SP_DEVICE_INTERFACE_DATA);
if (!SetupDiEnumDeviceInterfaces(hDevInfo,0,pGuid,iIndex,&DeviceInterfaceData))
{
if(GetLastError()==ERROR_NO_MORE_ITEMS)
break;
}
/* Get SerialNumber */
std::string strSerialNo = GetSerialNumber(hDevInfo,&DevInfoData);
/* Get Product Decription */
std::string strProductDescription = GetProductDescription(hDevInfo,&DevInfoData);
/* Get Device Symbolic LinkName*/
std::string strDevSymbolicLink = GetSymbolicLink(hDevInfo,&DeviceInterfaceData);
DeviceDescriptor DevDescriptor;
DevDescriptor.m_strSerialNumber = strSerialNo;
DevDescriptor.m_strProductDescription = strProductDescription;
DevDescriptor.m_strSymbolicName = strDevSymbolicLink;
m_vecDeviceDesc.push_back(DevDescriptor);
status = GetDevicePipeInfo(strDevSymbolicLink.c_str(),iIndex);
if(status != SLS_OK)
{
return SLS_IO_ERROR;
}
}
/*The SetupDiDestroyDeviceInfoList : function destroys a device information set
and frees all associated memory. */
if(!SetupDiDestroyDeviceInfoList(hDevInfo))
{
CString str;
str.FormatMessage(“SetupDiDestroyDeviceInfoList: function fail Getlasterror %d\n”,GetLastError());
DbgMsg(str.GetBuffer(str.GetLength()));
}
return SLS_OK;
}
Now when i attached another different hardware (Having a same USB chip a first hardware has), how can i know what happen on USB bus? For that i ussed one windows service which gives me some message like something is happend on USB bus. So my first application will call List device and above function is part of it. Using that i can found that my existing device disconnected or another device is connected. But for doing this i can loss my control on first hardware application. I am not doing any thing like closing the handle and ect…just i check the number of devices and base on that i am fetching descriptor value.
It is some what complicated for me to explanin but i hope this post will clear some of your doubts.
Thanks & Regards,
Tejas