Thread: MS precompiled headers

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    242

    MS precompiled headers

    After Elysia's remarks giving me at least some idea of the reasoning behind these precompiled headers, I just started exploring these a little and have some questions.

    First, VS also creates a file called targetver.h, which contains simply this:

    Code:
    #pragma once
    
    // The following macros define the minimum required platform.  The minimum required platform
    // is the earliest version of Windows, Internet Explorer etc. that has the necessary features to run 
    // your application.  The macros work by enabling all features available on platform versions up to and 
    // including the version specified.
    
    // Modify the following defines if you have to target a platform prior to the ones specified below.
    // Refer to MSDN for the latest info on corresponding values for different platforms.
    #ifndef _WIN32_WINNT            // Specifies that the minimum required platform is Windows Vista.
    #define _WIN32_WINNT 0x0600     // Change this to the appropriate value to target other versions of Windows.
    #endif
    I'm running this on an XP computer, and VS didn't put #include "targetver.h" into the file containing main. How does this file work? Do I need to put #include "targetver.h" in main in order to activate the macros that this file is somehow calling up?

    Second, rather than the int main() that I have been using, VS supplies:

    int _tmain(int argc, _TCHAR* argv[])

    Just to see how (that) it works, I ran a "Hello, World" from there, and it worked fine. I'm just wondering what the parameters are doing here. It looks like it's giving you the opportunity to pass an int and an array of pointers to C-strings into main if you need to ... (?)

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    242
    one other thing on the targetver.h issue: What do I put in there to specify XP as the minimum platform? I'm not finding it in VS help anyway.

  3. #3
    Registered User
    Join Date
    Feb 2009
    Posts
    26
    I believe the arguments are for command-line arguments, and the integer holds the number of arguments, and the character arrays hold you arguments themselves, but I'm not sure.
    My Dev Blog - The most up-to-date info on my current projects.

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    242
    that makes sense. It looks a lot like Java's command line arguments.

  5. #5
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Quote Originally Posted by Aisthesis View Post
    I'm running this on an XP computer, and VS didn't put #include "targetver.h" into the file containing main. How does this file work? Do I need to put #include "targetver.h" in main in order to activate the macros that this file is somehow calling up?
    It's included by stdafx.h I believe, which will be included in main.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    The targetver.h file usually contains some code that allows you to target specific versions of the Windows platform. Searching for the name of the macro (ie _WINNT32_WINNT) might help you find some info on what to add or change to change what platform you target.
    As for the _tmain, it is basically a macro that changes the function name depending on if you unicode or multi-byte. If you multi-byte, it becomes main; otherwise it becomes wmain.
    The same with _TCHAR. It translates to char or wchar_t depending on if you are using Unicode or not.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Speed test result
    By audinue in forum C Programming
    Replies: 4
    Last Post: 07-07-2008, 05:18 AM
  2. How to use precompiled headers in GCC?
    By jutirain in forum C++ Programming
    Replies: 0
    Last Post: 02-04-2008, 10:19 PM
  3. Ping
    By ZakkWylde969 in forum Tech Board
    Replies: 5
    Last Post: 09-23-2003, 12:28 PM
  4. The Timing is incorret
    By Drew in forum C++ Programming
    Replies: 5
    Last Post: 08-28-2003, 04:57 PM
  5. Precompiled Headers, are they necessary?
    By XenoCodex Admin in forum C++ Programming
    Replies: 2
    Last Post: 06-23-2002, 02:09 PM