创建键盘挂钩时发生编译器错误

问题描述

| 我正在向自己介绍如何在Win32 C ++中使用挂钩(特别是KeyboardHooks),并且遇到问题。 首先,我试图创建/声明一个HHook对象,但是当我这样做时,Microsoft Visual C ++给出了一个编译器错误,指出:
c:\\users\\soribo\\desktop\\c++ programming\\visual c++ programming\\testhhook\\testhhook\\testhhook.cpp(7): error C2146: syntax error : missing \';\' before identifier \'keyboardHook\'

1>c:\\users\\soribo\\desktop\\c++ programming\\visual c++ programming\\testhhook\\testhhook\\testhhook.cpp(7): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

1>c:\\users\\soribo\\desktop\\c++ programming\\visual c++ programming\\testhhook\\testhhook\\testhhook.cpp(7): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
这是生成此错误的代码行:
HHook keyboardHook; 
使用HHook类需要包括哪些Windows库?我已经做好了
#include <windows.h>
我的另一个问题是,使用这些挂钩是否需要UAC? 编辑:使用更多代码:
// TestHHook.cpp : Defines the entry point for the application.
//

     #include <windows.h>
#include \"stdafx.h\"
#include \"TestHHook.h\"

static HHook keyboardHook;
#define MAX_LOADSTRING 100

// Global Variables:
HINSTANCE hInst;                                // current instance
TCHAR szTitle[MAX_LOADSTRING];                  // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING];            // the main window class name

// Forward declarations of functions included in this code module:
ATOM                MyRegisterClass(HINSTANCE hInstance);
BOOL                InitInstance(HINSTANCE,int);
LRESULT CALLBACK    WndProc(HWND,UINT,WPARAM,LPARAM);
INT_PTR CALLBACK    About(HWND,LPARAM);
    

解决方法

        您正在使用区分大小写的语言。是挂钩,不是挂钩。     

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...