views:

306

answers:

2

I'm compiling my application on a new box (vista 64) and now it doesn't compile anymore. The compiler gives me the error in the title. The problem seems(?) to be that HWINEVENTHOOK is defined twice in

windef.h

#if(WINVER >= 0x0400)
DECLARE_HANDLE(HWINEVENTHOOK);
#endif /* WINVER >= 0x0400 */

and then in winable.h it's

#if WINVER < 0x0500 // these structures and functions
                    // are in NT 5.00 and above winuser.h
typedef DWORD   HWINEVENTHOOK;

However, I just looked up WINVER for vista and it is 0x0600 and windows XP is 0x0501 so why is DWORD being defined? I'm at a loss. Anyone help?

+2  A: 

According to this MSDN forum thread:

winable.h was moved from the Windows SDK in July 2005 because functionality was duplicated in winuser.h. It was determined at that time that efforts would be better spent on updating winuser.h to Windows Vista-level functionality rather than updating the functionality of both files.

What version of the Windows SDK are you using, and what Windows version is your code targetting? The target Windows version may be specified in a makefile, project file, or header file. Compiling your code on Vista doesn't necessarily mean that the target version is Vista.

Also, have you tried switching from winable.h to winuser.h?

bk1e
Ok, switching to winuser.h solved it. I think i was including both. Thanks. Your help was very valuable. I appreciate it.
+1  A: 

You might need to explicitly set WINVER to the version corresponding to the minimum version of Windows you are targeting. I suspect its default value is not much above Win2K...

You could check its default value with a quick (untested) hack like this:

#include <windows.h>
#include <stdio.h>
int main(int argc, char **argv) {
    printf("WINVER=0x%04x\n", WINVER);
    return 0;
}

Compiled as a console app and run at the command prompt it might provide a clue. Otherwise, you'll spend ages chasing through include files trying to identify where it set the default.

Edit: In general, it is safest to always specify WINVER for a project. Either do it in the project settings in Visual Studio (and for all builds, not just the current build!) or do it in a common header file included by every module in the project. Doing so explicitly will reduce the chance that different build environment might have a different assumption.

RBerteig
... and make sure you set it to the same value for the project, not just some files!
Greg Domjan