Click here to Skip to main content
15,898,010 members

C++: Global event opening problem

Alexey Loire asked:

Open original thread
Hey there, everyone.
While workin on my app i stuck with quite a problem: Application consists of two parts. Service and GUI. GUI while finishing work with data needs to set named global event into alerted state but it does not for some reason. Named Global Event is created by Service. And everything looks fine(no errors during creation)
Event at first was created with default SECURITY_ATTRIBUTES. But when i try openning Event from GUI application a recieve error 5 (ERROR_ACCESS_DENIED).
Then i tried with filled SECURITY_ATTRIBUTES structure and now i get error 2 (ERROR_FILE_NOT_FOUND).
Service part:
C++
#define UI_ACTION_EVENT L"Global\\APPLICATION_GLOBAL_EVENT"

  DWORD dwRes;
  SECURITY_ATTRIBUTES sa;
  PSECURITY_DESCRIPTOR pSD = NULL;
  SID_IDENTIFIER_AUTHORITY SIDAuthWorld = SECURITY_WORLD_SID_AUTHORITY;
  PACL pAcl = NULL;
  PSID pEveryoneSID = NULL;
  EXPLICIT_ACCESS ea[1];
  //Creation of SID for the Everyone group
  if(!AllocateAndInitializeSid(
    &SIDAuthWorld,   //PSID_IDENTIFIER_AUTHORITY
    1,               //nSubAuthorityCount
    SECURITY_WORLD_RID,     //nSubAuthority0
    0, 0, 0, 0, 0, 0, 0,    //Not used subAuthorities.
    &pEveryoneSID))         //Callback argument that recieves pointer to the allocated and initialized SID structure
  {
    LogMakeRecord(L"AllocateAndInitializeSid() Error.");
  }

  //Filling in EXPLICIT_ACCESS structure. Everyone's group members will have all the permissions on event.
  ZeroMemory(&ea, sizeof(EXPLICIT_ACCESS));
  ea[0].grfAccessPermissions = EVENT_ALL_ACCESS;
  ea[0].grfAccessMode = SET_ACCESS;
  ea[0].grfInheritance = NO_INHERITANCE;
  ea[0].Trustee.TrusteeForm = TRUSTEE_IS_SID;
  //ea[0].Trustee.TrusteeType = TRUSTEE_IS_GROUP;
  ea[0].Trustee.TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP;
  ea[0].Trustee.ptstrName = (LPTSTR)pEveryoneSID;

  //Creation of new ACL that contains the new ACE.
  dwRes = SetEntriesInAcl(1, ea, NULL, &pAcl);
  if(dwRes != ERROR_SUCCESS)
  {
    LogMakeRecord(L"SetEntriesInAcl() Error.");
  }

  //Security Descriptor initialization
  pSD = (PSECURITY_DESCRIPTOR) LocalAlloc(LPTR, SECURITY_DESCRIPTOR_MIN_LENGTH);
  if (pSD == NULL)
  {
    LogMakeRecord(L"LocalAlloc() Error.");
  }

  if(!InitializeSecurityDescriptor(pSD, SECURITY_DESCRIPTOR_REVISION))
  {
    LogMakeRecord(L"InitializeSecurityDescriptor() Error.");
  }
  
  //Adding ACL to Security Descriptor.
  if(!SetSecurityDescriptorDacl(pSD, TRUE, pAcl, FALSE))
  {
    LogMakeRecord(L"SetSecurityDescriptorDacl() Error.");
  }
  
  //Initialize Security Attributes structure.
  sa.nLength = sizeof(SECURITY_ATTRIBUTES);
  sa.lpSecurityDescriptor = pSD;
  sa.bInheritHandle = FALSE;

  
  HANDLE hUIActionEvent = CreateEvent(&sa, TRUE, FALSE, UI_ACTION_EVENT);


GUI part:
C++
#define UI_ACTION_EVENT L"Global\\APPLICATION_GLOBAL_EVENT"

HANDLE uiEvent = OpenEvent(EVENT_MODIFY_STATE, FALSE, UI_ACTION_EVENT);
  if (uiEvent != NULL)
  {
    if (SetEvent(uiEvent) == 0)
    {
      ASSERT(FALSE);
      #ifdef _DEBUG
      DWORD error = GetLastError();
      error = error;
      #endif
    }
  }
  else
  {
    #ifdef _DEBUG
    DWORD error = GetLastError();
    error = error;
    #endif
  }


The goal is: to make global event accessible to EveryOne group on pc.
I've tried searching similar posts on the internet but had no luck with it.
Looking forward to hearing from ya guys.
Tags: C++, Event

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



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