How to Override Start WinUI 3.0 Desktop Application
See the question and my original answer on StackOverflowThis has probably been generated by the tooling you use. If you don't use any special tooling or/and have chosen a fancy compiler, you should be able to do it yourself.
If you choose Microsoft tooling, typically C++/WinRT with C++ and Visual Studio, then WinMain is generated probably in a file named App.xaml.g.hpp
(to find that, just start debug, it should get you right in that WinMain).
To use your own, define DISABLE_XAML_GENERATED_MAIN somewhere (note it works for C# too):
And add for example this to your appp.xaml.cpp file:
int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nShowCmd)
{
winrt::init_apartment(winrt::apartment_type::single_threaded);
// put your fancy code somewhere here
::winrt::Microsoft::UI::Xaml::Application::Start(
[](auto&&)
{
// and here (default is like this)
// ::winrt::make<::winrt::MyNamespace::MyApp::implementation::App>();
});
return 0;
}