Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to get a thread handle from a thread id?

How to get a thread handle from a thread id?

Scheduled Pinned Locked Moved C / C++ / MFC
questionperformancec++javahelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Stephen Kellett
    wrote on last edited by
    #1

    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.

    L 1 Reply Last reply
    0
    • S Stephen Kellett

      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.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups