C ++事件挂钩 [英] C++ Event Hooks

查看:192
本文介绍了C ++事件挂钩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图理解C ++中的事件钩子。我知道一个事件是什么,我在Java,C#和Javascript中使用过很多。

I'm trying to understand event hooks in C++. I know what an event is, I've used them a lot in Java, C# and Javascript.

我遇到的麻烦是找到文档和教程例如全局钩子,dll注入,没有DLL的全局钩子。

What I'm having trouble with is finding the documentation, and tutorials on stuff like global hooks, dll injection, global hooks without a DLL.

我想在FireFox中迭代浏览器tabis。我需要希望FireFox有一个C ++的API?或者让我说,当用户打开一个新的选项卡时,我需要使用一个钩子,FireFox将在其API中提供的钩子。

Lets say that I wanted to iterate through the browser tabis in FireFox .. would I need to hope that FireFox has an API for C++? Or lets say I wanted to do something when a user opens a new tab would I need to use a hook that FireFox would provide in their API?

上面只是一个例子,所以人们知道我想学习/理解。

The above is just an example so people know what I'm trying to learn/understand. Am I thinking on the right ines?

我在论坛上看到一篇文章,过去2小时内我已经感兴趣了。我总是说,一个棘手的挑战或一个新的挑战,使一个更强大的程序员。

I seen a post on a forum and for the past 2 hours I've took an interest. I always say that a tricky challange, or a new challange, makes a stronger programmer.

任何资源或任何帮助,将非常感激。

Any resources, or any help, would be very much appreciated.

推荐答案

C ++本身没有事件或钩子,但很多C ++库和框架实现它们。有关通用事件库的示例,请参见 Boost.Signals

C++ itself does not have events or hooks, but a lot of C++ libraries and frameworks implement them. For an example of generic events library, see Boost.Signals.

一些实现允许其他应用程序看到它们的事件,但API是特定于应用程序的(例如,对于Firefox,请参阅 XPCOM )。



Windows有一个钩子机制,允许监视其窗口系统中的各种事件。但是,它是一个操作系统功能,与C ++无关。因为它是一个系统机制,所有Windows应用程序都受到影响,即使他们不为它做任何事情。有关Windows钩子的文档,请访问此处 。此外,由于您提到了没有DLL的全局钩子,请参阅 SetWinEventHook ,这是一个比上面链接的Windows钩子更高级的API,可以用于在DLL或EXE中实现的钩子函数。

Some of the implementations allow their events to be seen by other applications, but the API is application-specific (e.g. for Firefox, see XPCOM).


Windows has a mechanizm of hooks that allows to monitor various events in its windowing system. However, it is an OS feature, not related to C++. As it's a system mechanizm, all Windows applications are affected even if they don't do anything for it. The documentation for Windows hooks can be found here. Also, since you mentioned "global hooks without a DLL", see SetWinEventHook, which is a higher-level API than Windows hooks linked above and can be used with hook functions both implemented in DLLs or EXEs.

这篇关于C ++事件挂钩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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