'INPUT' was not declared in this scope
c++, winapi
Solution
You've misplaced your `#define` to after the `#include`. The result of this is that `windows.h` sees `_WIN32_WINNT` as undefined, so `INPUT` is not declared. Then you define it after `INPUT`'s chance of existing has passed.
#define _WIN32_WINNT 0x0500 //RIGHT
#include "Windows.h"
#define _WIN32_WINNT 0x0500 //WRONG
int main(){
INPUT foo;
return 0;
}
As a side note, unless `windows.h` is in the same directory as the source file, it should typically be imported using `#include <>` rather than `#include ""`.
Problem
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?