C. D'Alessandro
C. D'Alessandro

Reputation: 21

How to implement interoperation between XAML and a DirectX swap chain with C++/WinRT

Microsoft Documentation provides the code to implement interoperation between XAML and a DirectX swap chain with C++ [1]:

Microsoft::WRL::ComPtr<ISwapChainPanelNative>   m_swapChainNative;
// ...
IInspectable* panelInspectable = (IInspectable*) reinterpret_cast<IInspectable*>(swapChainPanel);
panelInspectable->QueryInterface(__uuidof(ISwapChainPanelNative), (void **)&m_swapChainNative);

However, I was not able to figure out how I should implement this with C++/WinRT.

When using this code, I get the following error message :

" [...] 'reinterpret_cast': cannot convert from 'winrt::Windows::UI::Xaml::Controls::SwapChainPanel' to 'IInspectable *' "

I'm using DirectX12, Visual Studio 2017.

[1] https://learn.microsoft.com/en-us/windows/desktop/api/windows.ui.xaml.media.dxinterop/nn-windows-ui-xaml-media-dxinterop-iswapchainpanelnative

Upvotes: 2

Views: 934

Answers (1)

Ryan Shepherd
Ryan Shepherd

Reputation: 815

I'm not sure why that WRL documentation is using reinterpret_cast. C++/WinRT makes this pretty simple:

winrt::com_ptr<ISwapChainswapChainNative> m_swapChainNative;
// ...
swapChainNative = swapChainPanel.as<ISwapChainPanelNative>();

Upvotes: 1

Related Questions