winrt::hresult_class_not_registered at memory location using Windows Composition APIs in Win32 app

Scrivano Dev 6 Reputation points
2022-04-05T20:08:05.893+00:00

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.

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,509 questions
{count} vote

1 answer

Sort by: Most helpful
  1. Junjie Zhu - MSFT 16,471 Reputation points Microsoft Vendor
    2022-04-06T09:09:15.283+00:00

    Hello,@Scrivano Dev
    Welcome to Microsoft Q&A!

    This exception may be that the COM server was not found. You need to check if WinRTComponent.dll is copied to other computer's exe directory.

    You can use the dumpbin /dependents F:\test.exe command to view the dll that the Application depends on, and put it in the exe directory before copying it to other computers.

    https://learn.microsoft.com/en-us/cpp/build/reference/dependents?view=msvc-170#example

    Thank you.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.