Share via

Crash issue from Microsoft official Win32 C++ custom WinRT XAML control tutorial

KKL 5 Reputation points
2024-10-18T02:50:15.38+00:00

Build was ok, but got a crash after following the official Microsoft official Win32 custom WinRT XAML control tutorial https://learn.microsoft.com/en-us/windows/apps/desktop/modernize/xaml-islands/host-custom-control-with-xaml-islands-cpp:Screenshot 2024-10-18 103912

Clicking "Retry" will show these stacktraces:

    ucrtbased.dll!issue_debug_notification(const wchar_t * const message) Line 28   C++
    ucrtbased.dll!__acrt_report_runtime_error(const wchar_t * message) Line 154 C++
    ucrtbased.dll!abort() Line 61   C++
    ucrtbased.dll!terminate() Line 59   C++
>   MyDesktopWin32App.exe!__scrt_unhandled_exception_filter(_EXCEPTION_POINTERS * const pointers) Line 93   C++
    KernelBase.dll!UnhandledExceptionFilter()   Unknown
    ntdll.dll!RtlUserThreadStart$filt$0()   Unknown
    ntdll.dll!__C_specific_handler()    Unknown
    ntdll.dll!RtlpExecuteHandlerForException()  Unknown
    ntdll.dll!RtlDispatchException()    Unknown
    ntdll.dll!RtlRaiseException()   Unknown
    KernelBase.dll!RaiseException() Unknown
    vcruntime140d.dll!_CxxThrowException(void * pExceptionObject, const _s__ThrowInfo * pThrowInfo) Line 82 C++
    MyDesktopWin32App.exe!winrt::throw_hresult(const winrt::hresult result) Line 5017   C++
    MyDesktopWin32App.exe!winrt::check_hresult(const winrt::hresult result) Line 5087   C++
    MyDesktopWin32App.exe!winrt::Windows::Foundation::IActivationFactory::ActivateInstance<winrt::MyUWPApp::MyUserControl>() Line 6582  C++
    MyDesktopWin32App.exe!winrt::MyUWPApp::MyUserControl::{ctor}::__l1::<lambda_143_>::operator()(const winrt::Windows::Foundation::IActivationFactory & f) Line 62 C++
    MyDesktopWin32App.exe!`winrt::MyUWPApp::MyUserControl::MyUserControl'::`1'::<lambda_143_>::<lambda_invoker_cdecl>(const winrt::Windows::Foundation::IActivationFactory & f) Line 62 C++
    MyDesktopWin32App.exe!winrt::impl::factory_cache_entry<winrt::MyUWPApp::MyUserControl,winrt::Windows::Foundation::IActivationFactory>::call<winrt::MyUWPApp::MyUserControl (__cdecl*)(winrt::Windows::Foundation::IActivationFactory const &)>(winrt::MyUWPApp::MyUserControl(*)(const winrt::Windows::Foundation::IActivationFactory &) && callback) Line 6419 C++
    MyDesktopWin32App.exe!winrt::impl::call_factory_cast<winrt::MyUWPApp::MyUserControl (__cdecl*)(winrt::Windows::Foundation::IActivationFactory const &),winrt::MyUWPApp::MyUserControl,winrt::Windows::Foundation::IActivationFactory,`winrt::MyUWPApp::MyUserControl::MyUserControl'::`1'::<lambda_143_>>(winrt::MyUWPApp::MyUserControl::{ctor}::__l1::<lambda_143_> && callback) Line 6458    C++
    MyDesktopWin32App.exe!winrt::MyUWPApp::MyUserControl::MyUserControl() Line 62   C++
    MyDesktopWin32App.exe!InitInstance(HINSTANCE__ * hInstance, int nCmdShow) Line 126  C++
    MyDesktopWin32App.exe!wWinMain(HINSTANCE__ * hInstance, HINSTANCE__ * hPrevInstance, wchar_t * lpCmdLine, int nCmdShow) Line 44 C++
    MyDesktopWin32App.exe!invoke_main() Line 123    C++
    MyDesktopWin32App.exe!__scrt_common_main_seh() Line 288 C++
    MyDesktopWin32App.exe!__scrt_common_main() Line 331 C++
    MyDesktopWin32App.exe!wWinMainCRTStartup(void * __formal) Line 17   C++
    kernel32.dll!BaseThreadInitThunk()  Unknown
    ntdll.dll!RtlUserThreadStart()  Unknown

However, it works fine using Option 2 by creating application manifest https://learn.microsoft.com/en-us/windows/apps/desktop/modernize/xaml-islands/host-custom-control-with-xaml-islands-cpp#option-2-create-an-application-manifest. The error only shows up for Option 1 using Windows Application Packaging Project.

Here's the project that I have setup, based on the tutorial above. https://drive.google.com/file/d/15o7Gp2xAEr0OXtMLzvbpqU0txFFZyvQj/view?usp=sharing

Any clue why that would happen?

Using Visual Studio 2022 v17.11.4

Windows development | Windows API - Win32
Developer technologies | C++
Developer technologies | C++

A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.

Developer technologies | XAML
Developer technologies | XAML

A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.


Your answer

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