开发者

Strange compiler errors with code::blocks

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 开发者_StackOverflow中文版using the GNU GCC compiler.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜