/////////////////////////////////////////////////////////////////////////////////
// NtGetExitCodeThread.cpp
//

#include "stdafx.h"
#include "NtGetExitCodeThread.h"

NTSTATUS 
NTAPI
NtGetExitCodeThread(
    IN HANDLE hThread,
    OUT NTSTATUS* lpExitCode
)
{
    NTSTATUS    dwNTStatus;
    THREAD_BASIC_INFORMATION stThreadInfo;
    stThreadInfo.ExitStatus = (NTSTATUS)(-1);
    dwNTStatus = NtQueryInformationThread(
        hThread,
        ThreadBasicInformation,
        &stThreadInfo,
        sizeof(stThreadInfo),
        NULL
        );
    *lpExitCode = stThreadInfo.ExitStatus;
    return dwNTStatus;
}

NTSTATUS
NTAPI
NtGetExitCodeProcess(
    IN HANDLE hProcess,
    OUT NTSTATUS* lpExitCode
    )
{
    NTSTATUS    dwNTStatus;
    PROCESS_BASIC_INFORMATION stProcessInfo;
    stProcessInfo.ExitStatus = (NTSTATUS) (-1);
    dwNTStatus = NtQueryInformationProcess(
        hProcess,
        ProcessBasicInformation,
        &stProcessInfo,
        sizeof(stProcessInfo),
        NULL
        );
    *lpExitCode = stProcessInfo.ExitStatus;
    return dwNTStatus;
}
