OpenThread function
Applies to: desktop apps only
Opens an existing thread object.
Syntax
HANDLE WINAPI OpenThread( __in DWORD dwDesiredAccess, __in BOOL bInheritHandle, __in DWORD dwThreadId );
Parameters
- dwDesiredAccess [in]
-
The access to the thread object. This access right is checked against the security descriptor for the thread. This parameter can be one or more of the thread access rights.
If the caller has enabled the SeDebugPrivilege privilege, the requested access is granted regardless of the contents of the security descriptor.
- bInheritHandle [in]
-
If this value is TRUE, processes created by this process will inherit the handle. Otherwise, the processes do not inherit this handle.
- dwThreadId [in]
-
The identifier of the thread to be opened.
Return value
If the function succeeds, the return value is an open handle to the specified thread.
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
|
Minimum supported client | Windows XP |
|---|---|
|
Minimum supported server | Windows Server 2003 |
|
Header |
|
|
Library |
|
|
DLL |
|
See also
- CloseHandle
- GetExitCodeThread
- GetThreadContext
- Process and Thread Functions
- ResumeThread
- SetThreadContext
- SetTokenInformation
- SuspendThread
- TerminateThread
- Threads
Send comments about this topic to Microsoft
Build date: 3/7/2012
To manually set _WIN32_WINNT define it before including windows.h.
- 8/30/2011
- Jan J. Janssen
Public Declare Function OpenThread Lib"kernel32.dll" (ByVal dwDesiredAccess As ThreadAccess, ByVal bInheritHandle As Boolean, ByVal dwThreadId As UInteger) As IntPtr
<Flags()>
Public Enum ThreadAccess As Integer
DELETE = &H10000
READ_CONTROL = &H20000
WRITE_DAC = &H40000
WRITE_OWNER = &H80000
SYNCHRONIZE = &H100000
THREAD_DIRECT_IMPERSONATION = &H200
THREAD_GET_CONTEXT = &H8
THREAD_IMPERSONATE = &H100
THREAD_QUERY_INFORMATION = &H40
THREAD_QUERY_LIMITED_INFORMATION = &H800
THREAD_SET_CONTEXT = &H10
THREAD_SET_INFORMATION = &H20
THREAD_SET_LIMITED_INFORMATION = &H400
THREAD_SET_THREAD_TOKEN = &H80
THREAD_SUSPEND_RESUME = &H2
THREAD_TERMINATE = &H1
End Enum
Appropriate CloseHandle declaration is (it's not possible to post it to CloseHandle):
Public Declare Function CloseHandle Lib"Kernel32.dll" (ByVal hObject As IntPtr) As Boolean