Process and Thread Function ...


GetExitCodeThread Function

Retrieves the termination status of the specified thread.

Syntax

C++
BOOL WINAPI GetExitCodeThread(
  __in   HANDLE hThread,
  __out  LPDWORD lpExitCode
);

Parameters

hThread [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.

Windows Server 2003 and Windows XP/2000:  The handle must have the THREAD_QUERY_INFORMATION access right.
lpExitCode [out]

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

Return Value

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:

  • The exit value specified in the ExitThread or TerminateThread function.
  • The return value from the thread function.
  • The exit value of the thread's process.

Important  The GetExitCodeThread function 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

Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderWinbase.h (include Windows.h)
LibraryKernel32.lib
DLLKernel32.dll

See Also

ExitThread
GetExitCodeProcess
OpenThread
Process and Thread Functions
TerminateThread
Terminating a Thread

Send comments about this topic to Microsoft

Build date: 10/8/2009

Tags :


Community Content

dmex
vb.net syntax
<DllImport("kernel32.dll")> Public Shared Function GetExitCodeThread(ByVal hThread As IntPtr, <Out> ByRef lpExitCode As UInt32) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
Tags :

dmex
C# syntax
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("kernel32.dll")]
public static extern bool GetExitCodeThread(IntPtr hThread, out uint lpExitCode);
Tags :

Page view tracker