How to get a thread handle from a thread id?
-
Hello everyone, I thought of posting this in the operating system forum, but it has so little traffic I thought the question would be overlooked. On Windows XP and Windows 2000 you can use:
HANDLE hThread; DWORD dwProcessId; dwProcessId = GetCurrentProcessID(); hThread = OpenThread(..., dwProcessId);
to get a handle to a thread if you know its thread id. How do I do this on Windows NT 4.0? The OpenThread() function does not exist in kernel32.dll on Windows NT 4.0. Hoping someone can help. Kernel mode device driver solutions are valid, I'll consider any method to get this info. Stephen Kellett -- C++/Java/Win NT/Unix variants Memory leaks/corruptions/performance/system problems. UK based. Problems with RSI/WRULD? Contact me for advice.
-
Hello everyone, I thought of posting this in the operating system forum, but it has so little traffic I thought the question would be overlooked. On Windows XP and Windows 2000 you can use:
HANDLE hThread; DWORD dwProcessId; dwProcessId = GetCurrentProcessID(); hThread = OpenThread(..., dwProcessId);
to get a handle to a thread if you know its thread id. How do I do this on Windows NT 4.0? The OpenThread() function does not exist in kernel32.dll on Windows NT 4.0. Hoping someone can help. Kernel mode device driver solutions are valid, I'll consider any method to get this info. Stephen Kellett -- C++/Java/Win NT/Unix variants Memory leaks/corruptions/performance/system problems. UK based. Problems with RSI/WRULD? Contact me for advice.
MSDN says: Windows NT 4.0 and earlier, Windows 95/98/Me: There is no 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. A thread can use the GetCurrentThread function to retrieve a pseudo handle to its own thread object. This pseudo handle is valid only for the calling process; it cannot be inherited or duplicated for use by other processes. To get the real handle to the thread, given a pseudo handle, use the DuplicateHandle function.