Kernel32CreateMutex Method
Namespace: DevCase.Win32.NativeMethodsAssembly: 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 CreateMutex(
[OptionalAttribute] SecurityAttributes mutexAttributes,
bool initialOwner,
[OptionalAttribute] string name
)
<DllImportAttribute("Kernel32.dll", CharSet := CharSet.Auto, BestFitMapping := false,
ThrowOnUnmappableChar := true, SetLastError := true>]
Public Shared Function CreateMutex (
<OptionalAttribute> mutexAttributes As SecurityAttributes,
initialOwner As Boolean,
<OptionalAttribute> name As String
) As IntPtr
Dim mutexAttributes As SecurityAttributes
Dim initialOwner As Boolean
Dim name As String
Dim returnValue As IntPtr
returnValue = Kernel32.CreateMutex(mutexAttributes,
initialOwner, name)
public:
[DllImportAttribute(L"Kernel32.dll", CharSet = CharSet::Auto, BestFitMapping = false,
ThrowOnUnmappableChar = true, SetLastError = true)]
static IntPtr CreateMutex(
[OptionalAttribute] [InAttribute] SecurityAttributes mutexAttributes,
bool initialOwner,
[OptionalAttribute] [InAttribute] String^ name
)
[<DllImportAttribute("Kernel32.dll", CharSet = CharSet.Auto, BestFitMapping = false,
ThrowOnUnmappableChar = true, SetLastError = true)>]
static member CreateMutex :
[<OptionalAttribute>] mutexAttributes : SecurityAttributes *
initialOwner : bool *
[<OptionalAttribute>] name : string -> IntPtr
No code example is currently available or this language may not be supported.
- 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.
- initialOwner Boolean
-
If this value is and the caller created the mutex,
the calling thread obtains initial ownership of the mutex object.
Otherwise, the calling thread does not obtain ownership of the mutex.
To determine if the caller created the mutex, see the return value section.
- 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 ().
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.