getDevice method

IMMDevice? getDevice(
  1. PCWSTR pwstrId
)

Retrieves an audio endpoint device that is identified by an endpoint ID string.

Throws a WindowsException on failure.

To learn more, see learn.microsoft.com/windows/win32/api/mmdeviceapi/nf-mmdeviceapi-immdeviceenumerator-getdevice.

Implementation

IMMDevice? getDevice(PCWSTR pwstrId) {
  final ppDevice = adaptiveCalloc<VTablePointer>();
  final hr$ = HRESULT(_GetDeviceFn(ptr, pwstrId, ppDevice));
  if (hr$.isError) {
    free(ppDevice);
    throw WindowsException(hr$);
  }
  final result$ = ppDevice.value;
  free(ppDevice);
  if (result$.isNull) return null;
  return .new(result$);
}