title: How to detect event object created in .NET from Win32
body: <p>I am creating a named event object in .NET using interop calls like this:</p>
  
  <pre><code>[DllImport("kernel32.dll")]
  static extern IntPtr CreateEvent(IntPtr lpEventAttributes, bool bManualReset,
      bool bInitialState, [MarshalAs(UnmanagedType.LPWStr)] string lpName);
  
  const string EVENT_NAME = "Global\\unique_id_string";
  const uint SYNCHRONIZE = 0x00100000;
  const uint EVENT_MODIFY_STATE = 0x0002;
  hEvent = CreateEvent(IntPtr.Zero, true, false, EVENT_NAME);
  </code></pre>
  
  <p>And then I try to open this event from a Win32 program like this</p>
  
  <pre><code>WCHAR evntName[MAX_PATH] = {0};
  wcscpy(evntName, L"Global\\unique_id_string");
  HANDLE hEvent = OpenEvent(EVENT_MODIFY_STATE | SYNCHRONIZE, FALSE, evntName);
  </code></pre>
  
  <p>But the handle returned is always 0.</p>
  
  <p>When I try the same from another .NET application like this,</p>
  
  <pre><code>[DllImport("kernel32.dll")]
  static extern IntPtr OpenEvent(UInt32 dwDesiredAccess, bool bInheritable,
      [MarshalAs(UnmanagedType.LPWStr)] string lpName);
  
  const string EVENT_NAME = "Global\\unique_id_string";
  const uint SYNCHRONIZE = 0x00100000;
  const uint EVENT_MODIFY_STATE = 0x0002;
  
  IntPtr hEvent = OpenEvent(EVENT_MODIFY_STATE | SYNCHRONIZE, false, EVENT_NAME);
  </code></pre>
  
  <p>it works perfectly and returns the correct handle to the event.</p>
  
  <p>Why is it not working with the native C++ application? Is there something I am missing?</p>