I have a problem with the project structure for an application using the Visual C++ | Windows Metro Style | Application template

    General discussion

  • After looking at the generated application, there are a few things that I consider a deviation from other projects, particularly those using precompiled headers, so I'll outline them.


    1. The use of using directives and declarations in header files, which I already wrote a long post.  I still think it is a bad practice that will spread very quickly through the canned project templates provided by VS.
    2. Inclusion of App.xaml.h in pch.h, and viceversa: inclusion of pch.h in App.xaml.h.  Before you say...but it uses #pragma once, that's not the point.  What I'd like to know is why is it included also in App.xaml.hand MainPage.xaml.h.  It seems that the template is "pch happy", and the bigger problem is that this practice would break the "self sufficient header files" good practice. The typical project without precompiled headers, assuming one class per header files, #include's the header file for the class as the first file.  When using precompiled headers, the stdafx.h is the first header file, followed by the corresponding header file:

      #include <stdafx.h>
      #include "myclass.h>

      Now, what I see here in App.xaml.cpp is:

      #include "pch.h"
      #include "MainPage.xaml.h" <-- Huh?

      and in MainPage.xaml.cpp:

      #include "pch.h"
      #include "MainPage.xaml.h" -- OK, this makes sense.

      My question is, why not "follow suit" and just do:

      In pch.h:
      What a typical precompiled header contains (as the comment in the file says, Header for standard system include files, but definitely not App.xaml.h!)

      In App.xaml.cpp:

      #include "pch.h"
      #include "App.xaml.h"
      #include "MainPage.xaml.h"

      MainPage.xaml.cpp looks fine.

      In App.xaml.h, remove the #include to pch.h. Ditto in MainPage.xaml.h.

    This works in the simplistic project I'm working on, so what gives? Why the pch-happiness by including it everywhere? What am I missing?


    • Edited by ljestrada Friday, October 28, 2011 5:23 AM Minor typo.
    Friday, October 28, 2011 5:21 AM

All replies

  • I could not find anyone reporting this feedback so far. Could you send this feedback thru our Connect site so our team that builds the templates is sure to get this?

    Here are the instructions if you haven't used it yet.

    Thanks so much!


    Thank you for posting your feedback, we want to make sure we get the right info including your log files.  Can you also submit feedback using the Windows Feedback Tool from the Connect Site associated with your Windows Developer Preview program? If you’re an MSDN subscriber, the information on how to join the Connect program is included on the download page where you installed Windows Developer Preview.  There’s a link to the Connect site and an invitation code that you can click on to join using a Windows Live ID account. If you’re not an MSDN subscriber follow this limited use link to join the Connect program and then follow the steps here

    Tuesday, November 1, 2011 5:12 PM