Skip to content

Bug: Surprising winrt::guid_of<> behavior for classes implementing winrt::implements #1494

Description

Version

2.0.250303.1

Summary

I'm struggling to understand the intended behavior of winrt::guid_of<T>(). The function appear to return the same value as __uuidof(T) for most types. However, it behaves very differently for classes inheriting winrt::implements<T...>, where it instead seem to return the interface ID GUID for the first interface in the winrt::implements template list.

I'm not sure if this is a bug or intended behavior, but it does at least seem to have caused a bug in wil::register_com_server (see microsoft/wil#533). I would therefore appreciate if the documentation could either be extended to clarify the behavior, or the behavior changed to avoid counter-intuitive surprises.

Reproducible example

structDECLSPEC_UUID("5fb96f8d-409c-42a9-99a7-8a95c1459dbd") ICapture : ::IUnknown {
...
};
structDECLSPEC_UUID("BABF401C-D3D2-4B68-8E1A-1F4177F3F49A") Capture : implements<Capture, ICapture, IStringable> {
...
};

Expected behavior

__uuidof(Capture); // returns {BABF401C-D3D2-4B68-8E1A-1F4177F3F49A} 
winrt::guid_of<Capture>(); // returns {BABF401C-D3D2-4B68-8E1A-1F4177F3F49A}

Actual behavior

winrt::guid_of<ICapture>(); // returns {5fb96f8d-409c-42a9-99a7-8a95c1459dbd} as expected__uuidof(Capture); // returns {BABF401C-D3D2-4B68-8E1A-1F4177F3F49A} as expected
winrt::guid_of<Capture>(); // returns {5fb96f8d-409c-42a9-99a7-8a95c1459dbd} which was surprising to me

Additional comments

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions