如何从句柄获取事件的名称

发布于 2024-08-07 22:37:05 字数 324 浏览 4 评论 0原文

我有一组 Win32 事件句柄,正在使用 WaitForMultipleObjects() 等待它们。这将返回触发的事件数组中的索引,但我需要知道的是事件的名称。我一直在浏览 MSDN,但看不到任何可以执行此操作的内容。

基本上,我有一个类,它在定义的时间段内使用 RegNotifyChangeKeyValue() 通过事件监视注册表,但在启动之前,其他类会注册对键和值的兴趣。然后,我在一个单独的线程上等待并报告已修改的键的名称。事件名称是该事件的关键,直到运行时我才知道其中会有多少个或者它们将被称为什么。我不想为每个键创建一个线程,因为它的性能不是很好。

有谁知道如何获取事件名称或更好的方法?

I have an array of Win32 event handles that I'm waiting on using WaitForMultipleObjects(). This returns the index in the array of events that triggered but what I need to know is the name of the event. I've been looking through MSDN and can't see anything to do this.

Basically I have a class that monitors the registry through events using RegNotifyChangeKeyValue() for a defined period of time but before it starts other classes register there interest in keys and values. I then wait on a separate thread and report back the name of the keys that have been modified. The event name is the key that the event is for and I don't know until runtime how many of these there will be or what they will be called. I don't want to create one thread per key as it's not very performant.

Does anyone know how to get the event name or a better way of doing this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

紫罗兰の梦幻 2024-08-14 22:37:05

您可能可以使用未记录的 NT 内容来完成此操作,也许 NtQueryObject(handle,ObjectNameInformation,....)

You could probably do it with undocumented NT stuff, maybe NtQueryObject(handle,ObjectNameInformation,....)

等待我真够勒 2024-08-14 22:37:05

就我个人而言,我不会那样做。在事件和键名称之间创建您自己的映射(std::map?),然后在发出事件信号时执行您自己的查找。

Personally I wouldn't do it that way. Create your own mapping (std::map?) between event and key name and then do your own lookup when an event is signalled.

醉殇 2024-08-14 22:37:05

通常,事件的名称用于调用 OpenEvent() 来获取句柄。这样,您不需要在运行时传递句柄,而是确定事件名称的命名约定。

我可以想到三种方法来做到这一点:

  • 循环所有硬编码事件名称并调用 OpenEvent()
  • 将句柄和名称保存在 std::map 中
  • 创建一个类来存储句柄和名称(可能在 std:: map),并编写方法以快速从句柄获取名称。

您是否根据事件的名称决定采取哪些操作?一个“if else if”语句,它逐一检查句柄的名称以确定要采取什么操作?这种情况通常会让我考虑将继承作为一种潜在的解决方案。请耐心等待一下。

如果您创建一个基类(例如 EventAction)怎么办?它有一个事件句柄和一个虚拟成员函数 go_go_commandos()。您可以从它派生出每个需要采取操作的“事件”,并在每个派生类的 go_go_commandos() 方法中实现该操作。

现在你需要的是一个容器,这样你就可以说actionlist->GetEventAction(handle)->go_go_commandos()。

这有帮助吗?

Normally the name of an event is used to call OpenEvent() to get the Handle. This way, you don't need to communicate a handle at runtime, but instead settle on a naming convention for the name of the event.

I can think of three ways to do this:

  • Loop over all hard-coded event names and call OpenEvent()
  • Save the handles and names in an std::map
  • Create a class to store your handles and names (possibly in an std::map), and write methods to quickly get a name from a handle.

Are you deciding what actions to take based on the name of the event? An 'if else if' statement that checks the names of the handles one-by-one to determine what action to take? This kind of scenario usually leads me to consider inheritance as a potential solution. Bear with me for a bit.

What if you create a base class, say EventAction. This has a handle to an event, and a virtual member function go_go_commandos(). You derive from it for each 'event' that has an action to be taken, and implement the action in the go_go_commandos() method of each deriving class.

Now what you need is a container so you can say actionlist->GetEventAction( handle )->go_go_commandos().

Did that help at all?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文