我有一些事件句柄,并将它们添加到列表中。我想知道我是否可以存储这些句柄,关闭本地句柄,以后仍然使用存储的句柄。
例子:
std::map<std::string, HANDLE> Events;
DWORD OpenSingleEvent(std::string EventName, bool InheritHandle, DWORD dwDesiredAccess, DWORD dwMilliseconds)
{
Handle hEvent = OpenEvent(dwDesiredAccess, InheritHandle, EventName.c_str()); //Local Handle.
if (hEvent)
{
DeleteSingleEvent(EventName); //Delete the correct/old handle in the map.
Events.insert(EventName, hEvent); //Add this new handle to the map.
DWORD Result = WaitForSingleObject(hEvent, dwMilliseconds);
CloseHandle(hEvent); //Close THIS handle. Not the one in my Map.
return Result;
}
CloseHandle(hEvent); //Close this handle.
return WAIT_FAILED;
}
上面的方法有用吗?如果没有,还有其他方法可以做到这一点吗?它用于共享内存通信,所以我不能复制句柄,因为我只有客户端 PID 而不是服务器的。
也有人可以解释 InheritHandle 的作用吗?我使用的函数是 OpenEvent,它具有该参数,但我不确定它的作用。