Kernel32CreateRemoteThread(IntPtr, IntPtr, IntPtr, ThreadStart, IntPtr, CreateThreadFlags, UInt32) Method

Creates a thread that runs in the virtual address space of another process.

Use the CreateRemoteThreadEx(IntPtr, SecurityAttributes, IntPtr, IntPtr, IntPtr, CreateThreadFlags, IntPtr, UInt32) function to create a thread that runs in the virtual address space of another process and optionally specify extended attributes.

Definition

Namespace: DevCase.Win32.NativeMethods
Assembly: DevCase.net48 (in DevCase.net48.dll) Version: 6.0.0.0 (6.0)
XMLNS for XAML: Not mapped to an xmlns.
[DllImportAttribute("Kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static IntPtr CreateRemoteThread(
	IntPtr hProcess,
	IntPtr threadAttributes,
	IntPtr stackSize,
	ThreadStart startAddress,
	IntPtr threadParameter,
	CreateThreadFlags creationFlags,
	ref uint refThreadId
)

Parameters

hProcess  IntPtr
A handle to the process in which the thread is to be created.

The handle must have the CreateThread, QueryInformation, VirtualMemoryOperation, VirtualMemoryRead, and VirtualMemoryWrite access rights, and may fail without these rights on certain platforms.

threadAttributes  IntPtr
A pointer to a SecurityAttributes structure that specifies a security descriptor for the new thread and determines whether child processes can inherit the returned handle.

If threadAttributes is Zero, the thread gets a default security descriptor and the handle cannot be inherited.

The access control lists (ACL) in the default security descriptor for a thread come from the primary token of the creator.

stackSize  IntPtr
The initial size of the stack, in bytes. The system rounds this value to the nearest page.

If this parameter is 0 (zero), the new thread uses the default size for the executable.

startAddress  ThreadStart
A pointer to the application-defined function of type LPTHREAD_START_ROUTINE to be executed by the thread and represents the starting address of the thread in the remote process.

The function must exist in the remote process.

threadParameter  IntPtr
A pointer to a variable to be passed to the thread function.
creationFlags  CreateThreadFlags
The flags that control the creation of the thread.
refThreadId  UInt32
A pointer to a variable that receives the thread identifier.

If this parameter is , the thread identifier is not returned.

Return Value

IntPtr
If the function succeeds, the return value is a handle to the new thread.

If the function fails, the return value is NULL.

To get extended error information, call GetLastWin32Error.

Remarks

See Also