Platform SDK: Performance Monitoring

PdhGetCounterInfo

The PdhGetCounterInfo function retrieves information about a counter, such as data size, counter type, path, and user-supplied data values.

PDH_STATUS PdhGetCounterInfo(
  HQUERY hCounter,               
  BOOLEAN bRetrieveExplainText,  
  LPDWORD pdwBufferSize,         
  PPDH_COUNTER_INFO lpBuffer     
);

Parameters

hCounter
[in] A handle to the counter from which to retrieve the information.
bRetrieveExplainText
[in] Determines whether explain text is retrieved. If you set this parameter to TRUE, then the explain text for the counter is retrieved. If you set this parameter to FALSE, the field in the returned buffer is NULL.
pdwBufferSize
[in/out] A pointer to a DWORD containing the size, in bytes, of the buffer passed in lpBuffer. If the counter requires a buffer larger than is indicated by pdwBufferSize, then PdhGetCounterInfo returns the required buffer size in this parameter. If the function succeeds, this parameter contains the size of the data returned in lpBuffer. If this parameter is zero on input, the function does not return data in the buffer (in fact, lpBuffer can be NULL); it returns the required size, in bytes.
lpBuffer
[out] A pointer to a PDH_COUNTER_INFO structure that receives the counter information. The structure returned is variable-length, because the string data is appended to the end of the fixed-format portion of the structure. This is done so that all data is returned in a single buffer allocated by the caller.

Return Values

If the function succeeds, it returns ERROR_SUCCESS.

If the function fails, the return value is a PDH error status defined in PDHMsg.h. The following are possible error values.

Error value Description
PDH_INVALID_ARGUMENT An argument is not correct or is incorrectly formatted.
PDH_INVALID_HANDLE The counter handle is not valid.
PDH_MORE_DATA The buffer supplied is not large enough to receive the requested data.

Requirements

  Windows NT/2000: Requires Windows NT 4.0 or later.
  Header: Declared in Pdh.h.
  Library: Use Pdh.lib.
  Unicode: Implemented as Unicode and ANSI versions on Windows NT/2000.

See Also

PDH_COUNTER_INFO