Checking Counter Data Status Codes

The return value of PDH functions indicates the success or failure of the function call, which is different 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:

ValueMeaning
PDH_CSTATUS_NO_MACHINEPDH was unable to connect to the computer 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_OBJECTThe specified computer was found, but the specified performance object was found on the computer. 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_INSTANCEThe 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_COUNTERThe 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 data collection, the data for that counter is invalid. Each time the data is requested, PDH tries to obtain this counter data.
PDH_CSTATUS_INVALID_DATAThe counter was successfully found, but the data returned is not valid. This error can occur if the counter value is less than the previous value. (Because counter values always increment, the counter value rolls over to zero when it reaches its maximum value.) Another possible cause is a system timer that is not correct.
PDH_CSTATUS_VALID_DATAThe data for the counter was returned successfully, but is unchanged from the last time the counter was read.
PDH_CSTATUS_NEW_DATAThe 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_DATAThe 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_VALIDATEDThe 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_COUNTERNAMENo counter name was specified in the query.
PDH_CSTATUS_NO_COUNTERThe specified counter name could not be found.
PDH_CSTATUS_NO_OBJECTThe specified performance object could not be found.
PDH_CALC_NEGATIVE_DENOMINATORA counter has a negative denominator value.
PDH_CALC_NEGATIVE_TIMEBASEA counter has a negative timebase value.
PDH_CALC_NEGATIVE_VALUEA counter has a negative value.
PDH_CSTATUS_NO_COUNTERNAMENo counter path was specified.
PDH_CSTATUS_BAD_COUNTERNAMEThe counter path format is incorrect.

 

 

 

Show: