getText method

BSTR getText(
  1. int maxLength
)

Returns the plain text of the text range.

Throws a WindowsException on failure.

To learn more, see learn.microsoft.com/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextrange-gettext.

Implementation

BSTR getText(int maxLength) {
  final text = adaptiveCalloc<Pointer<Utf16>>();
  final hr$ = HRESULT(_GetTextFn(ptr, maxLength, text));
  if (hr$.isError) {
    free(text);
    throw WindowsException(hr$);
  }
  final result$ = text.value;
  free(text);
  return .new(result$);
}