提问人:Kevin 提问时间:7/22/2012 最后编辑:CommunityKevin 更新时间:3/29/2021 访问量:7918
“INPUT”未在此范围内声明
'INPUT' was not declared in this scope
问:
我正在尝试编译一个我几年前编写的程序,该程序可以模拟鼠标点击和击键。我把它简化为这个最小的例子:
#include "Windows.h"
int main(){
INPUT foo;
return 0;
}
它给了我这个错误:
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 的 INPUT 页面说它是在 Windows.h 中定义的,所以我不知道为什么它无法识别该类型。
另一个 stackoverflow 用户在这里遇到了类似的问题,但他们的解决方案 adding 并没有修复错误。#define _WIN32_WINNT 0x0500
几年前,我就能够在 Windows XP 上构建该程序。难道 INPUT 在 Windows 7 上无法像在 XP 上那样工作吗?或者也许我忘了向编译器提供标志?
答:
7赞
chris
7/22/2012
#1
你把你放错了位置。这样做的结果是 see 为 undefined,因此未声明。然后,在存在的机会过去后定义它。#define
#include
windows.h
_WIN32_WINNT
INPUT
INPUT
#define _WIN32_WINNT 0x0500 //RIGHT
#include "Windows.h"
#define _WIN32_WINNT 0x0500 //WRONG
int main(){
INPUT foo;
return 0;
}
顺便说一句,除非与源文件位于同一目录中,否则通常应使用 而不是 .windows.h
#include <>
#include ""
评论
0赞
HeavenHM
3/30/2018
定义 WIN32_WINNT _ >= 0x0403 就足够了。
上一个:基于另一个表更新行
评论
include
main
include