Platform SDK: Performance Monitoring

Checking PDH Interface Return Values

The return value of PDH functions indicates the success or error of the function call, which is distinct from the status of the counter data. Always check the CStatus member of a counter value returned in the PDH structures to ensure that the data returned is valid before you use it. If the value of the CStatus member does not indicate success, do not use the data. The following are the possible status values for counters:

Value Meaning
PDH_CSTATUS_NO_MACHINE PDH was unable to connect to the machine specified in the counter path. If this status is returned when the counter is being added, the counter is not completely initialized. Each time the query is updated, PDH retries the connection. When the connection is established, normal data collection resumes.
PDH_CSTATUS_NO_OBJECT The specified machine was found, but no matching performance object was found on that machine. If this status is returned when the counter is being added, the specified counter is not included in the query. If this status is returned by an active counter, the data for that counter is invalid. Each time the data is requested, PDH tries to obtain this counter data.
PDH_CSTATUS_NO_INSTANCE The specified instance was not found in the object. If this status is returned while the counter is being added to the query, the counter is successfully added to the query, but no data is available until the specific instance appears and a successful status is returned.
PDH_CSTATUS_NO_COUNTER The specified counter was not found in the specified object. If this status is returned when the counter is being added, then the counter is not added to the query. If this status is returned after a data update, the data for that counter is invalid. Each time the data is requested, PDH tries to obtain this counter data.
PDH_CSTATUS_INVALID_DATA The counter was successfully found, but the data returned is not valid. One possible cause for this value is when the data of a normally increasing counter is less than the previous value. Another possible cause is a system timer that is not correct.
PDH_CSTATUS_VALID_DATA The data for the counter was returned successfully, but is unchanged from the last time the counter was read.
PDH_CSTATUS_NEW_DATA The data for the counter was returned successfully and is different from the last time the counter was read. PDH_CSTATUS_NEW_DATA can be returned on a rate counter even if the resulting rate is the same as the last sample. This is because the raw data value that is used in the determination of this status value has changed, not the computed rate.
PDH_MORE_DATA The supplied buffer was not large enough to store all of the counter data. Allocate a larger buffer and execute the function again.
PDH_CSTATUS_ITEM_NOT_VALIDATED The counter has been added to the query, but has not been validated nor accessed. No additional status information on this counter is available.
PDH_CSTATUS_NO_COUNTERNAME No counter name was specified in the query.
PDH_CSTATUS_NO_COUNTER The specified counter name could not be found.
PDH_CSTATUS_NO_OBJECT The specified performance object could not be found.
PDH_CALC_NEGATIVE_DENOMINATOR A counter has a negative denominator value.
PDH_CALC_NEGATIVE_TIMEBASE A counter has a negative timebase value.
PDH_CALC_NEGATIVE_VALUE A counter has a negative value.
PDH_CSTATUS_NO_COUNTERNAME No counter path was specified.
PDH_CSTATUS_BAD_COUNTERNAME The counter path format is incorrect.