com<T extends IUnknown> method

T com<T extends IUnknown>(
  1. GUID clsid
)

Creates a new COM object and binds its lifetime to this Arena.

This is a convenience wrapper around CoCreateInstance that:

  • Creates the COM object
  • Transfers ownership of the initial reference to the arena
  • Ensures release is called exactly once when the arena is disposed

The returned interface is safe to use for the duration of the arena scope, and must not be manually released by the caller.

Example:

using((arena) {
  // Create a COM object whose initial reference is owned by the arena.
  final dialog = arena.com<IFileOpenDialog>(FileOpenDialog);

  // Use the interface normally.
  dialog.setTitle(arena.pcwstr('Select a file'));

  // No explicit release call is required.
  // The arena will call release on `dialog` when this block exits.
});

Throws a WindowsException if CoCreateInstance fails.

Implementation

T com<T extends IUnknown>(GUID clsid) => adopt(
  CoCreateInstance<T>(clsid.toNative(allocator: this), null, CLSCTX_ALL),
);