Where is the main function?
-
Wednesday, September 12, 2012 1:50 PM
I'm trying to dust off my rusty C++ and learn DirectX
My first challenge is to modify a vanilla (just created off the template) Direct3D application and make it use XAML as in the sample:
http://code.msdn.microsoft.com/windowsapps/Metro-style-DirectX-18f98448
The problem is the vanilla D3D app has a main() function (fine!)But the XAML app doesn't have a main(), somehow it directly "start" the app class!
How can that be?
Could I just add take all the 'app' file from another C++/WinRT project, hook them in, remove my main, and it will work?
All Replies
-
Wednesday, September 12, 2012 2:14 PM
I made a blank XAML app, copied the App[.xaml/.h/.cpp] and MainPage[.xaml/.h/.cpp], commented out the main() method (and a few other things) and tried to compile..
I get the following error:
---
error WMC1009: The type path of x:Class 'Tests.App' does not match the name of Windows metadata 'PaxGalactica.winmd' file
---What can be the problem?
Me thing think it might be my App file should be called 'PaxGalactica.App' but there is already a class named 'PaxGalactica', I fear namespace and class name clashes.. going to try anyway!! :~
- Edited by lloyd Wednesday, September 12, 2012 2:15 PM made the question more clear
-
Wednesday, September 12, 2012 2:37 PM
I removed the default PaxGalactica[.cpp/.h] and renamed my App and MainPage file to use the PaxGalactica namespace.
I did add
#include "App.xaml.h"
in pch.hwhen I compiled I get the error:
--
error WMC1002: x:Class type 'PaxGalatica.App' is not found in 'PaxGalactica' ???
--I did check the XAML/.h/.cpp multiple time, they all have the namespace change...
what can be wrong??
-
Wednesday, September 12, 2012 3:05 PM
looking at the .vcproj file I can see that I have an ItemGroup tag, with
<ApplicationDefinition Include="App.xaml"/>
<Page Include="MainPage.xaml"/>But I can't find anyway to set that in the UI (i.e. Solution Explorer and object properties window)
Is there a way other than editing the .vcxproj manually???
Anyway I edited the project manually (unload project, edit option appear) I made App.xaml an ApplicationDefinition (it was a Page)
And then.. .. I got plenty of new error.. did a "Rebuild"...
And it compiled and run!! :)
-
Friday, September 14, 2012 2:30 AMSo where is the main function in XAML project?
NEU_ShieldEdge
-
Friday, September 14, 2012 4:39 AM
Luke, use the force!
There is main() but the App!!Oops, sorry, tryed to answer Yoda style...
Anyway, there is no user defined main() but I suppose that tagging App.xaml as 'ApplicationDefinition' in the .vcxproj (instead of 'Page') will make the compiler generate a main() that will launch the application?!
Look in your XAML/C++ app folder for generated source code file (might be same in C#, haven't looked yet), I bet the App.g.cpp will contains a main()
(Can't check now, at work, without win8 machine!!)Now that I think of it, on a normal WPF app there is no main either, the main() is in App.g.cs
-
Monday, September 17, 2012 5:45 PM
There is a commented line before the App::App method in the App.xaml file which is generated when you use the Blank App (XAML) template:
// This is the first line of authored code executed, and as such is the logical equivalent of main() or WinMain().So I guess this is what you try to find.
-
Thursday, September 20, 2012 12:23 PM
If you want a Direct3D+XAML app, I recommend starting with the "XAML Direct2D" app template and modify it as needed. The Direct2D XAML template has all the goop to get Direct3D and a SwapChainBackgroundPanel configured. Your "main" function will then be the DirectXPage constructor.
At least that's how I managed to get a D3D+XAML app up and running fairly quickly.
-
Thursday, December 06, 2012 6:05 AM
looking at the .vcproj file I can see that I have an ItemGroup tag, with
<ApplicationDefinition Include="App.xaml"/>
<Page Include="MainPage.xaml"/>But I can't find anyway to set that in the UI (i.e. Solution Explorer and object properties window)
Is there a way other than editing the .vcxproj manually???
Anyway I edited the project manually (unload project, edit option appear) I made App.xaml an ApplicationDefinition (it was a Page)
And then.. .. I got plenty of new error.. did a "Rebuild"...
And it compiled and run!! :)
you can set it in App.xaml's property panel.
just change the item type to application difinition type
Yop
- Marked As Answer by lloyd Thursday, December 06, 2012 9:57 AM
-
Thursday, December 06, 2012 9:57 AMHo.. it's a C++ project indeed, property are hidden in so many places! ^^
Indeed the property panel has it, thanks!
I was just not seeing it in the Property panel, where one can find that for a C# file!! ^^


