0

When using Win32 API, it's not really necessary to have a winmain entry point in order to create a window, because we can still call RegisterClassExW and CreateWindowExW, etc. I wonder if it's possible to do so as well in creating a C++/WinRT window, since almost every example on the Internet is using template projects.

I tried to create a struct which inherits implements<App, IFrameworkView, IFrameworkViewSource> with all necessary functions (Initialize, Uninitialize, Load, SetWindow, Run, etc.), then call CoreApplication::Run(winrt::make<App>()) inside int main(), but WinRT either complains about not having run init_apartment() beforehand, or shows a weird error as WinRT originate error - 0x80070057 : 'serverName' and that HRESULT is E_INVALIDARG, and that a hresult_invalid_argument(take_ownership_from_abi) is thrown. Plus, the source file created with template project doesn't even have to run init_apartment() first, which I couldn't really understand why.

Is it possible to create a C++/WinRT window from a console application? Thanks.

3
  • That appears to be possible. The XAML Hosting API sample might be a good starting point. Commented Jan 18, 2020 at 13:46
  • When you say console application, does that mean your application runs without app container (no AppXManifest)? If so, you cannot use CoreApplication class at all - you should use Win32 equivalents.
    – Sunius
    Commented Jan 23, 2020 at 23:16
  • CoreApplication is UWP only. So it's not WinRT issue, rather fact that this part of Windows Runtime won't work in Win32 applications. stackoverflow.com/q/56892952/950131
    – stoper
    Commented Sep 25, 2020 at 9:58

1 Answer 1

-1

No.

UWP console apps may not create a window. They cannot use MessageBox(), or Location(), or any other API that may create a window for any reason, such as user consent prompts.

https://learn.microsoft.com/en-us/windows/uwp/launch-resume/console-uwp

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.