Platform SDK: DLLs, Processes, and Threads

OpenThread

The OpenThread function opens an existing thread object.

HANDLE OpenThread(
  DWORD dwDesiredAccess,  // access right
  BOOL bInheritHandle,    // handle inheritance option
  DWORD dwThreadId        // thread identifier
);

Parameters

dwDesiredAccess
[in] Specifies the desired access to the thread object. For operating systems that support security checking, this access level is checked against any security descriptor for the target thread. This parameter can be STANDARD_RIGHTS_REQUIRED or any combination of the following values.
Value Description
SYNCHRONIZE Enables the use of the thread handle in any of the wait functions.
THREAD_ALL_ACCESS Specifies all possible access flags for the thread object.
THREAD_GET_CONTEXT Enables the use of the thread handle in the GetThreadContext function.
THREAD_QUERY_INFORMATION Enables the use of the thread handle to read certain information from the thread object, such as the exit code (see GetExitCodeThread).
THREAD_SET_CONTEXT Enables the use of the thread handle in the SetThreadContext function.
THREAD_SET_INFORMATION Enables the use of the thread handle to set certain information for the thread object.
THREAD_SET_THREAD_TOKEN Enables the use of the thread handle in the SetTokenInformation function to set the thread token.
THREAD_SUSPEND_RESUME Enables the use of the thread handle in the SuspendThread or ResumeThread function to suspend and resume the thread.
THREAD_TERMINATE Enables the use of the thread handle in the TerminateThread function to terminate the thread.

bInheritHandle
[in] Indicates whether the returned handle is to be inherited by a new process created by the current process. If this parameter is TRUE, the new process will inherit the handle.
dwThreadId
[in] Specifies the identifier of the thread to open.

Return Values

If the function succeeds, the return value is an open handle to the specified process.

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

Remarks

The handle returned by OpenThread can be used in any function that requires a handle to a thread, such as the wait functions, provided you requested the appropriate access rights. The handle is granted access to the thread object only to the extent it was specified in the dwDesiredAccess parameter.

When you are finished with the handle, be sure to close it by using the CloseHandle function.

Requirements

  Windows NT/2000: Requires Windows 2000.
  Windows 95/98: Unsupported.
  Header: Declared in Winbase.h; include Windows.h.
  Library: Use Kernel32.lib.

See Also

Processes and Threads Overview, Process and Thread Functions, CloseHandle, GetExitCodeThread, GetThreadContext, ResumeThread, SetThreadContext, SetTokenInformation, SuspendThread, TerminateThread