Code: Select all
BOOL sub_device(HDEVINFO hSubDevInfo, wchar_t* id, LPWSTR tDeviceDesc, LPWSTR tService, LPWSTR tDriverVersion)
{
SP_DEVINFO_DATA DeviceInfoData;
WCHAR Buff_InstanceId[MAX_PATH] = L"";
DEVPROPTYPE dpt = 0;
for (UINT index = 0; ; index++) {
DeviceInfoData.cbSize = sizeof(DeviceInfoData);
if (!SetupDiEnumDeviceInfo(hSubDevInfo, index, &DeviceInfoData))
{
return FALSE;
}
if (!SetupDiGetDevicePropertyW(hSubDevInfo, &DeviceInfoData, &DEVPKEY_Device_InstanceId, &dpt, (PBYTE)Buff_InstanceId, sizeof(Buff_InstanceId), NULL, 0))
{
continue;
}
if (StrCmpIW(Buff_InstanceId, id) == 0)
{
tDeviceDesc[0] = 0;
tService[0] = 0;
tDriverVersion[0] = 0;
SetupDiGetDevicePropertyW(hSubDevInfo, &DeviceInfoData, &DEVPKEY_Device_DeviceDesc, &dpt, (PBYTE)tDeviceDesc, 100*2, NULL, 0);
SetupDiGetDevicePropertyW(hSubDevInfo, &DeviceInfoData, &DEVPKEY_Device_Service, &dpt, (PBYTE)tService, 100*2, NULL, 0);
SetupDiGetDevicePropertyW(hSubDevInfo, &DeviceInfoData, &DEVPKEY_Device_DriverVersion, &dpt, (PBYTE)tDriverVersion, 50*2, NULL, 0);
return TRUE;
}
}
return FALSE;
}
// -1 = тюнер не опознан, или может это астромета-135 (а не 131)
// 0 = тюнер в режиме SDR, надо вывести предупреждение пользователю типа «BDA устройство не запущено потому что тюнер в режиме SDR»
// 1 = тюнер в режиме DVB
INT IsDVBmodeAstrometa131()
{
WCHAR text_tuner0131_DeviceDesc[100] = { 0 };
WCHAR text_tuner0131_Service[100] = { 0 };
WCHAR text_tuner0131_DriverVersion[50] = { 0 };
INT result = -1;
HDEVINFO hDevInfo;
SP_DEVICE_INTERFACE_DATA DeviceInterfaceData;
BYTE DeviceInterfaceDetailDataB[MAX_PATH * 2 + 100];
SP_DEVICE_INTERFACE_DETAIL_DATA* DeviceInterfaceDetailData = reinterpret_cast<SP_DEVICE_INTERFACE_DETAIL_DATA*>(DeviceInterfaceDetailDataB);
DEVPROPTYPE dpt = 0;
WCHAR ChildrenListBuffer[1000];
SP_DEVINFO_DATA DeviceInfo;
HDEVINFO hSubDevInfo;
hDevInfo = SetupDiGetClassDevsW(&(GUID_DEVINTERFACE_USB_DEVICE), 0, 0, DIGCF_DEVICEINTERFACE | DIGCF_ALLCLASSES); // корневые (композитные/составные) устройства
if (hDevInfo != INVALID_HANDLE_VALUE)
{
hSubDevInfo = SetupDiGetClassDevsW(&(GUID_DEVINTERFACE_USB_DEVICE), L"USB", NULL, DIGCF_ALLCLASSES); // все устройства включая дочерние устройства
if (hSubDevInfo != INVALID_HANDLE_VALUE)
{
for (UINT index = 0; ; index++)
{
DeviceInterfaceData.cbSize = sizeof(DeviceInterfaceData);
if (!SetupDiEnumDeviceInterfaces(hDevInfo, 0, &(GUID_CLASS_USB_DEVICE), index, &DeviceInterfaceData))
{
break;
}
DeviceInterfaceDetailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
DeviceInterfaceDetailData->DevicePath[0] = 0;
DeviceInfo.cbSize = sizeof(DeviceInfo);
if (SetupDiGetDeviceInterfaceDetailW(hDevInfo, &DeviceInterfaceData, DeviceInterfaceDetailData, sizeof(DeviceInterfaceDetailDataB), 0, &DeviceInfo))
{
if (StrCmpNIW(DeviceInterfaceDetailData->DevicePath, L"\\\\?\\usb#vid_15f4&pid_0131#", 26) == 0)
{
ChildrenListBuffer[0] = 0;
ChildrenListBuffer[1] = 0;
if (SetupDiGetDevicePropertyW(hDevInfo, &DeviceInfo, &DEVPKEY_Device_Children, &dpt, (PBYTE)ChildrenListBuffer, sizeof(ChildrenListBuffer), NULL, 0))
{
flag_tuner0131_present = 1;
wchar_t* p = ChildrenListBuffer;
while (true) {
if (p[0] == 0) break;
if (StrCmpNIW(p, L"USB\\VID_15F4&PID_0131&MI_00\\", 28) == 0)
{
if (sub_device(hSubDevInfo, p, text_tuner0131_DeviceDesc, text_tuner0131_Service, text_tuner0131_DriverVersion))
{
if (StrCmpIW(text_tuner0131_Service, L"AMDVBT2USB") == 0)
{
result = 1;
}
else if (StrCmpIW(text_tuner0131_Service, L"WinUSB") == 0)
{
result = 0;
}
else
{
result = -1;
}
}
}
p += lstrlenW(p) + 1;
}
}
}
}
}
SetupDiDestroyDeviceInfoList(hSubDevInfo);
}
SetupDiDestroyDeviceInfoList(hDevInfo);
}
return result;
}