I have a process that creates a named event, using ::CreateEvent.
In my process, I want to check whether the event exists or not, but I don’t want to create the event in case it doesn’t exist.
How can I do it?
I can do it like this, but then the event will be created in case it doesn’t exist:
HANDLE hEvent;
hEvent= ::CreateEvent(NULL, FALSE, FALSE, _T("MyEvent"));
if (::GetLastError() != ERROR_ALREADY_EXISTS)
{
.......
}
OpenEventdoes not create the event if it doesn’t already exist, so your code already almost does what you want. You need to check the event handle forNULLbefore checking the error code: