PdhGetCounterInfoA function

Retrieves information about a counter, such as data size, counter type, path, and user-supplied data values.

Syntax

PDH_FUNCTION PdhGetCounterInfoA(
  PDH_HCOUNTER        hCounter,
  BOOLEAN             bRetrieveExplainText,
  LPDWORD             pdwBufferSize,
  PPDH_COUNTER_INFO_A lpBuffer
);

Parameters

hCounter

Handle of the counter from which you want to retrieve information. The PdhAddCounter function returns this handle.

bRetrieveExplainText

Determines whether explain text is retrieved. If you set this parameter to TRUE, the explain text for the counter is retrieved. If you set this parameter to FALSE, the field in the returned buffer is NULL.

pdwBufferSize

Size of the lpBuffer buffer, in bytes. If zero on input, the function returns PDH_MORE_DATA and sets this parameter to the required buffer size. If the buffer is larger than the required size, the function sets this parameter to the actual size of the buffer that was used. If the specified size on input is greater than zero but less than the required size, you should not rely on the returned size to reallocate the buffer.

lpBuffer

Caller-allocated buffer that receives a PDH_COUNTER_INFO structure. The structure 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. Set to NULL if pdwBufferSize is zero.

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
PDH_INVALID_ARGUMENT
A parameter is not valid or is incorrectly formatted. For example, on some releases you could receive this error if the specified size on input is greater than zero but less than the required size.
PDH_INVALID_HANDLE
The counter handle is not valid.
PDH_MORE_DATA
The lpBuffer buffer is too small to hold the counter information. This return value is expected if pdwBufferSize is zero on input. If the specified size on input is greater than zero but less than the required size, you should not rely on the returned size to reallocate the buffer.

Remarks

You should call this function twice, the first time to get the required buffer size (set lpBuffer to NULL and pdwBufferSize to 0), and the second time to get the data.

Requirements

   
Minimum supported client Windows XP [desktop apps only]
Minimum supported server Windows Server 2003 [desktop apps only]
Target Platform Windows
Header pdh.h
Library Pdh.lib
DLL Pdh.dll

See also

PDH_COUNTER_INFO