How do I convert a thread ID into a thread handle?
A call to GetWindowThreadProcessId has given me the thread identifier that I wanted, but in order to call GetThreadContext I need a thread handle.
I'm experimenting using Get/SetThreadContext and I'm trying to use these API's without actually debugging the process.
Anyone have any thoughts on this,
Tom
A call to GetWindowThreadProcessId has given me the thread identifier that I wanted, but in order to call GetThreadContext I need a thread handle.
I'm experimenting using Get/SetThreadContext and I'm trying to use these API's without actually debugging the process.
Anyone have any thoughts on this,
Tom
I think you have to use OpenProcess:
Where dwDesiredAccess in your case should be PROCESS_SET_INFORMATION (but I'm not sure ); ) .
HANDLE OpenProcess(
DWORD dwDesiredAccess, // access flag
BOOL bInheritHandle, // handle inheritance flag
DWORD dwProcessId // process identifier
);
Where dwDesiredAccess in your case should be PROCESS_SET_INFORMATION (but I'm not sure ); ) .
Translated from MSDN,
invoke OpenThread, THREAD_SET_CONTEXT | THREAD_GET_CONTEXT, FALSE, threadid
should allow you to use both GetThreadContext and SetThreadContext.
invoke OpenThread, THREAD_SET_CONTEXT | THREAD_GET_CONTEXT, FALSE, threadid
should allow you to use both GetThreadContext and SetThreadContext.
Sounds weird, tank. I found no OpenThread api in MSDN, but I did
find the following. (Q127992).
There is no way to get the thread handle from the thread ID. While there is an OpenProcess() API that takes a PID and returns the handle to the process, there is no corresponding OpenThread() that takes a thread ID and returns a thread handle.
Q121093 mentions an OpenThread, but...
Win32s supports a new function, OpenThread(), which is not a part of the Win32 API.
You could try loading it with GetProcAddress and see what happens. At least it's exported from my kernel32.dll on win2k...
find the following. (Q127992).
There is no way to get the thread handle from the thread ID. While there is an OpenProcess() API that takes a PID and returns the handle to the process, there is no corresponding OpenThread() that takes a thread ID and returns a thread handle.
Q121093 mentions an OpenThread, but...
Win32s supports a new function, OpenThread(), which is not a part of the Win32 API.
You could try loading it with GetProcAddress and see what happens. At least it's exported from my kernel32.dll on win2k...
After having read your post, tank I have looked on MSDN web site, since in my MSDN cd (it is rather old) I didn't find any info on OpenThread, and I have found this link:
http://support.microsoft.com/support/kb/articles/Q127/9/92.asp
Is OpenThread available on any Win32 opereting systems?
http://support.microsoft.com/support/kb/articles/Q127/9/92.asp
Is OpenThread available on any Win32 opereting systems?
LuHa, that's the Q127992 I was talking about. Q121093 can be
found here:
http://support.microsoft.com/directory/article.asp?ID=KB;EN-US;Q121093
Reading that, I get the impression a GetModuleHandle followed by
GetProcAddress might be enough. It's probably then a "push threadid"
and "call eax", and you might be lucky :).
found here:
http://support.microsoft.com/directory/article.asp?ID=KB;EN-US;Q121093
Reading that, I get the impression a GetModuleHandle followed by
GetProcAddress might be enough. It's probably then a "push threadid"
and "call eax", and you might be lucky :).
Thankyou F0dder, I posted my comment before I read yours :).
Hm, win32s was that crappy semi-32bit support on win3.x, wasn't it?
Because Q121093 says it's supported on win32s. This would mean
it's supported on win3.x, Me and 2k? *giggle*.
Because Q121093 says it's supported on win32s. This would mean
it's supported on win3.x, Me and 2k? *giggle*.