PdhAddCounter
The PdhAddCounter function initializes a counter structure for the specified counter in the specified query.
PDH_STATUS PdhAddCounter(
IN HQUERY hQuery, // handle to the query
IN LPCTSTR szFullCounterPath,
// path of the counter
IN DWORD dwUserData, // user-defined value
IN HCOUNTER *phCounter // pointer to the counter handle buffer
);
Parameters
-
hQuery
-
The handle of the query to which the new counter will be added.
-
szFullCounterPath
-
The fully qualified and resolved path of the counter to create. This path cannot contain wild card path strings or characters. See PDH_COUNTER_PATH_ELEMENTS.
-
dwUserData
-
A user-defined value, typically, a pointer or index to the user's counter structure.
-
phCounter
-
A pointer to the buffer that is to receive the handle to the counter that is created.
Return Values
If the function succeeds, it returns ERROR_SUCCESS, creates a new counter, and returns the 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:
-
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.
See Also
Performance Data Helper Overview, Performance Data Functions, PdhRemoveCounter, PDH_COUNTER_PATH_ELEMENTS