Platform SDK: DLLs, Processes, and Threads

OpenWaitableTimer

The OpenWaitableTimer function opens an existing named waitable timer object.

HANDLE OpenWaitableTimer(
  DWORD dwDesiredAccess,  // access
  BOOL bInheritHandle,    // inheritance option
  LPCTSTR lpTimerName     // object name
);

Parameters

dwDesiredAccess
[in] Specifies the requested access to the timer object. For systems that support object security, the function fails if the security descriptor of the specified object does not permit the requested access for the calling process.

This parameter can be any combination of the following values.
Value Meaning
TIMER_ALL_ACCESS Specifies all possible access rights for the timer object.
TIMER_MODIFY_STATE Enables use of the timer handle in the SetWaitableTimer and CancelWaitableTimer functions to modify the timer's state.
TIMER_QUERY_STATE Reserved for future use.
SYNCHRONIZE Windows NT/2000: Enables use of the timer handle in any of the wait functions to wait for the timer's state to be signaled.

bInheritHandle
[in] Specifies whether the returned handle is inheritable. If TRUE, a process created by the CreateProcess function can inherit the handle; otherwise, the handle cannot be inherited.
lpTimerName
[in] Pointer to a null-terminated string specifying the name of the timer object. The name is limited to MAX_PATH characters. Name comparison is case sensitive.

Terminal Services: The name can have a "Global\" or "Local\" prefix to explicitly open an object in the global or session name space. The remainder of the name can contain any character except the backslash character (\). For more information, see Kernel Object Name Spaces.

Windows 2000: On Windows 2000 systems without Terminal Services running, the "Global\" and "Local\" prefixes are ignored. The remainder of the name can contain any character except the backslash character.

Windows NT 4.0 and earlier, Windows 95/98: The name can contain any character except the backslash character.

Return Values

If the function succeeds, the return value is a handle to the timer object.

If the function fails, the return value is NULL. To get extended error information, call GetLastError.

Remarks

The OpenWaitableTimer function enables multiple processes to open handles to the same timer object. The function succeeds only if some process has already created the timer using the CreateWaitableTimer function. The calling process can use the returned handle in any function that requires the handle to a timer object, such as the wait functions, subject to the limitations of the access specified in the dwDesiredAccess parameter.

The returned handle can be duplicated by using the DuplicateHandle function. Use the CloseHandle function to close the handle. The system closes the handle automatically when the process terminates. The timer object is destroyed when its last handle has been closed.

Requirements

  Windows NT/2000: Requires Windows NT 4.0 or later.
  Windows 95/98: Requires Windows 98.
  Header: Declared in Winbase.h; include Windows.h.
  Library: Use Kernel32.lib.
  Unicode: Implemented as Unicode and ANSI versions on Windows NT/2000.

See Also

Synchronization Overview, Synchronization Functions, CancelWaitableTimer, CloseHandle, CreateProcess, CreateWaitableTimer, DuplicateHandle, SetWaitableTimer, Object Names