问题
I'm kind of used to the way how C# applications are able to create performance counters - just instantiating new PerformanceCounter
object, and using it.
I'm now forced to use unmanaged C (C++?), and I'm really unhappy with ease of use of the API and samples provided. My main pain is the need to use lodctr for loading manifest, as is told in MSDN. I wasn't able to find any solution for this. Is there any way how can I use Performance counters without having explicitly loading the manifest, as I can do in C#?
回答1:
You want to use the PDH (Performance Data handler) library. The basic flow goes like this
// During startup call
h = PdhOpenQuery()
for each counter
PdhAddCounter( h ... )
// When you want the data values call
PdhCollectQueryData( h )
for each counter
PdhGetFormattedCounterValue()
来源:https://stackoverflow.com/questions/17880592/performance-counters-in-c-without-lodctr