OpenSemaphore

  HANDLE OpenSemaphore(fdwAccess, fInherit, lpszName)    
  DWORD fdwAccess; /* desired access flag */
  BOOL fInherit; /* will child process inherit? */
  LPTSTR lpszName; /* name of the semaphore */

The OpenSemaphore function opens a named semaphore object.

Parameters

fdwAccess

Specifies the desired access to the semaphore object. For NT/Win32, this access is checked against any security descriptor on the target semaphore.

This parameter can have some combination of the following values:

Value Meaning

SEMAPHORE_MODIFY_STATE  
  Specifies modify state access (release) to the semaphore.
SYNCHRONIZE  
  Specifies synchronization access (wait) to the semaphore.
SEMAPHORE_ALL_ACCESS  
  Specifies all possible access flags for the semaphore.

fInherit

Specifies whether the returned handle will be inherited by a new process created by the current process. A value of TRUE indicates that the new process will inherit the handle.

lpszName

Pointer to a null-terminated string that names the semaphore to be opened.

Return Value

If the function is successful, the return value is an open handle to the specified semaphore. Otherwise, the return value is NULL. Use the GetLastError function to obtain extended error information.

Comments

The OpenSemaphore function succeeds if the named semaphore exists and the security descriptor for the semaphore allows the access requested by the fdwAccess parameter.

If the function is successful, the handle is granted access to the semaphore object only to the extent requested by the fdwAccess parameter.

The handle that OpenSemaphore returns may be used with any function that requires a handle to a semaphore object.

The OpenSemaphore function may be used as either a wide-character function (where text arguments must use Unicode) or an ANSI function (where text arguments must use characters from the Windows 3.x character set installed).

See Also

CreateSemaphore, CloseHandle, WaitForSingleObject, WaitForMultipleObjects