|
//C++ ZwCreateThreadEx 调用函数
//线程处理函数 ThreadProc 和 ZwCreateThreadEx 创建新的线程,执行 ThreadProc
//使用 Windows API 如 CreateThread 创建线程
//炫彩IDE,网友参考
#include <Windows.h>
#include <ntddk.h>
VOID ThreadProc(PVOID p) {
// 线程处理函数
DbgPrint("Hello, World from new thread!\n");
}
int main() {
HANDLE hThread;
NTSTATUS status;
HANDLE ThreadHandle = NULL;
CLIENT_ID Cid;
PVOID StartAddress = ThreadProc;
PVOID ThreadParameter = NULL;
SIZE_T StackSize = 0;
SIZE_T MaxStackSize = 0;
ULONG Flags = 0;
SIZE_T ZeroBits = 0;
SIZE_T SizeOfThreadAttributeList = 0;
PVOID AttributeList = NULL;
status = ZwCreateThreadEx(&ThreadHandle,
MAXIMUM_ALLOWED,
NULL,
NtCurrentProcess(),
&StartAddress,
ThreadParameter,
Flags,
StackSize,
MaxStackSize,
&Cid,
&ZeroBits,
SizeOfThreadAttributeList,
AttributeList);
if (!NT_SUCCESS(status)) {
DbgPrint("ZwCreateThreadEx failed with status 0x%x\n", status);
} else {
DbgPrint("Thread created with handle 0x%x\n", ThreadHandle);
ZwClose(ThreadHandle);
}
return 0;
}
|
|