WinUI3 : How to fix WinRT originate error - 0x80040154 : 'Class not registered'.

Harshithraj1871 1,706 Reputation points
2023-04-10T07:15:10.87+00:00

Hi, I am working on WinUI3 desktop application in cpp without any xaml files and with cmake. I and getting this error immediately when i start the event loop.

Exception thrown at 0x00007FFF9E12051C (KernelBase.dll) in TWTallySCPNative.exe: WinRT originate error - 0x80040154 : 'Class not registered'. 'TWTallySCPNative.exe' (Win32): Loaded 'C:\Windows\System32\bcrypt.dll'. Exception thrown at 0x00007FFF9E12051C in TWTallySCPNative.exe: Microsoft C++ exception: winrt::hresult_class_not_registered at memory location 0x000000AB9B90F740.

I tried adding breakpoints and noticed this was the point(in base.h) where the error was triggered
User's image

I checked online and found that this issue is somehow related to the environment setup. These are my properties User's image

And my code flow goes something like this

int CALLBACK
WinMain([[maybe_unused]] HINSTANCE pInstance, [[maybe_unused]] HINSTANCE pPrevInstance, [[maybe_unused]] LPSTR pCmdLine, [[maybe_unused]] int pShowCmd) {

...
..

CallInitApartment(); // which is in different library linked statically

...

StartEventLoop();  // which is in different library linked statically

...

}

void CallInitApartment(){

     winrt::init_apartment (winrt::apartment_type::single_threaded);
}

void StartEventLoop () {

    Application::Start ([] (auto &&) {
        // Create a new instance of the App class
    
        make<TWWinUI3App> ();  // TWWinUI3App is defined and the execution did not reach TWWinUI3App constructor or Onlaunched 
    });
}


It would be of grate help if you could help me with this issue. Thank you.

Windows development | Windows App SDK
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.