WindowsCreateString function winrt

HSTRING WindowsCreateString(
  1. PCWSTR? sourceString,
  2. int length
)

Creates a new HSTRING based on the specified source string.

Throws a WindowsException on failure.

To learn more, see learn.microsoft.com/windows/win32/api/winstring/nf-winstring-windowscreatestring.

Implementation

HSTRING WindowsCreateString(PCWSTR? sourceString, int length) {
  final string = adaptiveCalloc<Pointer>();
  final hr$ = HRESULT(
    _WindowsCreateString(sourceString ?? nullptr, length, string),
  );
  if (hr$.isError) {
    free(string);
    throw WindowsException(hr$);
  }
  final result$ = string.value;
  free(string);
  return .new(result$);
}