Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 265395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:45:56+00:00 2026-05-11T22:45:56+00:00

Windows provides only GetTickCount up to Windows Vista and starting from that OS also

  • 0

Windows provides only GetTickCount up to Windows Vista and starting from that OS also GetTickCount64. How can I make a C program compile with calls to different functions?

How can I make a C compiler check whether a function is declared in the included header files and compile different portions of code depending on whether that particular function is available or not?

#if ??????????????????????????????
unsigned long long get_tick_count(void) { return GetTickCount64(); }
#else
unsigned long long get_tick_count(void) { return GetTickCount(); }
#endif

Looking for a working sample file not just hints.

Edit: I tried the following using gcc 3.4.5 from MinGW on a (64-bit) Windows 7 RC but it didn’t help. If this is a MinGW problem, how can I work around this issue?

#include <windows.h>
#if (WINVER >= 0x0600)
unsigned long long get_tick_count(void) { return 600/*GetTickCount64()*/; }
#else
unsigned long long get_tick_count(void) { return 0/*GetTickCount()*/; }
#endif
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T22:45:56+00:00Added an answer on May 11, 2026 at 10:45 pm

    Previous answers have pointed out checking for the particular #define that would be present for your particular case. This answer is for a more general case of compiling different code whether a function is available or not.

    Rather than trying to do everything in the C file itself, this is the sort of thing where configure scripts really shine. If you were running on linux, I would point you to the GNU Autotools without hesitation. I know there’s ports available for Windows, at least if you’re using Cygwin or MSYS, but I have no idea how effective they are.

    A simple (and very very ugly) script that could work if you have sh handy (I don’t have a Windows setup handy to test this on) would look something like this:

    #!/bin/sh
    
    # First, create a .c file that tests for the existance of GetTickCount64()
    
    cat >conftest.c <<_CONFEOF
    #include <windows.h>
    int main() {
        GetTickCount64();
        return 0;
    }
    _CONFEOF
    
    # Then, try to actually compile the above .c file
    
    gcc conftest.c -o conftest.out
    
    # Check gcc's return value to determine if it worked.
    #   If it returns 0, compilation worked so set CONF_HASGETTICKCOUNT64
    #   If it doesn't return 0, there was an error, so probably no GetTickCount64()
    
    if [ $? -eq 0 ]
    then
        confdefs='-D CONF_HASGETTICKCOUNT64=1'
    fi
    
    # Now get rid of the temporary files we made.
    
    rm conftest.c
    rm conftest.out
    
    # And compile your real program, passing CONF_HASGETTICKCOUNT64 if it exists.
    
    gcc $confdefs yourfile.c
    

    This should be easy enough to translate into your scripting language of choice. If your program requires extra include paths, compiler flags, or whatever, make sure to add the necessary flags to both the test compile and the real compile.

    ‘yourfile.c’ would look something like this:

    #include <windows.h>
    
    unsigned long long get_tick_count(void) {
    #ifdef CONF_HASGETTICKCOUNT64
      return GetTickCount64();
    #else
      return GetTickCount();
    #endif
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WCF service that provides a couple of methods. A Windows Forms
I have a windows form that creates multiple console applications of the same program
I am writing a program that is using a database library. The library provides
I'm trying to access a repository on Github from a Windows machine that is
wxWidgets provides for notebooks with multiple lines of tabs only on Windows platforms. Is
Windows has a Performance Counters infrastructure. The OS provides some common counters, and I
Expression Blend + SketchFlow provides a template for Windows Phone rapid application prototyping which
I've got a Windows Forms control that I'm attempting to wrap as a WPF
I have an application that provides real time log messages for users. Currently the
I want to read status information that an application provides via shared memory. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.