0xC000027B exception when trying to start WinUI from within a dll
See original GitHub issueDescribe the bug Our exe (C++ desktop app) is (and must stay) UI agnostic. The UI is loaded from a C/C++ dll. The first exported function called from the exe is “void InitWinUI()” that mimic what is done in the main from the desktop c++ sample.
void InitWinUI()
{
winrt::init_apartment(winrt::apartment_type::single_threaded);
//winrt::init_apartment();
print_context();
::winrt::Microsoft::UI::Xaml::Application::Start(
[](auto&&)
{
::winrt::make<::winrt::App1::implementation::App>();
});
}
Exception 0xC000027B is thrown somewhere within the call to “winrt::Microsoft::UI::Xaml::Application::Start(lambda)” Tried with winui preview1 and preview2. Same result.
Steps to reproduce the bug Make a C++ winui desktop app using the winui sample (VS new project) Change its type to dll, and export a basic C function “InitWInUI()” as above Make a regular C/C++ exe (console or , link it with the dll and call InitWinUI() -> notice the 0xC000027B exception
Expected behavior Able to “start” winui (create windows, controls, etc) from within a dll. Maybe I’m doing it wrong… Any workaround or suggestions welcome!
Screenshots Unhandled exception at 0x00007FFFA90E6589 (Microsoft.Internal.XamlUdk.dll) in GameFake.exe: 0xC000027B: An application-internal exception has occurred (parameters: 0x000001F9DFC377C0, 0x0000000000000001).
Version Info WinUI version=“3.0.0-preview2.200713.0” (same with preview1) CppWinRT version=“2.0.200316.3” VCRTForwarders.140 version=“1.0.6”
Windows 10 version 1909 (build 18363.900)
Desktop
Additional context I attach the mini dump file. Here is the callstack:
KernelBase.dll!RaiseFailFastException() Unknown
combase.dll!RoFailFastWithErrorContextInternal2(HRESULT hrError, unsigned long cStowedExceptions, _STOWED_EXCEPTION_INFORMATION_V2 * * aStowedExceptionPointers) Line 1458 C++
Microsoft.Internal.XamlUdk.dll!FailFastWithStowedExceptionInfo() Unknown
Microsoft.UI.Xaml.dll!UdkShim::FailFastWithStowedExceptions(HRESULT hrError, unsigned long cStowedExceptions, _STOWED_EXCEPTION_INFORMATION_V2 * * aStowedExceptionPointers) Line 85 C++
Microsoft.UI.Xaml.dll!FailFastWithStowedExceptions(HRESULT hrError, unsigned long cStowedExceptions, _STOWED_EXCEPTION_INFORMATION_V2 * * aStowedExceptionPointers) Line 93 C++
Microsoft.UI.Xaml.dll!CXcpDispatcher::Init(IXcpHostSite * pSite) Line 356 C++
Microsoft.UI.Xaml.dll!CXcpDispatcher::Create(IXcpHostSite * pSite, IXcpDispatcher * * ppInterface) Line 505 C++
Microsoft.UI.Xaml.dll!CJupiterControl::Init() Line 145 C++
Microsoft.UI.Xaml.dll!CJupiterControl::Create(CJupiterControl * * ppControl) Line 32 C++
Microsoft.UI.Xaml.dll!DirectUI::DXamlCore::InitializeInstance(InitializationType initializationType, bool runWithoutCoreApplication) Line 372 C++
Microsoft.UI.Xaml.dll!DirectUI::DXamlCore::InitializeImpl(InitializationType initializationType, bool runWithoutCoreApplication) Line 2636 C++
Microsoft.UI.Xaml.dll!DirectUI::FrameworkApplication::StartDesktop() Line 188 C++
Microsoft.UI.Xaml.dll!DirectUI::FrameworkApplicationFactory::Start(ABI::Microsoft::UI::Xaml::IApplicationInitializationCallback * pCallback) Line 713 C++
> App1.dll!winrt::impl::consume_Microsoft_UI_Xaml_IApplicationStatics<winrt::Microsoft::UI::Xaml::IApplicationStatics>::Start(const winrt::Microsoft::UI::Xaml::ApplicationInitializationCallback & callback) Line 260 C++
App1.dll!winrt::Microsoft::UI::Xaml::Application::Start::__l2::<lambda>(const winrt::Microsoft::UI::Xaml::IApplicationStatics & f) Line 12898 C++
App1.dll!winrt::impl::factory_cache_entry<winrt::Microsoft::UI::Xaml::Application,winrt::Microsoft::UI::Xaml::IApplicationStatics>::call<void <lambda>(const winrt::Microsoft::UI::Xaml::IApplicationStatics &) &>(winrt::Microsoft::UI::Xaml::Application::Start::__l2::void <lambda>(const winrt::Microsoft::UI::Xaml::IApplicationStatics &) & callback) Line 5984 C++
App1.dll!winrt::impl::call_factory<winrt::Microsoft::UI::Xaml::Application,winrt::Microsoft::UI::Xaml::IApplicationStatics,void <lambda>(const winrt::Microsoft::UI::Xaml::IApplicationStatics &)>(winrt::Microsoft::UI::Xaml::Application::Start::__l2::void <lambda>(const winrt::Microsoft::UI::Xaml::IApplicationStatics &) && callback) Line 6007 C++
App1.dll!winrt::Microsoft::UI::Xaml::Application::Start(const winrt::Microsoft::UI::Xaml::ApplicationInitializationCallback & callback) Line 12899 C++
App1.dll!InitWinUI() Line 48 C++
GameFake.exe!wWinMain(HINSTANCE__ * hInstance, HINSTANCE__ * hPrevInstance, wchar_t * lpCmdLine, int nCmdShow) Line 34 C++
GameFake.exe!invoke_main() Line 123 C++
GameFake.exe!__scrt_common_main_seh() Line 288 C++
GameFake.exe!__scrt_common_main() Line 331 C++
GameFake.exe!wWinMainCRTStartup() Line 17 C++
kernel32.dll!BaseThreadInitThunk() Unknown
ntdll.dll!RtlUserThreadStart() Unknown
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (3 by maintainers)
Top GitHub Comments
@stevenbrix thx for the suggestions, I’ll give it a go.
Our app/exe is a game, which in normal mode doesn’t need UI. Started with a specific parameter, it runs in “tool/editor” mode, which loads the “UI” dll and add dialogs/controls, etc… UI dll is currently MFC based. I’m investigating replacing MFC by Winui3 (progressively).
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 5 days.