Export (0) Print
Expand All
Expand Minimize

GetCurrentThread function

Retrieves a pseudo handle for the calling thread.

Syntax


HANDLE WINAPI GetCurrentThread(void);

Parameters

This function has no parameters.

Return value

The return value is a pseudo handle for the current thread.

Remarks

A pseudo handle is a special constant that is interpreted as the current thread handle. The calling thread can use this handle to specify itself whenever a thread handle is required. Pseudo handles are not inherited by child processes.

This handle has the THREAD_ALL_ACCESS access right to the thread object. For more information, see Thread Security and Access Rights.

Windows Server 2003 and Windows XP:  This handle has the maximum access allowed by the security descriptor of the thread to the primary token of the process.

The function cannot be used by one thread to create a handle that can be used by other threads to refer to the first thread. The handle is always interpreted as referring to the thread that is using it. A thread can create a "real" handle to itself that can be used by other threads, or inherited by other processes, by specifying the pseudo handle as the source handle in a call to the DuplicateHandle function.

The pseudo handle need not be closed when it is no longer needed. Calling the CloseHandle function with this handle has no effect. If the pseudo handle is duplicated by DuplicateHandle, the duplicate handle must be closed.

Do not create a thread while impersonating a security context. The call will succeed, however the newly created thread will have reduced access rights to itself when calling GetCurrentThread. The access rights granted this thread will be derived from the access rights the impersonated user has to the process. Some access rights including THREAD_SET_THREAD_TOKEN and THREAD_GET_CONTEXT may not be present, leading to unexpected failures.

Windows Phone 8: This API is supported.

Windows Phone 8.1: This API is supported.

Examples

For an example, see Checking Client Access.

Requirements

Minimum supported client

Windows XP [desktop apps | Windows Store apps]

Minimum supported server

Windows Server 2003 [desktop apps | Windows Store apps]

Header

WinBase.h on Windows XP, Windows Server 2003, Windows Vista, Windows 7, Windows Server 2008, and Windows Server 2008 R2 (include Windows.h);
Processthreadsapi.h on Windows 8 and Windows Server 2012

Library

Kernel32.lib

DLL

Kernel32.dll

See also

CloseHandle
DuplicateHandle
GetCurrentProcess
GetCurrentThreadId
OpenThread
Process and Thread Functions
Threads

 

 

Community Additions

ADD
Show:
© 2014 Microsoft