createFromID static method
Create an instance of a COM object using its class identifier, cast to the specified interface.
The caller is responsible for disposing of the memory of the returned
object when it is no longer required. A FFI Arena may be passed as a
custom allocator for ease of memory management.
Implementation
static Pointer<COMObject> createFromID(
String clsid,
String iid, {
Allocator allocator = calloc,
}) {
final pClsid = convertToCLSID(clsid);
final pIid = convertToIID(iid);
final pObj = allocator<COMObject>();
try {
final hr = CoCreateInstance(
pClsid,
nullptr,
CLSCTX_ALL,
pIid,
pObj.cast(),
);
if (FAILED(hr)) throw WindowsException(hr);
return pObj;
} finally {
free(pClsid);
free(pIid);
}
}