Platform SDK: Performance Monitoring

PdhAddCounter

The PdhAddCounter function initializes a counter structure for the specified counter in the specified query.

PDH_STATUS PdhAddCounter(
  HQUERY hQuery,              
  LPCTSTR szFullCounterPath,  
  DWORD_PTR dwUserData,           
  HCOUNTER *phCounter         
);

Parameters

hQuery
[in] Handle of the query to which the new counter will be added.
szFullCounterPath
[in] A pointer to the fully qualified and resolved path of the counter to create. This path can contain wildcard characters. See PDH_COUNTER_PATH_ELEMENTS.
dwUserData
[in] A user-defined value, typically, a pointer or index to the user's counter structure.
phCounter
[out] A pointer to the buffer that receives a handle to the created counter.

Remarks

If a wildcard character is specified in the szFullCounterPath parameter, all counter names matching the wildcard character are added to the query.

Return Values

If the function succeeds, it returns ERROR_SUCCESS, creates a new counter, and returns a handle to the counter in the buffer pointed to by phCounter.

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_CSTATUS_BAD_COUNTERNAME The counter name path string could not be parsed or interpreted.
PDH_CSTATUS_NO_COUNTER The specified counter was not found.
PDH_CSTATUS_NO_COUNTERNAME An empty counter name path string was passed in.
PDH_CSTATUS_NO_MACHINE A machine entry could not be created.
PDH_CSTATUS_NO_OBJECT The specified object could not be found.
PDH_FUNCTION_NOT_FOUND The calculation function for this counter could not be determined.
PDH_INVALID_ARGUMENT One or more arguments are invalid.
PDH_INVALID_HANDLE The query handle is not valid.
PDH_MEMORY_ALLOCATION_FAILURE A memory buffer could not be allocated.

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

PdhRemoveCounter, PDH_COUNTER_PATH_ELEMENTS