execNotificationQuery method

IEnumWbemClassObject? execNotificationQuery(
  1. BSTR strQueryLanguage,
  2. BSTR strQuery,
  3. WBEM_GENERIC_FLAG_TYPE lFlags,
  4. IWbemContext? pCtx,
)

Executes a query to receive events.

The call returns immediately, and the user can poll the returned enumerator for events as they arrive. Releasing the returned enumerator cancels the query.

Throws a WindowsException on failure.

To learn more, see learn.microsoft.com/windows/win32/api/wbemcli/nf-wbemcli-iwbemservices-execnotificationquery.

Implementation

IEnumWbemClassObject? execNotificationQuery(
  BSTR strQueryLanguage,
  BSTR strQuery,
  WBEM_GENERIC_FLAG_TYPE lFlags,
  IWbemContext? pCtx,
) {
  final ppEnum = adaptiveCalloc<VTablePointer>();
  final hr$ = HRESULT(
    _ExecNotificationQueryFn(
      ptr,
      strQueryLanguage,
      strQuery,
      lFlags,
      pCtx?.ptr ?? nullptr,
      ppEnum,
    ),
  );
  if (hr$.isError) {
    free(ppEnum);
    throw WindowsException(hr$);
  }
  final result$ = ppEnum.value;
  free(ppEnum);
  if (result$.isNull) return null;
  return .new(result$);
}