Skip to content

Add tearoff support to C++/WinRT#348

Merged
kennykerr merged 5 commits into
masterfrom
kennykerr-qi-fallback
Apr 24, 2019
Merged

Add tearoff support to C++/WinRT#348
kennykerr merged 5 commits into
masterfrom
kennykerr-qi-fallback

Conversation

@kennykerr

Copy link
Copy Markdown
Contributor

This is an advanced feature that most developers won't ever need to deal with. Occasionally there is a need to implement an interface as a COM tearoff and this update adds support for that in C++/WinRT. This also allows C++/WinRT implementations to integrate support for the fast abi forwarding implementation that Scott's been working on. An implementation can simply define the query_interface_tearoff function and provide a suitable implementation. Something like this:

struct Sample : implements<Sample, /* interfaces directly implemented */>
{
    HRESULT query_interface_tearoff(GUID const& id, void** result) const noexcept
    {
        if (is_guid_of</* some tearoff interface */>(id))
        {
            return make_tearoff(this, result);
        }

        *result = nullptr;
        return E_NOINTERFACE;
    }

    // rest of implementation...
};

Comment thread src/tool/cppwinrt/test/tearoff.cpp Outdated
closable = nullptr;
REQUIRE(!InteropType::Destroyed);

// Releasing the tearoof finally destroys the object.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo (and below)

// Creates an implementation of IStringable as a tearoff.
HRESULT make_stringable(winrt::IInspectable const& object, winrt::hstring const& value, void** result) noexcept
{
struct stringable final : abi::IStringable

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could factor a base_tearoff for m_object mgmt, but if these are the only intended test cases, don't bother

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, just examples really.

@Scottj1s Scottj1s left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@kennykerr kennykerr merged commit f2b764d into master Apr 24, 2019
@kennykerr kennykerr deleted the kennykerr-qi-fallback branch April 24, 2019 21:52
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.

3 participants