getDeviceRegistryPath static method

String getDeviceRegistryPath(
  1. int deviceIndex
)

Implementation

static String getDeviceRegistryPath(int deviceIndex) {

  // final midiClassGuid = calloc<GUID>()..ref.setGUID(MIDI_CLASS_GUID);
  // final usbClassGuid = calloc<GUID>()..ref.setGUID(USB_CLASS_GUID);
final audioClassGuid = calloc<GUID>()..ref.setGUID(AUDIO_CLASS_GUID);


  final hDevInfo = SetupDiGetClassDevs(audioClassGuid, nullptr, 0, SETUP_DI_GET_CLASS_DEVS_FLAGS.DIGCF_PRESENT | SETUP_DI_GET_CLASS_DEVS_FLAGS.DIGCF_ALLCLASSES);


  print("hdevInfo ${hDevInfo}");
  if (hDevInfo == INVALID_HANDLE_VALUE) {

    throw Exception('Failed to get device information set. Error: ${GetLastError()}');
  }

  try {
    final devInfoData = calloc<SP_DEVINFO_DATA>()..ref.cbSize = sizeOf<SP_DEVINFO_DATA>();

    for (var i = 0;; i++) {

      final result = SetupDiEnumDeviceInfo(hDevInfo, i, devInfoData);

      if (result == 0) {
        final lastError = GetLastError();
        if (lastError == WIN32_ERROR.ERROR_NO_MORE_ITEMS) {
          print("no more");
          break;
        } else {
          throw Exception('Failed to get device info. Error: $lastError');
        }
      }


      final deviceInstanceId = _getDeviceInstanceId(hDevInfo, devInfoData);
      final deviceDescription = _getDeviceDescription(hDevInfo, devInfoData);

      print("[$i] deviceInstanceId $deviceInstanceId deviceDescription $deviceDescription");

      calloc.free(devInfoData);

      return "$deviceInstanceId - $deviceDescription";
    }

    throw Exception('No Device registery property found');
  } finally {
    SetupDiDestroyDeviceInfoList(hDevInfo);
  }
}