question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to cast Compositor to ICompositorInterop

See original GitHub issue

Describe the bug In our WinUI for UWP app, we are trying to create an ICompositionGraphicsDevice2 instance as documented here. For this, we try to cast the Window.Current.Compositor instance to the ICompositorInterop interface:

var compositorPtr = Marshal.GetIUnknownForObject(Window.Current.Compositor);            
var guid = typeof(ICompositorInterop).GUID;
var hresult = Marshal.QueryInterface(compositorPtr, ref guid, out var pCompositorInterop);
var compositorInterop = (ICompositorInterop)Marshal.GetObjectForIUnknown(pCompositorInterop);

However, the QueryInterface returns the E_NOINTERFACE hresult.

I’ve listed available IIDs for the compositor object using the IInspectable API and have not found the ICompositorInterop iid (25297D5C-3AD4-4C9C-B5CF-E36A38512330)

Steps to reproduce the bug

Steps to reproduce the behavior:

  1. Download and run the sample from the Additional Context section
  2. Click on the “Click Me” button
  3. The exception will be thrown.

Expected behavior The ICompositorInterop should be available

Screenshots

Version Info

NuGet package version:

[Microsoft.WinUI 3.0.0-preview3.201113.0] [Microsoft.NETCore.UniversalWindowsPlatform 6.2.10]

Windows app type:

UWP Win32
Yes
Windows 10 version Saw the problem?
Insider Build (xxxxx)
May 2020 Update (19041) Yes
November 2019 Update (18363)
May 2019 Update (18362)
October 2018 Update (17763)
April 2018 Update (17134)
Fall Creators Update (16299)
Creators Update (15063)
Device form factor Saw the problem?
Desktop Yes
Xbox
Surface Hub
IoT

Additional context

App6.zip

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
alexserovcommented, Dec 7, 2020

@Scottj1s I tried your solution - it works like a charm, thanks!

Your link to the header file helped me a lot.

0reactions
Scottj1scommented, Dec 4, 2020

@alexserov - my apologies, I missed that this was UWP.

It looks like you need to QI for the lifted compositor interop interface (in Microsoft.UI.Composition.Interop, rather than Windows.UI.Composition.Interop), which requires a GUID change. Also, the interop interface should be IUnknown, rather than IInspectable:

    [ComImport, Guid("FAB19398-6D19-4D8A-B752-8F096C396069"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]

For additional interop interfaces, see the nuget header: <nuget packages>\microsoft.winui\3.0.0-preview3.201113.0\include\Microsoft.UI.Composition.Interop.h

Read more comments on GitHub >

github_iconTop Results From Across the Web

ICompositorInterop (windows.ui.composition.interop.h)
Native interoperation interface that allows creating swapchain surfaces and graphics devices. This is interface is available in C++ only.
Read more >
How to draw WinRT::Windows::UI - Visual on bitmap
I am trying to draw cppwinrt Lottie animation into my Direct2D app, but can't understand how to do this... It's possible draw this...
Read more >
Untitled
Compositor type 0 winwordp1 Casting from Compositor to ... Unable to cast Compositor to ICompositorInterop #3752 WebDec 8, 2018 · 0.
Read more >
Untitled
Xaml) - Windows App … Unable to cast Compositor to ICompositorInterop #3752 - GitHub Question: Is there analogue for Window.Current.Compositor in …
Read more >
Untitled
Casting from Compositor to ICompositorDesktopInterop causes Windows.Ui.Composition.Interop.h header - Win32 apps Composition swapchain code examples - Win32 ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found