Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about Application::Start #51

Closed
Firelark opened this issue Dec 11, 2016 · 6 comments
Closed

Question about Application::Start #51

Firelark opened this issue Dec 11, 2016 · 6 comments

Comments

@Firelark
Copy link

Hello, this is not an issue, just a question. I've just started to playing around with cppwinrt and I started with the sample project "XamlCode".

I'm a little bit confused about the following code found in wWinMain:

Application::Start(
[](auto &&) 
{
make<App>();
});

This lambda seems to create an instance of App but it is not returning it to the caller.

My Question: How is the function OnLaunched and other functions like OnWindowsCreated and OnActivated getting called?

I'm just curious.

Thanks for the cppwinrt initiative, it is really needed in my opinion.

@smj389
Copy link

smj389 commented Dec 14, 2016

Windows.UI.Xaml.Application takes a delegate as its argument. The Lambda is converted to that. In the callback you create your app object.

@Firelark
Copy link
Author

Yes, but the App object doesn't seem to go anywhere, from the looks of it the object should die just as soon as it returns from make<App>(); as there is nothing to keep it alive. Unless it is somehow assigned to some global internal variable inside the make<App> funktion?

I reckon that there should only be one App object within the application and so I'm figuring that it might be implemented in a singleton pattern with a static data member somewhere?

I just find the

Application::Start(
[](auto &&) 
{
make<App>();
});

to be a little unintuitive and confusing. Perhaps have a differently named function to make and register the App objekt, maybe something like register_new<App>() or something similar instead of make<App>().

Just my thoughts, and I might have misunderstood things.

@smj389
Copy link

smj389 commented Dec 15, 2016 via email

@Firelark
Copy link
Author

Aha that makes a lot more sense! Thanks smj389 for clarifying that.

If I could make a suggestion, maybe have a function named run<App>() or something like that would be more clear than make<App>().

@kennykerr
Copy link
Collaborator

The XAML startup model is a bit odd because if you only look at WinMain it seems as if the XAML framework never gets a reference to your App class, but keep in mind that your App class derives from the XAML Application class. This causes the Application constructor to run, which is the way that the XAML framework discovers that the app is ready for launch.

@Firelark
Copy link
Author

Thanks for the information and for the good work on cppwinrt!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants