Unable to cast Compositor to ICompositorInterop
See original GitHub issueDescribe 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:
- Download and run the sample from the Additional Context section
- Click on the “Click Me” button
- 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
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Scottj1s I tried your solution - it works like a charm, thanks!
Your link to the header file helped me a lot.
@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:
For additional interop interfaces, see the nuget header:
<nuget packages>\microsoft.winui\3.0.0-preview3.201113.0\include\Microsoft.UI.Composition.Interop.h