Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have one exe which creates set of events.This event creation sometimes return error code 5 sometimes it is successful.

HANDLE event1 = CreateEvent(NULL, FALSE, FALSE,"Global\\event1");
if (NULL == event1)
{
DBG_TRACE_L1("Create event1 failed with an error code: "<< GetLastError());
}

HANDLE hEvent2= CreateEvent(NULL, FALSE, FALSE,"Global\\hEvent2");
if (NULL == hEvent2)
{
DBG_TRACE_L1("Create hEvent2 failed with an error code: "<< GetLastError());
}
HANDLE hEvent3= CreateEvent(NULL, FALSE, FALSE,"Global\\hEvent3");
if (NULL == hEvent3)
{
DBG_TRACE_L1("Create hEvent3 failed with an error code: "<< GetLastError());
}




when i try to open the event am getting error code 5

What I have tried:

I have one exe  which creates set of events.This event creation sometimes return error code 5 sometimes it is successful.

HANDLE event1 = CreateEvent(NULL, FALSE, FALSE,"Global\\event1");
    if (NULL == event1)
    {
		DBG_TRACE_L1("Create event1 failed with an error code: "<< GetLastError());
    }
	
	HANDLE hEvent2= CreateEvent(NULL, FALSE, FALSE,"Global\\hEvent2");
    if (NULL == hEvent2)
    {
		DBG_TRACE_L1("Create hEvent2 failed with an error code: "<< GetLastError());
    }
	HANDLE hEvent3= CreateEvent(NULL, FALSE, FALSE,"Global\\hEvent3");
    if (NULL == hEvent3)
    {
		DBG_TRACE_L1("Create hEvent3  failed with an error code: "<< GetLastError());
    }




 when i try to open the event am getting error code 5
Posted
Updated 8-Nov-19 19:40pm
Comments
Richard MacCutchan 8-Nov-19 9:47am    
Where is the code that calls OpenEvent?

You need to have to correct access rights (as administrator) for the "Global" namespace.

If the event is already created, than you cant re create it. Read the documentation about CreateEvent.
 
Share this answer
 
Comments
Member 14648774 8-Nov-19 8:08am    
If the event is already created, createevent will fail.But the openevent should not fail in that case right?.openevent will return the already existing handle?
According to this MS error page, error code 5 is "Access is denied". The application probably did not run with administrator rights. Since your CreateEvent fails, OpenEvent will fail too.

According to this MSDN CreateEvent Page,

Quote:
If the function succeeds, the return value is a handle to the event object. If the named event object existed before the function call, the function returns a handle to the existing object and GetLastError returns ERROR_ALREADY_EXISTS.

If the function fails, the return value is NULL. To get extended error information, call GetLastError.


ERROR_ALREADY_EXISTS is code 183. Right-click on your executable and run as administrator to see the "access is denied" problem still persists. The program that open the events also needs to run as an administrator because it is accessing a global object.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900