Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++/WinRT support for implementing COM interfaces that derive from ::IInspectable #603

Merged
merged 4 commits into from
Sep 24, 2019

Conversation

kennykerr
Copy link
Contributor

Ideally this would not be required, but regrettably there exists some COM interop interfaces that just happen to derive from ::IInspectable. This update makes it easier to implement such interfaces in C++/WinRT.

This now "just works" provided you include <inspectable.h> before including any C++/WinRT headers. This is distinct from general COM interop support that merely requires that you include <unknwn.h> because changing that now would break the world.

struct __declspec(uuid("ed0dd761-c31e-4803-8cf9-22a2cb20ec47")) IBadInterop : ::IInspectable
{
    virtual int32_t __stdcall JustSayNo() noexcept = 0;
};

struct Sample : implements<Sample, Windows::Foundation::IActivationFactory, IBadInterop>
{
    Windows::Foundation::IInspectable ActivateInstance()
    {
        throw hresult_not_implemented();
    }

    hstring GetRuntimeClassName()
    {
        return L"Sample";
    }

    Windows::Foundation::TrustLevel GetTrustLevel()
    {
        return Windows::Foundation::TrustLevel::PartialTrust;
    }

    int32_t __stdcall JustSayNo() noexcept final
    {
        return 123;
    }
};


namespace
{
struct __declspec(uuid("ed0dd761-c31e-4803-8cf9-22a2cb20ec47")) IBadInterop : ::IInspectable
Copy link
Member

Choose a reason for hiding this comment

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

In practice, this IBadInterop definition would come from some ABI header file, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right.

@kennykerr kennykerr merged commit e7ad763 into master Sep 24, 2019
@kennykerr kennykerr deleted the kennykerr-inspectable branch September 24, 2019 22:23
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