[StructLayout(LayoutKind.Sequential)]
public struct SECURITY_ATTRIBUTES
{
public int nLength;
public IntPtr lpSecurityDescriptor;
public int bInheritHandle; // BOOL
}
Structure SECURITY_ATTRIBUTES
Public TODO
End Structure
None.
SECURITY_DESCRIPTOR sd = new SECURITY_DESCRIPTOR();
InitializeSecurityDescriptor(ref sd, 1);
SetSecurityDescriptorDacl(ref sd, 1, IntPtr.Zero, 0);
GCHandle sdHandle = GCHandle.Alloc(sd, GCHandleType.Pinned);
try
{
SECURITY_ATTRIBUTES sa = new SECURITY_ATTRIBUTES();
sa.nLength = Marshal.SizeOf(sa);
sa.lpSecurityDescriptor = sdHandle.AddrOfPinnedObject();
sa.bInheritHandle = 0;
this.Handle = CreateSemaphore(ref sa, 0, int.MaxValue, name);
if (Handle.ToInt32() == 0)
{
int errNo = (int) GetLastError();
throw new Win32Exception(errNo , "Error " + errNo + " creating semaphore " + name);
}
}
finally
{
sdHandle.Free();
}