TlsGetValue2 function (processthreadsapi.h)
Important
Some information relates to a prerelease product which may be substantially modified before it's commercially released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Retrieves the value in the calling thread's thread local storage (TLS) slot for the specified TLS index. Each thread of a process has its own slot for each TLS index.
Syntax
LPVOID TlsGetValue2(
[in] DWORD dwTlsIndex
);
Parameters
[in] dwTlsIndex
The TLS index that was allocated by the TlsAlloc function.
Return value
If the function succeeds, the return value is the value stored in the calling thread's TLS slot associated with the specified index. If dwTlsIndex is a valid index allocated by a successful call to TlsAlloc, this function always succeeds.
If the function fails, the return value is zero.
Remarks
TLS indexes are typically allocated by the TlsAlloc function during process or DLL initialization. After a TLS index is allocated, each thread of the process can use it to access its own TLS slot for that index. A thread specifies a TLS index in a call to TlsSetValue to store a value in its slot. The thread specifies the same index in a subsequent call to TlsGetValue2 to retrieve the stored value.
TlsGetValue2 was implemented with speed as the primary goal. The function performs minimal parameter validation and error checking. In particular, it succeeds if dwTlsIndex is in the range 0 through (TLS_MINIMUM_AVAILABLE– 1). It is up to the programmer to ensure that the index is valid and that the thread calls TlsSetValue before calling TlsGetValue2.
This function is identical to TlsGetValue except that it doesn't set the thread's last error. Applications calling this function should avoid using 0 as a valid value, because GetLastError cannot be called to check if the function failed.
Examples
See Using Thread Local Storage or Using Thread Local Storage in a Dynamic-Link Library.
Requirements
Requirement | Value |
---|---|
Minimum supported client | Windows 11, version 24H2 |
Target Platform | Windows |
Header | processthreadsapi.h |
Library | Kernel32.lib |
DLL | Kernel32.dll |
API set | api-ms-win-core-processthreads-l1-1-8 |