Index: RS232Layer.cpp =================================================================== --- RS232Layer.cpp (revision 5322) +++ RS232Layer.cpp (working copy) @@ -832,6 +832,11 @@ // Depends on the wParam we don't need all classes ;-) DWORD dwFlag = DBT_DEVICEARRIVAL != wParam ? DIGCF_ALLCLASSES : (DIGCF_ALLCLASSES | DIGCF_PRESENT); + CString szBaseDevice = szDevId; + + if(szBaseDevice.Mid(szBaseDevice.GetLength() - 2, 2) == _T("\\0")) + szBaseDevice = szDevId.Mid(0, szBaseDevice.GetLength() - 2); + // Get and check handle to the device class if(NULL != (hDevInfo = SetupDiGetClassDevs(NULL,szClass,NULL,dwFlag))) { @@ -845,11 +850,15 @@ // Get device id if( !SetupDiGetDeviceInstanceId(hDevInfo, &spDevInfoData, buf, sizeof(buf), &nSize) ) break; + // Check, that the found device is our device - if ( szDevId == buf ) + if( ( szDevId == buf ) || + ( 0 == _tcsncmp(szBaseDevice, buf, _tcslen(szBaseDevice))) ) { - // OK, device found - #if _DEBUG + if (spDevInfoData.ClassGuid == GUID_DEVCLASS_PORTS) + { + // OK, device found +#if _DEBUG OLECHAR* bstrGuid; StringFromCLSID(spDevInfoData.ClassGuid, &bstrGuid); TRACE("Device Class GUID: %S\r\n", bstrGuid); @@ -859,9 +868,11 @@ ::CoTaskMemFree(bstrGuid); TRACE("Device ID: %s\r\n", szDevId.GetBuffer()); TRACE("Device Class: %s\r\n", szClass.GetBuffer()); - #endif - fFound = true; - break; +#endif + + fFound = true; + break; + } } } } @@ -870,39 +881,36 @@ if(fFound) { - if (spDevInfoData.ClassGuid == GUID_DEVCLASS_PORTS) + HKEY hkDevice = SetupDiOpenDevRegKey(hDevInfo, &spDevInfoData, DICS_FLAG_GLOBAL, 0, DIREG_DEV, KEY_QUERY_VALUE); + + if (!hkDevice) { - HKEY hkDevice = SetupDiOpenDevRegKey(hDevInfo, &spDevInfoData, DICS_FLAG_GLOBAL, 0, DIREG_DEV, KEY_QUERY_VALUE); - - if (!hkDevice) - { - TRACE("SetupDiOpenDevRegKey() failed - lRet = 0x%08x\r\n", GetLastError()); + TRACE("SetupDiOpenDevRegKey() failed - lRet = 0x%08x\r\n", GetLastError()); - } else - { + } else + { - TCHAR szName[MAX_PATH]; - DWORD dwLen = sizeof(szName); - LONG lRegRet = ERROR_SUCCESS; + TCHAR szName[MAX_PATH]; + DWORD dwLen = sizeof(szName); + LONG lRegRet = ERROR_SUCCESS; - // Init the string - szDeviceName.assign("UNKNOWN"); - - // Get value from the registry - if( ERROR_SUCCESS == (lRegRet = ::RegQueryValueEx( hkDevice, _T("Portname"),NULL, - NULL,(BYTE*)szName, &dwLen)) ) - { - // Set device name - szDeviceName = szName; - fRet = true; - } - - TRACE("Interface name: %s (Error = 0x%08x)\r\n", szDeviceName.c_str(), lRegRet); + // Init the string + szDeviceName.assign("UNKNOWN"); + + // Get value from the registry + if( ERROR_SUCCESS == (lRegRet = ::RegQueryValueEx( hkDevice, _T("Portname"),NULL, + NULL,(BYTE*)szName, &dwLen)) ) + { + // Set device name + szDeviceName = szName; + fRet = true; + } + + TRACE("Interface name: %s (Error = 0x%08x)\r\n", szDeviceName.c_str(), lRegRet); - // Close Reg Key - ::RegCloseKey(hkDevice); - } - } + // Close Reg Key + ::RegCloseKey(hkDevice); + } } return fRet;