Share via


why there is no stdafx.h and targetver.h in visual studio c++ 2017?

Question

Wednesday, February 27, 2019 2:45 AM

I created new project in VS 2017 using windows desktop wizard by not changing any default. There should be stdafx.h and targetver.h in the head file in VS 2013 right? But why there's no such files in VS 2017? How can I add these two files in my project?

All replies (3)

Wednesday, February 27, 2019 5:48 AM | 1 vote

Hi,

Welcome to MSDN forum.

Start from visual studio 2017 15.3, in order to make the templates more user-friendly and intuitive, we made the following changes:

  • The Win32 category has been renamed to Windows Desktop, and continues to contain the Win32 project templates.
  • The Win32 Console Application template has been renamed to Windows Console Application and no longer shows a wizard when creating a project.
  • The Win32 Project template has been renamed to Windows Desktop Application and it no longer displays a wizard.

So, please use windows desktop application template and there will be stdafx.h and targetver.h in the head file.

If you do want to go through a wizard and configure your project from the get-go, you can choose the new Windows Desktop Wizard template:

https://devblogs.microsoft.com/cppblog/changes-to-project-templates-and-code-wizards-in-15-3/

Best regards,

Joyce

Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact [email protected].


Wednesday, February 27, 2019 10:53 AM | 1 vote

There is no requirement for a precompiled header to be part of the project template, and there is no requirement for it to be called stdafx.h. Some of the newer templates have called it precompiled.h or pch.h.

The targetver.h header file just included sdkddkver.h but it wasn't really required. This is pulled in automatically through Windows.h, so it isn't needed. If you wanted to target a version of Windows different to the Windows SDK, you could just #define _WIN32_WINNT and NTDDI_VERSION.

This is a signature. Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.


Wednesday, February 27, 2019 11:57 AM | 1 vote

Visual Studio 2017 15.9.7 at least generates pch.h instead of stdafx.h when you create a console application. This is true if you use the Windows Console Application template or select Console Application as the application type using the Windows Desktop Wizard.

This is a signature. Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.