Hi, I'm making use of the Windows Runtime Composition APIs in my Win32 application as instructed at the following page using-the-visual-layer-with-win32. I followed the tutorial using the exact same steps as detailed in this page and was able to build and run the example successfully. Then, I wanted to integrate the windows.ui.composition.delegatedinktrailvisual class in my app so I slightly modified the code of CompositionHost.cpp as follows:
void CompositionHost::AddElement(float size, float x, float y)
{
if (m_target.Root())
{
auto visuals = m_target.Root().as<ContainerVisual>().Children();
auto visual = m_compositor.CreateSpriteVisual();
// ADDED AN INK TRAIL
auto inkTrail = DelegatedInkTrailVisual::Create(m_compositor);
//
auto element = m_compositor.CreateSpriteVisual();
uint8_t r = (double)(double)(rand() % 255);;
uint8_t g = (double)(double)(rand() % 255);;
uint8_t b = (double)(double)(rand() % 255);;
element.Brush(m_compositor.CreateColorBrush({ 255, r, g, b }));
element.Size({ size, size });
element.Offset({ x, y, 0.0f, });
auto animation = m_compositor.CreateVector3KeyFrameAnimation();
auto bottom = (float)600 - element.Size().y;
animation.InsertKeyFrame(1, { element.Offset().x, bottom, 0 });
using timeSpan = std::chrono::duration<int, std::ratio<1, 1>>;
std::chrono::seconds duration(2);
std::chrono::seconds delay(3);
animation.Duration(timeSpan(duration));
animation.DelayTime(timeSpan(delay));
element.StartAnimation(L"Offset", animation);
visuals.InsertAtTop(element);
visuals.InsertAtTop(visual);
}
}
With the single line I added, the code runs fine on my machine and the app successfully builds and run. However, when I tried to run the same exact example on another machine running Windows 10 Home 21H2 and with the SDK version 10.0.20348.0 in Visual Studio, I get the following error:
Exception thrown at 0x00007FFC466C4F69 (KernelBase.dll) in HelloComposition.exe: WinRT originate error - 0x80040111 : 'Windows.UI.Composition.DelegatedInkTrailVisual'.
Exception thrown at 0x00007FFC466C4F69 (KernelBase.dll) in HelloComposition.exe: WinRT originate error - 0x80040154 : 'Class not registered'.
Exception thrown at 0x00007FFC466C4F69 in HelloComposition.exe: Microsoft C++ exception: winrt::hresult_class_not_registered at memory location 0x0000001F51CFE3A8.
Unhandled exception at 0x00007FFC466C4F69 in HelloComposition.exe: Microsoft C++ exception: winrt::hresult_class_not_registered at memory location 0x0000001F51CFE3A8.
This is very strange since the example ran perfectly fine on my previous machine (running Windows 11 with the latest SDK). According to the documentation windows.ui.composition.delegatedinktrailvisual, the DelegatedInkTrailVisual class was introduced in the 10.0.20348.0 SDK so I don't know why this is happening. Upon further testing I could also reproduce on some other Windows machines and couldn't on some others, with no clear pattern on why the exception is thrown.
Any pointer on this, would be appreciated.
Note, that my code is exactly the same as the "HelloComposition" example here https://github.com/microsoft/Windows.UI.Composition-Win32-Samples/tree/master/cpp, with the sole addition of the line above that adds a DelegatedInkTrailVisual to the compositor.