WindowsCreateString function winrt
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$);
}