KEMBAR78
Add option to disable default agility for COM `implement` macro by kennykerr · Pull Request #3770 · microsoft/windows-rs · GitHub
Skip to content

Conversation

@kennykerr
Copy link
Collaborator

@kennykerr kennykerr commented Sep 24, 2025

COM object implementations are agile and indicate this by implementing both IAgileObject and IMarshal. This is the default and suitable for the vast majority of implementations, whether or not you need support for COM apartments.

For C++/WinRT I provided a non_agile marker type that indicated that the object would not provide an implementation of IAgileObject or IMarshal directly. You are then free to implement them yourself or not at all. This supports the few cases where you need more control over the apartment model of the caller and callee.

The implement macro now provides an equivalent option to control the agility directly. Here is an example from the accompanying test:

// IAgileObject and IMarshal are implemented
#[implement(ITest)]
struct DefaultAgile;

// IAgileObject and IMarshal are *not* implemented
#[implement(ITest, Agile = false)]
struct AgileFalse;

// IAgileObject and IMarshal are implemented
#[implement(ITest, Agile = true)]
struct AgileTrue;

// IAgileObject is implemented while IMarshal is not
#[implement(ITest, Agile = false, IAgileObject)]
struct ExplicitAgile;

Fixes: #3768

@kennykerr kennykerr merged commit 9162058 into master Sep 24, 2025
28 checks passed
@kennykerr kennykerr deleted the implement-agile branch September 24, 2025 18:03
This was referenced Sep 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

COM objects using implement macro cannot opt-out of IInspectable or IAgileObject

2 participants