#include <windows.h>
#include <process.h>
#include <stdio.h>
#include <assert.h>
void mythreadfunc(void *data)
{
...
_exitthread();
}
void changeThreadState()
{
HANDLE thread = (HANDLE)_beginthread( mythreadfunc, 0, NULL );
CONTEXT context;
BOOL success;
SuspendThread(thread);
// get context
context.ContextFlags = (CONTEXT_FULL | CONTEXT_CONTROL);
success = GetThreadContext(thread, &context);
assert(success);
printf( "eax=%08X, ebx=%08X, ecx=%08X\n",
context.Eax, context.Ebx, context.Ecx );
// change context (dangerous, can crash program)
context.Eax = 0x1234BBBB;
context.Ecx = 0x2468ABCD;
success = SetThreadContext(thread, &context);
assert(success);
ResumeThread(thread);
// the resumed thread should see different values of eax, and ecx
}