奇怪的编译器错误与代码::块 [英] Strange compiler errors with code::blocks

查看:160
本文介绍了奇怪的编译器错误与代码::块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我昨天从Visual Studio切换到Code :: Blocks,只是有一些奇怪的编译器错误消息。



我包括windows.h和我可以使用所有的API调用很好,例如创建窗口类和创建窗口/按钮和东西。但是当我试图用 SendInput()发送一些按键时,我得到这两个声明的错误信息:

  INPUT ip; 
KEYBDINPUT kbi;

编译器错误:



< C:\ code_blocks\test-app\main.cpp | 21 |错误:INPUT未在此范围中声明|
C:\ code_blocks\test-app\main.cpp | 22 |错误:'KEYBDINPUT'未在此范围内声明|

我甚至可以右键单击 KEYBDINPUT INPUT 结构体并单击查找声明,它在winuser.h(它在里面)中找到它,但它仍然给我这些错误消息,未声明。



此代码在VS中运行正常,只包括windows.h。我使用GNU GCC编译器。

解决方案

我认为你需要预处理器指令):



您有 _WIN32_WINNT 有什么定义?



也许您可以添加:

  #ifndef _WIN32_WINNT 
#define _WIN32_WINNT 0x0400
#endif

,或者可以将其添加到预处理器伪指令中,作为编译序列的一部分。任何好的编译器都会有它。



如果它仍然不工作,删除包含守卫和直接定义。



一些编译器在预处理器指令设置中会有这样的设置: WIN32,_DEBUG,_CONSOLE,_MBCS,_WIN32_WINNT = 0x0400


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.

解决方案

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

这篇关于奇怪的编译器错误与代码::块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆