###User Defined Function###
_WinAPI_CreateMutex

###Description###
Creates or opens a named or unnamed mutex object.

###Syntax###
#include <WinAPIProc.au3>
_WinAPI_CreateMutex ( $sMutex [, $fInitial = 1 [, $tSecurity = 0]] )


###Parameters###
@@ParamTable@@
$sMutex
	The name of the mutex object. Name comparisons are case sensitive.
$fInitial
	[optional] Specifies whether the calling process obtains the initial ownership of the mutex object, valid values:
	True      - The calling thread obtains initial ownership of the mutex object (Default).
	False     - The calling thread does not obtain ownership of the mutex object.
$tSecurity
	[optional] $tagSECURITY_ATTRIBUTES structure that specifies a security descriptor for the new mutex. If this
	parameter is 0 (Default), the mutex gets a default security descriptor.
@@End@@

###ReturnValue###
@@ReturnTable@@
Success 	The handle to the newly created mutex object.
Failure 	0, call <a href="_WinAPI_GetLastError.htm">_WinAPI_GetLastError()</a> to get extended error information.
@@End@@


###Remarks###
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, <a href="_WinAPI_GetLastError.htm">_WinAPI_GetLastError()</a> returns ERROR_ALREADY_EXISTS (183), $fInitial 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 (5) and the caller should use the _WinAPI_OpenMutex() function.

Any process can specify the mutex-object handle in a call to one of the wait functions. The single-object wait
functions return when the state of the specified object is signaled. The multiple-object wait functions can be
instructed to return either when any one or when all of the specified objects are signaled. When a wait function
returns, the waiting thread is released to continue its execution.

Two or more processes can call _WinAPI_CreateMutex() to create the same named mutex. The first process actually
creates the mutex, and subsequent processes with sufficient access rights simply open a handle to the existing
mutex. This enables multiple processes to get handles of the same mutex, while relieving the user of the responsibility
of ensuring that the creating process is started first. When using this technique, you should set the $fInitial
parameter to False; otherwise, it can be difficult to be certain which process has initial ownership.

Use the _WinAPI_CloseHandle() function to close the handle. The system closes the handle automatically when the
process terminates. The mutex object is destroyed when its last handle has been closed.


###Related###
_WinAPI_OpenMutex, _WinAPI_CloseHandle


###See Also###
@@MsdnLink@@ CreateMutex
