PdhGetFormattedCounterValue function
Computes a displayable value for the specified counter.
Syntax
PDH_STATUS PdhGetFormattedCounterValue( _In_ PDH_HCOUNTER hCounter, _In_ DWORD dwFormat, _Out_ LPDWORD lpdwType, _Out_ PPDH_FMT_COUNTERVALUE pValue );
Parameters
- hCounter [in]
-
Handle of the counter for which you want to compute a displayable value. The PdhAddCounter function returns this handle.
- dwFormat [in]
-
Determines the data type of the formatted value. Specify one of the following values.
Value Meaning - PDH_FMT_DOUBLE
Return data as a double-precision floating point real.
- PDH_FMT_LARGE
Return data as a 64-bit integer.
- PDH_FMT_LONG
Return data as a long integer.
You can use the bitwise inclusive OR operator (|) to combine the data type with one of the following scaling factors.
- lpdwType [out]
-
Receives the counter type. For a list of counter types, see the Counter Types section of the Windows Server 2003 Deployment Kit. This parameter is optional.
- pValue [out]
-
A PDH_FMT_COUNTERVALUE structure that receives the counter value.
Return value
If the function succeeds, it returns ERROR_SUCCESS.
If the function fails, the return value is a system error code or a PDH error code. The following are possible values.
| Return code | Description |
|---|---|
|
A parameter is not valid or is incorrectly formatted. |
|
The specified counter does not contain valid data or a successful status code. |
|
The counter handle is not valid. |
Remarks
The data for the counter is locked (protected) for the duration of the call to PdhGetFormattedCounterValue to prevent any changes during the processing of the call. Reading the data (calling this function successfully) clears the data-changed flag for the counter.
Some counters, such as rate counters, require two counter values in order to compute a displayable value. In this case you must call PdhCollectQueryData twice before calling PdhGetFormattedCounterValue. For more information, see Collecting Performance Data.
If the specified counter instance does not exist, the method will return PDH_INVALID_DATA and set the CStatus member of the PDH_FMT_COUNTERVALUE structure to PDH_CSTATUS_NO_INSTANCE.
Prior to Windows Server 2003: The format call may fail for counters that require only a single value when the instance is not found. Try calling the query and format calls again. If the format call fails the second time, the instance is not found. As an alternative, you can call the PdhEnumObjects function with the refresh option set to TRUE to refresh the counter instances before querying and formatting the counter data.
Examples
For an example, see Browsing Performance Counters or Reading Performance Data from a Log File.
Requirements
|
Minimum supported client | Windows XP [desktop apps only] |
|---|---|
|
Minimum supported server | Windows Server 2003 [desktop apps only] |
|
Header |
|
|
Library |
|
|
DLL |
|
See also
Send comments about this topic to Microsoft
Build date: 10/26/2012