Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

OpenEvent (kernel32)
 
.
Summary

C# Signature:

[DllImport("Kernel32.dll", SetLastError=true)]
static extern IntPtr OpenEvent(uint dwDesiredAccess, bool bInheritHandle, string lpName);

User-Defined Types:

None.

Notes:

None.

Tips & Tricks:

Tip 1: Use OpenEvent to open named event and attach it to AutoResetEvent class:

  AutoResetEvent are= new AutoResetEvent(false);
  are.Close();
  GC.ReRegisterForFinalize(are);
  are.Handle= handle; // handle from OpenEvent

Sample Code:

  // taken from header files
  const uint STANDARD_RIGHTS_REQUIRED    = 0x000F0000;
  const uint SYNCHRONIZE             = 0x00100000;
  const uint EVENT_ALL_ACCESS        = (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x3);
  const uint EVENT_MODIFY_STATE        = 0x0002 ;
  const long ERROR_FILE_NOT_FOUND        = 2L;

  // open event with error handling
  IntPtr handle= OpenEvent(EVENT_ALL_ACCESS | EVENT_MODIFY_STATE, false, name);
  int le= Marshal.GetLastWin32Error();
  if ((handle==IntPtr.Zero) && (le!=0) && (le!=ERROR_FILE_NOT_FOUND))
    throw new ApplicationException(string.Format("Fehler in Win32.CreateEvent: {0}: {1}", le, sle));

Alternative Managed API:

CreateEvent also opens an existing (named) event...

Documentation
OpenEvent on MSDN

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Find References
Show Printable Version
Revisions