SHCreateItemFromParsingName<T extends IUnknown> function shell32

T SHCreateItemFromParsingName<T extends IUnknown>(
  1. PCWSTR pszPath,
  2. IBindCtx? pbc
)

Creates and initializes a Shell item object from a parsing name.

This method uses the ComInterface.type method to retrieve metadata about the target interface defined by T, including its IID (Interface ID) and instantiation logic.

All COM interfaces provided by this package are pre-registered. Custom COM interfaces must be registered manually using the ComInterface.register method before calling this method.

Throws a WindowsException on failure.

To learn more, see learn.microsoft.com/windows/win32/api/shobjidl_core/nf-shobjidl_core-shcreateitemfromparsingname.

Implementation

T SHCreateItemFromParsingName<T extends IUnknown>(
  PCWSTR pszPath,
  IBindCtx? pbc,
) {
  final companion = ComInterface.type<T>();
  final riid = companion.iid.toNative();
  final ppv = adaptiveCalloc<Pointer>();
  final hr$ = HRESULT(
    _SHCreateItemFromParsingName(pszPath, pbc?.ptr ?? nullptr, riid, ppv),
  );
  free(riid);
  if (hr$.isError) {
    free(ppv);
    throw WindowsException(hr$);
  }
  final result = companion.fromPointer(ppv.value.cast());
  free(ppv);
  return result;
}