In mainpage.cpp:
1. In the function MainPage::ExitButton_Click Insert the following code above the last line of code of the function (which is return hr;)
//Get reference to the Window IXRVisualHostPtr pHost; UINT ExitCode = 1; hr = App::GetVisualHost(&pHost); //Close the Window if(hr == S_OK) { pHost->EndDialog(ExitCode); }
//Get reference to the Window
IXRVisualHostPtr pHost;
UINT ExitCode = 1;
hr = App::GetVisualHost(&pHost);
//Close the Window
if(hr == S_OK)
{
pHost->EndDialog(ExitCode);
}
Listing 15.8: XAML application exit code
2. Rebuild the subproject and test this exit functionality: When the Exit button is pressed the application should exit.
[1] In some C# XAML discussions, it is stated that for app closure on Main Windows closure, you might need the following in the OnStartUp method, otherwise the app won’t fully terminate: this.ShutdownMode = System.Windows.ShutdownMode.OnMainWindowClose;
NEXT: 15.6 Calling a DLL from Native XAML C++
Click here to provide feedback and input