GetExitCodeThread

Retrieves the termination status of the specified thread.

Syntax

BOOL GetExitCodeThread(
         HANDLE hThread,
         LPDWORD lpExitCode
)  

Parameters

hThread
Type: HANDLE 

[in]

A handle to the thread.

The handle must have the THREAD_QUERY_INFORMATION or THREAD_QUERY_LIMITED_INFORMATION access right. For more information, see Thread Security and Access Rights.

Note

  The handle must have the THREAD_QUERY_INFORMATION access right.

lpExitCode
Type: LPDWORD 

[out]

A pointer to a variable to receive the thread termination status. For more information, see Remarks.

Return value

Type: BOOL 

If the function succeeds, the return value is nonzero.

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

Remarks

This function returns immediately. If the specified thread has not terminated and the function succeeds, the status returned is STILL_ACTIVE. If the thread has terminated and the function succeeds, the status returned is one of the following values:

Important

GetExitCodeThread returns a valid error code defined by the application only after the thread terminates. Therefore, an application should not use STILL_ACTIVE (259) as an error code. If a thread returns STILL_ACTIVE (259) as an error code, applications that test for this value could interpret it to mean that the thread is still running and continue to test for the completion of the thread after the thread has terminated, which could put the application into an infinite loop.

Requirements

Header: Declared in processthreadsapi.h.

Library: Use kernelx.lib.