Hi.
Is there a way to get a thread handle if i got the tid of the thread? i mean something like OpenProcess for theads?
Posted on 2002-05-02 07:17:56 by darester
There's a function called OpenThread but it's available only in winME+ and win2K+

Thomas
Posted on 2002-05-02 07:20:21 by Thomas
so what about win9x? :p
Posted on 2002-05-02 09:41:27 by darester
IIRC it's nearly impossible in win9x, with good reasons according to microsoft:

applies only to older windows versions:
The Win32 API does not provide a way to get the thread handle from the
thread identifier. If the handles were made available this way, the
owning process could fail because another process unexpectedly
performed an operation on one of its threads, such as suspending it,
resuming it, adjusting its priority, or terminating it. Instead, you
must request the handle from the thread creator or the thread itself.


Thomas
Posted on 2002-05-02 09:49:09 by Thomas
Thomas may indeed be right. My reference does not mention for what platforms each of these functions are scoped for but this does look promising...


A snapshot that includes the Win32 thread list contains information about each thread of each currently executing Win32 process. You can retrieve information for the first thread in the list by using the Thread32First function. After retrieving the first thread in the list, you can retrieve information for subsequent threads by using the Thread32Next function. Thread32First and Thread32Next fill a THREADENTRY32 structure with information about individual threads in the snapshot.

You can enumerate the threads of a specific process by taking a snapshot that includes the threads and then by traversing the thread list, keeping information about the threads that have the same process identifier as the specified process.
You can retrieve an extended error status code for Thread32First and Thread32Next by using the GetLastError function. For more information about GetLastError, see the documentation included in the Win32 SDK.


I am assuming that with a ThreadID that you can get its handle and compair it to the one you are looking for...
Posted on 2002-05-02 11:57:15 by Graebel