2

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

  • As for the rest of my code, I started from one side with a blank template for C++/WinRT application and I took the rendering pipeline entirely from [2]. I have not other build issue apart from the code that should link XAML and DirectX. [2]: https://github.com/Microsoft/Xbox-ATG-Samples/tree/master/UWPSamples/IntroGraphics/SimpleTriangleCppWinRT_UWP12 – C. D'Alessandro Mar 22 '19 at 18:36

1 Answers1

1

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>();
Ryan Shepherd
  • 755
  • 4
  • 11
  • Hi Ryan, thanks; I still have problems. Apparently, to see the ISwapChainswapChainNative interface, it needs "#include " as considered in [3], found after googling about your code. Then, I get this error: "binary '=': no operator found which takes a right-hand operand of type 'winrt::com_ptr' " referring to "swapChainNative = swapChainPanel.as();" ; I have swapChainPanel defined as: SwapChainPanel swapChainPanel. [3]: – C. D'Alessandro Mar 22 '19 at 18:38
  • 1
    I literally just compiled this successfully against the 17763 SDK version of cppwinrt: ``` #include #include #pragma comment (lib, "WindowsApp.lib") using namespace winrt; int main() { winrt::Windows::UI::Xaml::Controls::SwapChainPanel swapChainPanel{ nullptr }; // ... winrt::com_ptr m_swapChainNative; m_swapChainNative = swapChainPanel.as(); } ``` – Ryan Shepherd Mar 22 '19 at 19:01
  • Many Thanks Ryan, by including the mentioned files I can see that the interoperation related code builds correctly. Adding "m_swapChainNative->SetSwapChain(swapChain);" makes everything working, too. – C. D'Alessandro Mar 22 '19 at 19:38