Kernel32CreateMutexEx(SecurityAttributes, String, CreateMutexFlags, StandardAccessRights) Method

Creates or opens a named or unnamed mutex object and returns a handle to the object.

Definition

Namespace: DevCase.Win32.NativeMethods
Assembly: DevCase.net48 (in DevCase.net48.dll) Version: 6.0.0.0 (6.0)
XMLNS for XAML: Not mapped to an xmlns.
[DllImportAttribute("Kernel32.dll", CharSet = CharSet.Auto, BestFitMapping = false, 
	ThrowOnUnmappableChar = true, SetLastError = true)]
public static IntPtr CreateMutexEx(
	[OptionalAttribute] SecurityAttributes mutexAttributes,
	[OptionalAttribute] string name,
	CreateMutexFlags flags,
	StandardAccessRights desiredAccess
)

Parameters

mutexAttributes  SecurityAttributes  (Optional)
A pointer to a SecurityAttributes structure.

If this parameter is NULL, the mutex handle cannot be inherited by child processes.

The SecurityDescriptor member specifies a security descriptor for the new mutex.

If mutexAttributes is NULL, the mutex gets a default security descriptor.

The ACLs in the default security descriptor for a mutex come from the primary or impersonation token of the creator.

name  String  (Optional)
The name of the mutex object. The name is limited to MAX_PATH characters. Name comparison is case sensitive.

If name is NULL, the mutex object is created without a name.

If name matches the name of an existing event, semaphore, waitable timer, job, or file-mapping object, the function fails and the GetLastError function returns ERROR_INVALID_HANDLE. This occurs because these objects share the same namespace.

The name can have a "Global" or "Local" prefix to explicitly create the object in the global or session namespace. The remainder of the name can contain any character except the backslash character ().

flags  CreateMutexFlags
Mutex creation flags.
desiredAccess  StandardAccessRights
The access mask for the mutex object.

Return Value

IntPtr
If the function succeeds, the return value is a handle to the newly created mutex object.

If the function fails, the return value is Zero.

If the mutex is a named mutex and the object existed before this function call, the return value is a handle to the existing object, GetLastError returns ERROR_ALREADY_EXISTS., InitialOwner is ignored, and the calling thread is not granted ownership.

However, if the caller has limited access rights, the function will fail with ERROR_ACCESS_DENIED and the caller should use the OpenMutex(UInt32, Boolean, String) function.

Remarks

See Also