访问Windows句柄 [英] Accessing Windows handle
问题描述
我在一个类中声明了一个事件句柄对象。我需要在另一个类中访问该句柄。
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屋!