I am trying to compile a program I wrote a few years ago that simulates mouse clicks and key strokes. I’ve reduced it to this minimal example:
#include "Windows.h"
int main(){
INPUT foo;
return 0;
}
It gives me this error:
C:\projects\clicker>g++ minimaltest.cpp
minimaltest.cpp: In function 'int main()':
minimaltest.cpp:4:2: error: 'INPUT' was not declared in this scope
minimaltest.cpp:4:8: error: expected ';' before 'foo'
MSDN’s page on INPUT says it’s defined in Windows.h, so I don’t know why it doesn’t recognize the type.
Another stackoverflow user had a similar problem here, but their solution, adding #define _WIN32_WINNT 0x0500, didn’t fix the errors.
I was able to build the program years ago on windows XP. Could it be that INPUT doesn’t work on Windows 7 the way it did on XP? Or maybe I forgot to supply a flag to the compiler?
You’ve misplaced your
#defineto after the#include. The result of this is thatwindows.hsees_WIN32_WINNTas undefined, soINPUTis not declared. Then you define it afterINPUT‘s chance of existing has passed.As a side note, unless
windows.his in the same directory as the source file, it should typically be imported using#include <>rather than#include "".