+#if defined(__WINDOWS__)
+static bool GetComPortFromHandle(HDEVINFO hDevHandle, PSP_DEVINFO_DATA devInfoData, char* strPortName, unsigned int iSize)
+{
+ bool bReturn(false);
+ TCHAR strRegPortName[256];
+ strRegPortName[0] = _T('\0');
+ DWORD dwSize = sizeof(strRegPortName);
+ DWORD dwType = 0;
+
+ HKEY hDeviceKey = SetupDiOpenDevRegKey(hDevHandle, devInfoData, DICS_FLAG_GLOBAL, 0, DIREG_DEV, KEY_QUERY_VALUE);
+ if (!hDeviceKey)
+ return bReturn;
+
+ // locate the PortName
+ if ((RegQueryValueEx(hDeviceKey, _T("PortName"), NULL, &dwType, reinterpret_cast<LPBYTE>(strRegPortName), &dwSize) == ERROR_SUCCESS) &&
+ (dwType == REG_SZ) &&
+ _tcslen(strRegPortName) > 3 &&
+ _tcsnicmp(strRegPortName, _T("COM"), 3) == 0 &&
+ _ttoi(&(strRegPortName[3])) > 0)
+ {
+ // return the port name
+ snprintf(strPortName, iSize, "%s", strRegPortName);
+ bReturn = true;
+ }
+
+ RegCloseKey(hDeviceKey);
+
+ return bReturn;
+}
+
+static bool FindComPortForComposite(const char* strLocation, char* strPortName, unsigned int iSize)
+{
+ bool bReturn(false);
+
+ // find all devices of the CDC class
+ HDEVINFO hDevHandle = SetupDiGetClassDevs(&USB_CDC_GUID, NULL, NULL, DIGCF_PRESENT);
+ if (hDevHandle == INVALID_HANDLE_VALUE)
+ return bReturn;
+
+ // check all devices, whether they match the location or not
+ char strId[512];
+ bool bGetNext(true);
+ for (int iPtr = 0; !bReturn && bGetNext && iPtr < 1024 ; iPtr++)
+ {
+ strId[0] = 0;
+
+ SP_DEVINFO_DATA devInfoData;
+ devInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
+
+ // no more devices
+ if (!SetupDiEnumDeviceInfo(hDevHandle, iPtr, &devInfoData))
+ bGetNext = false;
+ else
+ {
+ // check if the location of the _parent_ device matches
+ DEVINST parentDevInst;
+ if (CM_Get_Parent(&parentDevInst, devInfoData.DevInst, 0) == CR_SUCCESS)
+ {
+ CM_Get_Device_ID(parentDevInst, strId, 512, 0);
+
+ // match
+ if (!strncmp(strId, strLocation, strlen(strLocation)))
+ bReturn = GetComPortFromHandle(hDevHandle, &devInfoData, strPortName, iSize);
+ }
+ }
+ }
+
+ SetupDiDestroyDeviceInfoList(hDevHandle);
+ return bReturn;
+}
+#endif
+
+uint8_t CUSBCECAdapterDetection::FindAdapters(cec_adapter_descriptor *deviceList, uint8_t iBufSize, const char *strDevicePath /* = NULL */)