Mike
Mike

Reputation:

C++ Windows API over-riding?

In VS9, when i call the GetTickCount() function, it automatically converts it into the GetTickCount64() function upon compilation. This second function only works on Vista+, and thus my program errors when run on XP.

How can I 'over-ride' this so that it calls the original GetTickCount() ?

Thanks

Upvotes: 1

Views: 782

Answers (3)

Michael Burr
Michael Burr

Reputation: 340516

Set WINVER to the version of windows you want to target. Or maybe it's _WIN32_WINNT or _WIN32_WINDOWS. Maybe even all of them...

Take a look at https://devblogs.microsoft.com/oldnewthing/20070411-00/?p=27283 for details on that small mess-o-version macros.

However, I don't see that redefinition at all in the Windows SDK - could there be something else in our setup that's doing the redefinition (or maybe I'm missing it...)?

Upvotes: 3

Mike
Mike

Reputation:

I set the following inside targetver.h:

#define WINVER 0x0501 
#define _WIN32_WINNT 0x0501
#define _WIN32_WINDOWS 0x0501 

and it still gets re-defined. However, when i create a simple new project that prints out GetTickCount(), it works fine on XP even without me having to define the above. I did not change anything in the project settings. The only difference between the sample GetTickCount() that works and the one that doesn't is that it has plenty of other code around it and using it, but none of that code should be changing anything.

What could be causing this?

EDIT: One of the other files I was using was calling GetTickCount64() directly, and I did not know about this, so I assumed it was my own GetTickCount() function. Please ignore what i wrote above

Upvotes: 0

Jim H.
Jim H.

Reputation: 5579

Remember that you're not compiling your application for Vista or Windows XP, rather you're compiling for a 32-bit or 64-bit operating system. If your application needs to support other versions of Windows than 64-bit Vista, then specify in your build options to be 32-bit.

Upvotes: 0

Related Questions