bindToStorage<T extends IUnknown> method
Binds to the storage for the specified object.
Unlike the IMoniker.bindToObject method, this method does not activate
the object identified by the moniker.
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/objidl/nf-objidl-imoniker-bindtostorage.
Implementation
T bindToStorage<T extends IUnknown>(IBindCtx? pbc, IMoniker? pmkToLeft) {
final companion = ComInterface.type<T>();
final riid = companion.iid.toNative();
final ppvObj = adaptiveCalloc<Pointer>();
final hr$ = HRESULT(
_BindToStorageFn(
ptr,
pbc?.ptr ?? nullptr,
pmkToLeft?.ptr ?? nullptr,
riid,
ppvObj,
),
);
free(riid);
if (hr$.isError) {
free(ppvObj);
throw WindowsException(hr$);
}
final result = companion.fromPointer(ppvObj.value.cast());
free(ppvObj);
return result;
}