NtCreateThreadEx - NtDoc

Native API online documentation, based on the System Informer (formerly Process Hacker) phnt headers
#ifndef _NTPSAPI_H
//
// User processes and threads
//
#if (PHNT_MODE != PHNT_MODE_KERNEL)

/**
 * Creates a new thread in the specified process.
 *
 * @param ThreadHandle A pointer to a handle that receives the thread object handle.
 * @param DesiredAccess The access rights desired for the thread object.
 * @param ObjectAttributes Optional. A pointer to an OBJECT_ATTRIBUTES structure that specifies the attributes of the new thread.
 * @param ProcessHandle A handle to the process in which the thread is to be created.
 * @param StartRoutine A pointer to the application-defined function to be executed by the thread.
 * @param Argument Optional. A pointer to a variable to be passed to the thread.
 * @param CreateFlags Flags that control the creation of the thread. These flags are defined as THREAD_CREATE_FLAGS_*.
 * @param ZeroBits The number of zero bits in the starting address of the thread's stack.
 * @param StackSize The initial size of the thread's stack, in bytes.
 * @param MaximumStackSize The maximum size of the thread's stack, in bytes.
 * @param AttributeList Optional. A pointer to a list of attributes for the thread.
 * @return NTSTATUS Successful or errant status.
 */
NTSYSCALLAPI
NTSTATUS
NTAPI
NtCreateThreadEx(
    _Out_ PHANDLE ThreadHandle,
    _In_ ACCESS_MASK DesiredAccess,
    _In_opt_ PCOBJECT_ATTRIBUTES ObjectAttributes,
    _In_ HANDLE ProcessHandle,
    _In_ PUSER_THREAD_START_ROUTINE StartRoutine,
    _In_opt_ PVOID Argument,
    _In_ ULONG CreateFlags, // THREAD_CREATE_FLAGS_*
    _In_ SIZE_T ZeroBits,
    _In_ SIZE_T StackSize,
    _In_ SIZE_T MaximumStackSize,
    _In_opt_ PPS_ATTRIBUTE_LIST AttributeList
    );

#endif
#endif

View code on GitHub
#ifndef _NTZWAPI_H

NTSYSCALLAPI
NTSTATUS
NTAPI
ZwCreateThreadEx(
    _Out_ PHANDLE ThreadHandle,
    _In_ ACCESS_MASK DesiredAccess,
    _In_opt_ POBJECT_ATTRIBUTES ObjectAttributes,
    _In_ HANDLE ProcessHandle,
    _In_ PUSER_THREAD_START_ROUTINE StartRoutine,
    _In_opt_ PVOID Argument,
    _In_ ULONG CreateFlags, // THREAD_CREATE_FLAGS_*
    _In_ SIZE_T ZeroBits,
    _In_ SIZE_T StackSize,
    _In_ SIZE_T MaximumStackSize,
    _In_opt_ PPS_ATTRIBUTE_LIST AttributeList
    );

#endif

View code on GitHub

Creates a new thread in the specified process.

Parameters

Creation flags

Check the corresponding pages for more details.

Supported attributes

Check the corresponding pages for more details.

Remarks

To avoid retaining unused resources, call NtClose to close the returned handle when it is no longer required.

For the legacy equivalent of this function, see NtCreateThread.

Related Win32 API

See also