Creating Win32 events from c#

前端 未结 2 1589
甜味超标
甜味超标 2021-02-13 20:10

I\'d like create a kernel(aka named events) from C#.

Do I have to interop services and wrap the native CreateEvent function or is there already a .NET class that does t

2条回答
  •  天命终不由人
    2021-02-13 20:56

    If you still want to use interop, you can define the function like this:

    [DllImport("kernel32.dll")]
    static extern IntPtr CreateEvent(IntPtr lpEventAttributes, bool bManualReset, bool bInitialState, string lpName);
    

    and the struct like this(you may have to mess with the Pack attribute to make it fit):

    [StructLayout(LayoutKind.Sequential)]
    struct SECURITY_ATTRIBUTES{
      public int length;
      public IntPtr securityDesc;
      public bool inherit;
    }
    

    Also, here's a code example of putting it all together.

提交回复
热议问题