1


There must be a function that gets the current status of a thread in the system because
there is this application: http://www.softwareverify.com/cpp/thread-status-monitor/index.html

It must be using some sort of API function or something... How can I get a thread state myself in C++/Windows?
thanks :)

(this is my last question for today. I promise :))

Idov
  • 5,006
  • 17
  • 69
  • 106
  • Out of interest I downloaded the thread state app (it's free) to try it out. It does not display any process, and therefore thread, information in XP so I can only assume it's using API calls only available in Vista/Win7 – Tony Jan 07 '11 at 10:17

3 Answers3

2

That's done via Toolhelp library, check information at MSDN : http://msdn.microsoft.com/en-us/library/ms686780%28v=VS.85%29.aspx

Nickolay Olshevsky
  • 13,706
  • 1
  • 34
  • 48
1

You can use the following examples to get the running processes and, when you have a process ID, the threads.

Taking a Snapshot and Viewing Processes

Traversing the Thread List

EDIT: After getting the handle to the thread(s) you are interested in you can call GetExitCodeThread but that will only tell you if the thread is STILL_ACTIVE until it ends, when you can find the exit code.

While searching for the additional information for your comment I also came across this thread on SO which might be of interest to you.

Community
  • 1
  • 1
Tony
  • 9,672
  • 3
  • 47
  • 75
1

You get the most bang out of WMI, Win32_Thread class. The linked article has a link to the C++ code you need. Experiment with the WMI Code Creator tool.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • I know, it sucks that you can do this in a scripting language with so little code. But the query itself is the same in any language. Use the tool to verify that your C++ code works properly. – Hans Passant Jan 08 '11 at 11:16