getNamedStringOrDefault method

String getNamedStringOrDefault(
  1. String name,
  2. String defaultValue
)

Implementation

String getNamedStringOrDefault(String name, String defaultValue) {
  final retValuePtr = calloc<HSTRING>();
  final nameHstring = convertToHString(name);
  final defaultValueHstring = convertToHString(defaultValue);

  try {
    final hr = ptr.ref.vtable
            .elementAt(8)
            .cast<
                Pointer<
                    NativeFunction<
                        HRESULT Function(Pointer, IntPtr name,
                            IntPtr defaultValue, Pointer<IntPtr>)>>>()
            .value
            .asFunction<
                int Function(
                    Pointer, int name, int defaultValue, Pointer<IntPtr>)>()(
        ptr.ref.lpVtbl, nameHstring, defaultValueHstring, retValuePtr);

    if (FAILED(hr)) throw WindowsException(hr);

    final retValue = retValuePtr.toDartString();
    return retValue;
  } finally {
    WindowsDeleteString(nameHstring);
    WindowsDeleteString(defaultValueHstring);
    WindowsDeleteString(retValuePtr.value);
    free(retValuePtr);
  }
}