#ifndef _NTPSAPI_H
// Threads
#if (PHNT_MODE != PHNT_MODE_KERNEL)
#if (PHNT_VERSION >= PHNT_WIN11)
NTSYSCALLAPI
NTSTATUS
NTAPI
NtQueueApcThreadEx2(
_In_ HANDLE ThreadHandle,
_In_opt_ HANDLE ReserveHandle, // NtAllocateReserveObject
_In_ ULONG ApcFlags, // QUEUE_USER_APC_FLAGS
_In_ PPS_APC_ROUTINE ApcRoutine,
_In_opt_ PVOID ApcArgument1,
_In_opt_ PVOID ApcArgument2,
_In_opt_ PVOID ApcArgument3
);
View code on GitHub#ifndef _NTZWAPI_H
NTSYSCALLAPI
NTSTATUS
NTAPI
ZwQueueApcThreadEx2(
_In_ HANDLE ThreadHandle,
_In_opt_ HANDLE ReserveHandle, // NtAllocateReserveObject
_In_ ULONG ApcFlags, // QUEUE_USER_APC_FLAGS
_In_ PPS_APC_ROUTINE ApcRoutine,
_In_opt_ PVOID ApcArgument1,
_In_opt_ PVOID ApcArgument2,
_In_opt_ PVOID ApcArgument3
);
View code on GitHubQueues a user-mode Asynchronous Procedure Call (APC) on the specified thread.
ThreadHandle - a handle the the thread granting the THREAD_SET_CONTEXT access.ReserveHandle - an optional handle to the reserve object (see NtAllocateReserveObject) to avoid memory allocations.ApcFlags - the flags that control properties of the APC.ApcRoutine - the address of the function to invoke.ApcArgument1 - the first argument to pass to the APC routine.ApcArgument2 - the second argument to pass to the APC routine.ApcArgument3 - the third argument to pass to the APC routine.QUEUE_USER_APC_FLAGS_NONE - indicates that none of the flags listed below are used. The behavior defaults to regular APCs that require the thread to first enter an alertable wait via NtDelayExecution (or a similar function) or call NtTestAlert.QUEUE_USER_APC_FLAGS_SPECIAL_USER_APC - queue a special user-mode APC that does not require the thread to enter an alertable state. The APC will be executed on the next thread's transition to user mode.QUEUE_USER_APC_CALLBACK_DATA_CONTEXT - let the callback routine receive the context (set of registers) that was interrupted when the thread was directed to call the APC function.To queue a WoW64 APC, encode the ApcRoutine parameter using the Wow64EncodeApcRoutine macro or use RtlQueueApcWow64Thread.
Note that user APCs on the Native API level have three parameters in contrast with the Win32 APCs that only have one.
This function was introduced in Windows 11.