I want to count native threads of the current Windows process via C/C++. I see there's a related question with a .NET answer, but I can't use that solution. I suspect that there may be a solution via PdhOpenQuery/PdhCollectQueryData but I haven't explored that direction yet, and I'm hoping there's an easier approach.
UPDATE: I should have said that my current implementation uses CreateToolhelp32Snapshot/Thread32First/Thread32Next and that's what I'm trying to replace. That implementation is heavy-handed and causes 20,000 page faults on every invocation in my process. Maybe I'm just using it wrong?
Update2: The solution that worked best for me was to make a string like "\Process(_)\Thread Count" with the PID of the process I was interested in. Then I called PdhExpandWildCardPath() to expand the "" wildcard. Then I invoked PdhOpenQuery(), PdhAddCounter() and PdhCollectQueryData() to initialize. Thereafter, I called PdhCollectQueryData() and PdhGetFormattedCounterValue() to get my values periodically.