bindToObject<T extends IUnknown> method
Binds to the specified object.
The binding process involves finding the object, putting it into the running state if necessary, and providing the caller with a pointer to a specified interface on the identified object.
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-bindtoobject.
Implementation
T bindToObject<T extends IUnknown>(IBindCtx? pbc, IMoniker? pmkToLeft) {
final companion = ComInterface.type<T>();
final riidResult = companion.iid.toNative();
final ppvResult = adaptiveCalloc<Pointer>();
final hr$ = HRESULT(
_BindToObjectFn(
ptr,
pbc?.ptr ?? nullptr,
pmkToLeft?.ptr ?? nullptr,
riidResult,
ppvResult,
),
);
free(riidResult);
if (hr$.isError) {
free(ppvResult);
throw WindowsException(hr$);
}
final result = companion.fromPointer(ppvResult.value.cast());
free(ppvResult);
return result;
}