访问Windows句柄 [英] Accessing Windows handle

查看:83
本文介绍了访问Windows句柄的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个类中声明了一个事件句柄对象。我需要在另一个类中访问该句柄。

I have an event handle object declared in one class. I need that handle to be accessible in another class.

class A
{

private:
HANDLE m_hEvent;

void DoSomthing()
{
...
...
SetEvent(m_eEvent);
}
}


class B
{

  void Do()
{
 Initialize  the handle and wait for the event to set
}
}


是否可以声明他处理第二类的朋友并使用它?使用这样的手柄是一个好的设计吗?因为我有这样的场景。还有其他方法吗?

Is it OK to declare he handle a friend of the second class and use it? Is it a good design to use handles like this? Because I have such a a scenario .Is there any other method?

推荐答案


[...]还有其他方法吗?

[...] Is there any other method?

我认为您也可以在两个类中调用 CreateEvent ,通过
lpName 参数。 (参见 OpenEvent )。如果
A B 处于不同的流程中,这也是合适的。

I think that you can also call CreateEvent in both of the classes, specifying the same name via lpName parameter. (See OpenEvent too). This is also suitable if A and B are in different processes.


这篇关于访问Windows句柄的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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