Home > Software engineering >  How to get other processes threadcontext? Why do I always go wrong
How to get other processes threadcontext? Why do I always go wrong

Time:09-28

Need to get another program register,
First I get a window handle, testing is a notepad window test

Then getwindowthreadprocessid threadid
Then openthread threadhandle
Again suspendthread (hthread)
Then look at the notepad window is no longer response, hang up the function return value is also success
It then calls the BOOL ret=GetThreadContext ((HANDLE) hThread, & amp; CTX);
This function is not line, anyway returns failure, error code is 87, don't know is which parameter errors, who know how to return a responsibility,

Below is a code,

HWND HWND=FindWindow (NULL, "a new text document. TXT - notepad");
If (hWnd!=NULL)
{
DwThreadID=GetWindowThreadProcessId (hWnd, & amp; DwProcessID);
}

HANDLE hThread=OpenThread (THREAD_ALL_ACCESS, FALSE, the dwThreadID);
DWORD dret=SuspendThread (hThread);

The CONTEXT CTX.
ZeroMemory (& amp; CTX, sizeof (CTX));
CTX. ContextFlags=CONTEXT_ALL;
BOOL ret=GetThreadContext (hThread, & amp; CTX);

Int the error=GetLastError ();

ResumeThread (hThread);


CodePudding user response:

To download and install
MSDN98_1. ISO http://pan.baidu.com/s/1dDF41ix, MSDN98_2. ISO http://pan.baidu.com/s/1bnGo0Vl

Reference:
MSDN98 \ SAMPLES \ MSDN \ PERIODIC \ 4598 \ KILLTHRD CPP
MSDN98 \ SAMPLES \ MSDN \ TECHART \ 3274 \ INJLIB CPP
MSDN98 \ SAMPLES \ MSDN \ TECHART \ 1407 \ PDEBUG C
MSDN98 \ SAMPLES \ MSDN \ TECHART \ 5143 \ PDEBUG C
MSDN98 \ SAMPLES \ VC98 \ SDK \ SDKTOOLS \ IMAGE \ DRWATSON \ CONTEXT C
MSDN98 \ SAMPLES \ VC98 \ SDK \ SDKTOOLS \ IMAGE \ DRWATSON \ DEBUG C
MSDN98 \ SAMPLES \ VC98 \ SDK \ SDKTOOLS \ IMAGE \ WINNT \ PFMON \ DEBUG C
MSDN98 \ SAMPLES \ VC98 \ SDK \ SDKTOOLS \ WINNT \ WALKER \ PDEBUG C
MSDN98 \ SAMPLES \ VC98 \ SDK \ WINBASE \ DEBUG \ DEB \ DEBDEBUG C
  • Related