One point to note is that when we get a return type of PDH_CALC_NEGATIVE_DENOMINATOR then it is to be understood that the present raw counter value is subtracted from the previous raw counter value and a negative result was detected. APIâs such as PdhFormatFromRawValue, PdhGetFormattedCounterValue those try to format the raw counter values usually need to calculate the denominator. For example the % processor time performance counter is the percentage of time that the processor is running a non-Idle thread. The calculation is done as follows:
When the application calls the PdhGetFormattedCounterValue PDH function, the calculation shown above is performed to calculate the % Processor Time. Since there is a requirement to calculate the denominator (Y1 â Y0) so if a negative denominator is detected the API PdhGetFormattedCounterValue will return PDH_CALC_NEGATIVE_DENOMINATOR.
If the function PdhGetFormattedCounterValue() fails, the return value is a system error code or a PDH error code. In case of an error, the following are *possible* values returned by PdhGetFormattedCounterValue():
â¢ PDH_INVALID_HANDLE ERROR
â¢ PDH_INVALID_ARGUMENT ERROR
â¢ PDH_INVALID_DATA ERROR
This means there is a possibility that you might get a return value other than PDH_INVALID_ARGUMENT, PDH_INVALID_DATA or PDH_INVALID_HANDLE, and the return values are stated at PDH error code.
The return values like PDH_CALC_NEGATIVE_DENOMINATOR can occur because of either bug in the provider or overflow of values in data storage. In these situations, you have an option to ignore this return value and retry a bit later like 1 second to get the new values. This is not a fatal error that application canât continue correctly, like INVALID_HANDLE or INVALID_DATA.