tags:

views:

66

answers:

2

I switched from Visual Studio to Code::Blocks yesterday, and just had some strange compiler error messages.

I included windows.h and i can use all the API calls just fine, such as creating window classes and creating windows / buttons and stuff. But when I tried to send some keypresses with SendInput(), I got error messages on these two declarations:

INPUT ip;
KEYBDINPUT kbi;

Compiler errors:

C:\code_blocks\test-app\main.cpp|21|error: 'INPUT' was not declared in this scope|
C:\code_blocks\test-app\main.cpp|22|error: 'KEYBDINPUT' was not declared in this scope|

I can even right click the KEYBDINPUT and INPUT structors and click on "Find declaration", it finds it inside the "winuser.h" (which is inside ), but it's still giving me these error messages that they are not declared.

This code works fine in VS with just windows.h included. I'm using the GNU GCC compiler.

+1  A: 

I think you need the pre-processor directives (Visual Studio may already add them):

What do you have _WIN32_WINNT defined as?

Perhaps you could add:

#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0400
#endif

or you can add it to your pre-processor directives as part of your compile sequence. Any good compiler will have it.

If it still doesn't work, remove the include guards and define it directly. Maybe it is getting defined elsewhere.

Some compilers will have this in the pre-processor directive settings: WIN32,_DEBUG,_CONSOLE,_MBCS,_WIN32_WINNT=0x0400

0A0D
well #define WINVER 0x0400 found in windef.h, which is inside windows.h and then #define _WIN32_WINNT WINVER I noticed i can't use anything at all in winuser.h
Finally, you got me on the right track, i defined WINVER as 0x0400, but it still didn't work, but then tried 0x0500, and it worked... thanks.
Great! Glad you fixed it
0A0D
+1  A: 

To elaborate on Changeling's answer, if you look at the documentation for say KEYBDINPUT, you will see that near the bottom it has a table of minimal supported OS versions. VC++ sets _WIN32_WINNT to a later version than MinGW/GCC (which I am guessing is the compiler you are using with Code::Blocks), which is probably why you have encountered this problem.

The purpose of this macro is to prevent you inadvertently using API's that are not compatible with your minimum intended target OS.

There are a number of version related macros used by Windows API headers. The details can be found here

Clifford