Compartir a través de


TlsGetValue

A version of this page is also available for

Windows Embedded CE 6.0 R3

4/8/2010

This function retrieves the value in the calling thread's thread local storage (TLS) slot for a specified TLS index. Each thread of a process has its own slot for each TLS index.

Syntax

LPVOID TlsGetValue(
  DWORD dwTlsIndex
);

Parameters

  • dwTlsIndex
    [in] Specifies a TLS index that was allocated by the TlsAlloc function.

Return Value

The value stored in the calling thread's TLS slot associated with the specified index indicates success. Zero indicates failure. To get extended error information, call GetLastError.

The data stored in a TLS slot can have a value of zero. If so, the return value is zero, and GetLastError returns NO_ERROR.

Remarks

TLS indexes are typically allocated by the TlsAlloc function during process or DLL initialization. When allocated, each thread of the process can use a TLS index to access its own TLS storage slot for that index.

The storage slot for each thread is initialized to NULL.

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 TlsGetValue, to retrieve the stored value.

For Windows CE 3.0 and later, NULL is returned when TlsGetValue is called before TlsSetValue.

For Windows CE 1.0 through 2.12, the returned value is not guaranteed to be NULL.

The primary goal of TlsSetValue and TlsGetValue is speed. These functions perform minimal parameter validation and error checking. In particular, this function succeeds if dwTlsIndex is in the range zero (0) through (TLS_MINIMUM_AVAILABLE – 1). You must ensure that the index is valid.

On Windows Embedded CE, when TlsGetValue succeeds with a return value of 0, NO_ERROR is passed to the SetLastError function. For Windows desktop-based platforms, TlsGetValue sets the last error to NO_ERROR for any success, regardless of the return value.

Requirements

Header winbase.h
Library coredll.lib
Windows Embedded CE Windows CE 1.0 and later
Windows Mobile Windows Mobile Version 5.0 and later

See Also

Reference

Process and Thread Functions
SetLastError
TlsAlloc
TlsFree
TlsSetValue