WinUI3 : How to fix WinRT originate error - 0x80040154 : 'Class not registered'.
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
I checked online and found that this issue is somehow related to the environment setup.
These are my properties
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.