toInterface method Null safety

Pointer<COMObject> toInterface(
  1. String iid

Cast an existing COM object to a specified interface.

Takes a string (typically a constant such as IID_IModalWindow) and does a COM QueryInterface to return a reference to that interface. This method reduces the boilerplate associated with calling QueryInterface manually.


Pointer<COMObject> toInterface(String iid) {
  final pIID = convertToIID(iid);
  final pObject = calloc<COMObject>();
  try {
    final hr = QueryInterface(pIID, pObject.cast());
    if (FAILED(hr)) throw WindowsException(hr);
    return pObject;
  } finally {